Component names
-
-
Sorry one more bit of bother
Chris
-
Sorry typo by me...
insts=[];model.active_entities.each{|inst|insts.push(inst)if inst.typename=="ComponentInstance"}
I usually use 'e' as my block variable BUT changed it to 'inst' to help you BUT forgot to change one !!! It's inst.typename... NOT e.typename... I've edited the original too...
-
To do stuff on the model's content you need to find the placed component instances...
insts=[];model.active_entities.each{|inst|insts.push(inst)if inst.typename=="ComponentInstance"}
To find an instance's definition name use
inst.definition.name
, to find its individual instance name (you can also give each instance its own name using entity info...) you can use
inst.name
.
To do stuff on the model's data-base definitions etc usedefns=model.definitions;defns.each{|defn|insts=defn.instances;insts.each{|inst|###etc###} }
Again defn.name or inst.name to give you their names...
You can also find an instance's unique enduring ID if needed...
Groups work slightly differently... but similar enough... -
No sorry please! (Chinglish)
Yes I thought that but thought maybe it was some special thing when I did not get the answer I was expecting with inst. I thought active_entities was the same as select all, but I see now it's not ... so I get all components rather than just those in the scene (like outliner does). If you have time to figure that out for me that would be great ...
Chris
-
model.selection
gives only currently selected entities
model.active_entities
gives only entities that are currently 'active' i.e. editable - e.g. inside a group edit when you would want to ignore other external things
model.entities
gives all of the model's entities, even those currently not editable.
It is often best to use 'active_entities' as it is equal to 'entites' if you are currently at the base model level but it's limited to the edited instance-definition/group's entities if you are not. If you use 'entities' and were to add something to them it is put at the base level - and it might then be outside of the group edit and lead to confusion/splats, whereas with 'active_entities' it is put at the lowest level in that edit, also note that definition.entities or group.entities returns the specified definition's or group's entities etc...
I think in your case 'model.entities' is what you want ?
-
Ok thanks but it's not quite there yet I'm afraid, and this is of course a very important part of the whole.
If I select all from the edit menu, and then use model.selection instead of active_entities I can abstract just the instances that show in that scene (page). Is it possible to "ruby" the select all?
Chris
edit added pic
-
Use 'model.entities' and filter it thus ?
insts=[] model.entities.each{|e|insts.push(e)if e.typename=="ComponentInstance"} ### insts is then an array containing all of the instances in the model ### you could also add names, groups etc
If you want only things that are active then use 'model.active_entities'.
I'm not sure you can get things only if they are visible in a scene ?
Do you mean not 'behind' the camera ?
You can of course get if they are hidden or on off-layers etc and remove them from the array... -
@tig said:
You can of course get if they are hidden or on off-layers etc and remove them from the array...
That's it ... but of course?? I'll get back on it tomorrow. In the meantime thanks for your help.
Chris
-
@chrisglasier said:
I'll get back on it tomorrow. In the meantime thanks for your help.
ChrisHere's the result:
# Lists components and groups (with hidden status) in a scene @dlg.add_action_callback("findComponents") {|d, p| model = Sketchup.active_model entities = model.active_entities a = 0 array = [] entities.each do |entity| if entity.class == Sketchup;;Group || entity.class == Sketchup;;ComponentInstance if entity.layer.visible? array[a] = [] if entity.class == Sketchup;;ComponentInstance array[a][0] = entity.definition.name end if entity.class == Sketchup;;Group array[a][0] = entity.name end array[a][1] = entity.hidden? array[a] = array[a].join(",") a+=1 end #if class end # if visible end #loop array = array.join(";") cmd = "receiveComponents('#{array}');" @dlg.execute_script (cmd) }
Tally ho!Chris
Advertisement