Hi guys,
I’m trying to position an Entity to a Construction Point that I have previously placed in case of the used want an option (I can change to any placed position object if the Construction Point limit the actions).
This entity is placed in an object hierarchy at the right position to add an another object correctly connected to the first one.
As I understood, under SketchUp, the positions are Local to the context the entity is positioned. Maybe I misunderstood something but the fact is that I need to:
1 | Get the world positions, of the :
° Entity marker placed in the first object.
° Entity marker placed in the second object added lately.
2 | Calculate the deformation (SecondObjectWorldTransfo - firstObjectWorldTransfo = deltaTransfoToApply).
3 | Apply the delta tansfo calculated to the second object.
The 2nd and 3rd step I know how to do this but I’m blocked on the first one. There could be two ways to do this:
• The simple one could be a method to retrieve the world transformation but I wasn’t able to localize it after lots of time spent on the really nice SketchUp Ruby API documentation.
• Retrieve all the locals transformations of the hierarchy of the placed maker to go up to the model. Then I could combine them and calculate the world transformation. But the fact is that I can’t retrieve the path from the model origin to the maker entity.
I will avoid explaining all the tracks I have found one this site but wasn’t able to understand correctly and do what I need to do.
Is someone has any tracks or informations/clues to open me the path to any solution ? I’m sure that I missed something because it’s basic works
Thanks for your appreciated help !!!
You can only go up if all the contexts are unique. Ie, that each level has only one instance of the level’s definition.
Otherwise, you can only go down from the top-level model entities, and build an InstancPath
object, and then get the world transform via it’s #transformation
method.
If you do not know this instance path, then the only alternative is to walk the whole model hierarchy (keeping a nesting path array as you go) until you find the right “marker”.
3 Likes
Thank you Dan for the explanation that confirm what I understood.
Thanks for the explanations of the InstancePath that I need to rebuild. I thought I could extract it from the “marker” entity which is a ConstructionPoint which inherit from Sketchup::Entity than have a parent method.
The fact is taht I stored the marker in a variable and I need to rebuild the path by walking-up the model hierarchy. The fact is I need to go throught different levels of Sketchup::Group. When I called the parant mathod, it returns a ComponentDefinition from which I can extract The instance because, as you said, that each level has only one instance of the level’s definition.
Thank again for all the explanations and give my clue to build a solution
Exemple :
cp0 = Sketchup.active_model.entities.add_cpoint([0,0,0])
gr1 = Sketchup.active_model.entities.add_group
gr1.move!([100.mm,0,100.mm])
cp1 = gr1.entities.add_cpoint([0,0,0])
gr2 = gr1.entities.add_group
gr2.move!([100.mm,0,100.mm])
cp2 = gr2.entities.add_cpoint([0,0,0])
gr3 = gr2.entities.add_group
gr3.move!([100.mm,0,100.mm])
cp3 = gr3.entities.add_cpoint([0,0,0])
parent = cp3
path =[]
loop do
if parent.class == Sketchup::ComponentDefinition
#Set the instance as real parent
parent = parent.instances[-1]
else
#Store the active parent to the path
path << parent
#Jump to the next parent
parent = parent.parent
end
#Stop when reaching the highest level
count += 1
break if parent.class == Sketchup::Model or count == 20
end
puts path.reverse
1 Like