[HowTo?] Find Instance parent's Instances
-
Is there any API to find the parent ComponentInstance of a ComponentInstance ? (or any trick code for that?).
Reading the documentation for entity.parent (below) I wonder why the parent method of a ComponentInstance give back the definition of its parent's Instance. If the parent method give back it's ComponentInstance (and not its parent's Definition), if one needs that parent definition it should just ask for parent.Definition.
Am I missing something ? Is the part of the documentation that talks about "the future" addressing that ?
Thank you.
*parent
The parent method is used to retrieve the parent entity of the entity. Think of the whole SketchUp model as a "Component Definition", just as you can import a .skp model as a component into another .skp model. Such is this reference. If an entity belongs to the top level model.entities list, then its parent with be the "Model". A Component Instance will have as its parent a Component Definition. An entity within a Group will also have as its parent a Component Definition. In the future, there may be a new "container" that more accurately describes an entities "container".*
-
Hi marcio,
Not sure if I understood you well, but when you say@unknownuser said:
the parent method of a ComponentInstance give back the definition of its parent's Instance
you're wrong here.
If A is a component instance, A.parent returns the active_model (assuming you're not mining through nested components).And:
@unknownuser said:
Is there any API to find the parent ComponentInstance of a ComponentInstance ?
This doesn't make sense to me. The parent of a component instance cannot be a component instance.
You can think of A.definition as almost the 'parent' of this instance.
Hope this helps, -
Hi Didier, maybe I'm misunderstanding how SketchUP works. Please let me explain how I get it with a bike example:
[ComponentInstance][ComponentDefinition] <Instance Name> <Definition Name>
[0x11][0x01] <my><Bike>
[0x12][0x02] - <Front><Fork>
[0x13][0x03] - - <this><Wheel> .... front wheel
[0x14][0x02] - <Rear><Fork>
[0x13][0x03] - - <this><Wheel> .... rear wheelSuppose I select the front wheel instance. Its parent is ComponentInstance:0x12.
How can I discover that the front fork (ComponentInstance:0x12) is the parent of front wheel and not the rear fork (ComponentInstance:0x14) ?
Thank you
-
Is this what you're looking for?
def parent_of selset = Sketchup.active_model.selection for e in selset if (e.kind_of?(Sketchup;;ComponentInstance) ) compo_name = e.definition.name parent_name = e.parent.name puts compo_name puts parent_name end end end
Emmanuel
-
@didier bur said:
Hi marcio,
Not sure if I understood you well, but when you say@unknownuser said:
the parent method of a ComponentInstance give back the definition of its parent's Instance
you're wrong here.
If A is a component instance, A.parent returns the active_model (assuming you're not mining through nested components).And:
@unknownuser said:
Is there any API to find the parent ComponentInstance of a ComponentInstance ?
This doesn't make sense to me. The parent of a component instance cannot be a component instance.
You can think of A.definition as almost the 'parent' of this instance.
Hope this helps,But nested components is his example, and I've often had the same issue of wanting to know the containing space for a nested g/c. Fortunately, there's a new API command in SU7 that will give the "path" of the entity spaces (e.g. instance1>group1>group2>instance2):
model=Sketchup.active_model model.active_path
this will return 'nil' if you're in the model.entities space, and will return an array of all the groups/components you've entered (manually).
-
That is exactly what I was looking for !
Thank you
MarcioObs: A new documentation for SU7 Ruby APIs could be nice. It could be a kind of open Wiki so we all could help improve it, as write documentation is ... boring.
Advertisement