Hi all, I’m stuck on something simple I think. When I create an InstancePath using a component and another component that is some degree of nesting inside of that component I get back a path that only contains the root and the leaf.
Say I create a batch of nested components like this:
def add_components
mod = Sketchup.active_model
ents = mod.entities
names = ["orange", "yellow", "blue", "green", "red"]
for name in names
x = mod.definitions.add(name)
face = x.entities.add_face([0,0,0], [1,0,0], [1,1,0], [0,1,0])
face.reverse!
face.material = name
face.pushpull(1)
end
container4 = mod.definitions.add("container4")
red = mod.definitions.find{|d| d.name == "red"}
transformation = Geom::Transformation.new([0,3,0])
container4.entities.add_instance(red, transformation)
green = mod.definitions.find{|d| d.name == "green"}
transformation = Geom::Transformation.new([0,0,0])
container4.entities.add_instance(green, transformation)
container3 = mod.definitions.add("container3")
blue = mod.definitions.find{|d| d.name == "blue"}
transformation1 = Geom::Transformation.new([0,0,0])
container3.entities.add_instance(blue, transformation1)
transformation2 = Geom::Transformation.new([0,3,0])
container3.entities.add_instance(container4, transformation2)
container2 = mod.definitions.add("container2")
yellow = mod.definitions.find{|d| d.name == "yellow"}
transformation1 = Geom::Transformation.new([0,0,0])
container2.entities.add_instance(yellow, transformation1)
transformation2 = Geom::Transformation.new([0,3,0])
container2.entities.add_instance(container3, transformation2)
container1 = mod.definitions.add("container1")
orange = mod.definitions.find{|d| d.name == "orange"}
transformation1 = Geom::Transformation.new([0,0,0])
container1.entities.add_instance(orange, transformation1)
transformation2 = Geom::Transformation.new([0,3,0])
container1.entities.add_instance(container2, transformation2)
ents.add_instance(container1, IDENTITY)
end
add_components
Then I get the variable names of the components
red = mod.definitions.find{|d| d.name == “red”}.instances[0]
green = mod.definitions.find{|d| d.name == “green”}.instances[0]
blue = mod.definitions.find{|d| d.name == “blue”}.instances[0]
yellow = mod.definitions.find{|d| d.name == “yellow”}.instances[0]
orange = mod.definitions.find{|d| d.name == “orange”}.instances[0]
container4 = mod.definitions.find{|d| d.name == “container4”}.instances[0]
container3 = mod.definitions.find{|d| d.name == “container3”}.instances[0]
container2 = mod.definitions.find{|d| d.name == “container2”}.instances[0]
container1 = mod.definitions.find{|d| d.name == “container1”}.instances[0]
Then:
path = Sketchup::InstancePath.new([container1, red])
… and I get only: path[0] is container1 and path[1] is red. Nothing inbetween.
What am I doing wrong?