Component definition list from Ruby vs SU window
-
I use this code to list all used component definition names:
def TESTXD.listcompnames1 $componentnames=[] Sketchup.active_model.entities.each{|e| TESTXD.listcompnames2(e) } $componentnames.uniq! $componentnames.sort! puts ($componentnames) end def TESTXD.listcompnames2(e) theclass=e.class if theclass==Sketchup;;Group gen=e.entities gen.each{|gent| TESTXD.listcompnames2(gent) } elsif theclass==Sketchup;;ComponentInstance $componentnames<<e.definition.name e.definition.entities.each{|ent| TESTXD.listcompnames2(ent) } end end
This gives me a list in the ruby console.
Now if I compare this list with the list shown in the components windows I see that certain definitions are available in ruby but not in the components window.Is this due to the fact that those component definitions are only used in nested component definitions? That makes no sense.
Or maybe I'm missing something. -
ok, hitting 'Expand' would be a good idea
-
If you have a lot of model entities, duplicate instances etc it can take a while to sift through it all.
It's quicker to iterate the model.definitions and compile lists of 'names' [or references] for all groups, components, used-components, unused-components and images thusdefs=Sketchup.active_model.definitions groups=[]; group_defs=[]; group_refs=[]; images=[] compo_names=[]; used_compo_names=[]; unused_compo_names=[] compo_refs=[]; compos_instances=[] compos_instances_names=[]; compos_instances_refs=[] defs.each{|d| if d.image? images << d.name elsif d.group? groups << d.instances[0].name group_defs << d group_refs << d.instances else ### compo compo_names << d.name if d.instances[0] used_compo_names << d.name else ### unused unused_compo_names << d.name end compo_refs << d compo_instances << d.instances ins=[]; d.instances.each{|i|ins << i.name} compo_instances_names << [d.name, ins] compo_instances_refs << [d, d.instances] end }
Choose which data you want to extract for later use...
-
Note that the
DefinitionList
include groups and images as well. As TIG mentioned, some components are hidden by default in SketchUp's Component Browser - sub-component of imported models for instance. They are marked withComponentDefinition.internal?
.Detailed explanation of the
ComponentList
andComponentDefinitions
in SketchUp: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/ -
great, thank you both for the information!
Advertisement