Internal numbering of entities differs in iterations?
-
hello,
i face a seldom problem:i have always the same polyline created from ruby (say 10 edges, all connected) : curve
then i generate a rectangle at the startin point : square
then i use
status1 = square.followme curve
works perfect.
BUT:
while idenfifying the sidewalls of the result, i found out, that it's entity-number changes from iteration to iteration.
i would not expect that.i checked it by letting the ruby ERASE the entity[16],
which sometimes deleted a different face .
can anybody confirm that?
if so, how is it possible to allocate always the same face of an object generated in a routine?
thanx stan
-
@artmusicstudio said:
hello,
if so, how is it possible to allocate always the same face of an object generated in a routine?Attach an attribute to the face to mark it.
face.set_attribute("AMS_Fancy_Widget", "face number", i.to_s )
You decide what the name of the attribute will be, and what value to store.
-
hi dan,
ok, so i can give an attribute to an entity.but what can i do , when the same face (let us say the front face of the cube , which is generated by the code again and again), sometimes has a different number in the array ? it is impossible then to know the number and so also not possible to assign attributes.
what ever i do, in my case the number of the face changes (a 3d object crewted by follow me)
hopefully infind the reason, since moving always the same face is an important feature for me.
regards and thanx
stan -
I assumed you would attach an attribute before the operation.
.. then search the array using one of the methods in
Enumerable
(which is mixed intoArray
.) -
IF you know what direction the face's normal vector will be pointing.. then you could search the array for the face who's normal == vector.
found = results.find {|f| f.normal == vector } face = found if found
-
Currently at least, SketchUp does not give any entities an "enduring id" across sessions - it's unlikely that 'raw geometry' will ever get them. So you have give them an id attribute - as Dan has suggested.
It can be an integer - this is best as searching strings is slower...
i = 3 ### say... face.set_attribute("AMS_Fancy_Widget", "face_id", i )
then later onnum = 3 ### say... face = nil entities.grep(Sketchup;;Face).each{|e| if face.get_attribute("AMS_Fancy_Widget", "face_id", -1) == num face = e break end } if face ### do something ...
Note how I used
-1
as the default response rather than accepting 'nil' - you will NOT have used that as an id and now any faces without an id attribute will be skipped too, only the 'face' with the exact matching id number will be found... Because the 'face' with a particular id might no longer exist [it could have been deleted] you'll need to use aif face...
test... in case there is no match. -
hi tig,
yes, i understand the principles of giving attributes to entities now and will try to experiment with this.
maybe i may go step back to my special situation (just for understanding):i have an axis of different edges, giving a path for 'followme' ,
then i let create the ruby the same object again and again (imagine:
square, path, followme, delete
square, path, followme, delete
etc.)the funny thing is, that the entities DO have a numbering , which is their position in the array, right?
and so a thought, while knowing , which entity has which number in the row, i could access them easily (again: always the same object with same amount of edges and faces from the same procedure)
but at this point the numbering of faces in the array changes, although generated thru same procedure.
and since the object is a follow-me- object, i cannot give any attributes to single faces, i guess.....
so that's the trouble.
but i can gerate these objects per hand too (face by face), so i will be able to use the 'attribute' option.
regards stan
Advertisement