@tt_su said:
@fuzzybro said:
So I have identical inst3 transformations for both selected and deselected cases but inst1 and inst2 transformations are different in case of inst3 being selected and deselected.
You say selected, but do you mean open?
Selection doesn't affect transformation at all.
Hi Thomas,
This instance isn't opened, at least I don't open it myself but maybe SketchUp performs some sort of similar operation while creating a new Definition, Instance and placing components into it.
I'm using following code to get transformations of scene entities after new ComponentDefinition and Instance was created:
@model = Sketchup.active_model
# close all active edit sessions to prevent crashes
while (!@model.active_path.nil?)
@model.close_active
end
@model.selection.clear
# recursive function to go through all of the instances
export_component(@model.entities)
...
def export_component(entities)
if entities.class == Sketchup;;ComponentInstance
return if entities.hidden? or !entities.layer.visible?
# remember entityID, get instance local transformation and use it somehow
entity_list = definition.entities
else
entity_list = entities
end
entity_list.each { |entity|
if entity.layer.visible?
export_component(entity) if !entity.hidden?
end
}
end
This way I'm getting all the local transformations and the hierarchy of the model. Then I just have to go through the hierarchy and accumulate local matrices to get the global matrix as I described earlier.
But when I try to track changes via EntitiesObserver on create new component event I get 2 calls of onElementRemoved which removes instances inst1 and inst2, 1 call of onElementAdded, which creates inst3 and 2 calls of an onElementModified - one for ComponentIstance which has been added and one for ComponentDefinition for this instance. Oddly enough, I don't get any events for inst1 and inst2 as they have been removed before creating new component but they are present in new ComponenDefinition.entities. In onElementAdded I'm getting the transformation of a newly created inst3 and getting transformations of child Instances inst1 and inst2 which are present in the definition of inst3. At this stage I'm getting completely different transformations for inst1 and inst2 which results in a wrong global transformation when I' doing the multiplication.
I think than at onElementAdded call stage inst1 and inst2 might have not changed their matrices from model root space to inst3 local space, I'll check it in couple of minutes and report you in that.
But the other question is why I'm failing to receive events that removed instances inst1 and inst2 have been added or modified? I'm adding an EntityObserver to a newly created definition of an inst3 but don't receive any messages. I guess that I could use these events to get a proper matrices of a newly created inst1 and inst2 in the inst3 space.