Please help me to get a group's layer
-
Hi there,
Im beginner to Sketchup ruby,
Im writing something like this:a = instance.parent.layer.name
with "instance" is a component instance placed inside a group/component. "instance.parent" returns a ComponentDefinition, not the instance, so that i cant get the layer's name i wanted.
Is there some way for me can get this?
Thanks. -
a = instance.parent.**instances[0].**layer.name
Should now return the instance's parent [definition], then the group, then its layer, then that layer's name. -
Hey TIG, what if the parent group definition has more than 1 instance, and the target is not the first in the instances collection ?
Could a coder "tag" the target instance by pushing it's reference into the selection set, and then iterate the instances collection looking for a match ?
... Or, do they have to walk the model's entities tree ?
-
I did think of that !
But since we don't know the rest of the OP's code I assumed that the group was unique.Without more info, if there are multiple instances of the instance's parent group definition, then how can we know which of those the user intends to reference...
If the instance is simply derived from its definition, and the user knows it's always nested inside a group, then he only needs to worry if there are multiple group instances...
If the user has 'selected' the instance previously, e.g. by editing the group containing it then the group itself has been automatically made_unique, so there is only one instance.
Since the OP is not currently at an advanced level I suspect he is not picking the instance using a tool & pick_helper.
However, if the OP were doing this, then the pick_helper itself could be used to find the path to the picked instance and from that determine the actual instance of the group that the picked instance is inside ?
In fact I think this is the only likely solution ?
Since the same instance occurs inside several copied groups the actual container's instance is needed ?With v2017 the new instance_path method might help - from an input_point - but who knows ? ...
-
Good answer(s)!
-
(This last question needs it 's own thread.)
-
Thank you Masters.
I have another problem:
I wrote code to make BOM base on ComponentReport of TIG. Then I place data on a html datatable.So I have to replace all "\n" by "<br>" like this:des=c.definition.description des=des.gsub("\n","<br>")
Then the datatable looks good. Then I save data in a .xlsx file. Still look good when openned in Excel. But when I inserted it to LayOut, it create "x000D" before every new line in cell. Please help me how to solve this. Thanks a lottt.
Advertisement