How to get the root Model in the scene?

btw, to esily detect if a ComponentDefinition is open for editing you can do this test

def inside_component?(definition)
  path = (Sketchup.active_model.active_path || [])# This method should in my view return an empty Array, not nil, when the model root is the active context.
  instance = path.last

  instance && instance.definition == definition
end
3 Likes

+1 for this.

@DanRathbun Would it be possible to post a refinement to add this functionality?

inst.model_transformation
inst.model_transformation = tr
group.model_transformation
group.model_transformation = tr

I don’t have the time right now, but I’m sure many people would find it useful.

I was thinking along the same lines:

vertex.local_position()

vertex.model_position()

With regard to the others, I think they’ve been asked for. It is hard for us because we cannot get the nesting path unless the object is open for edit, and we cannot cause the object to be opened for edit.

There is a “feature” of Attributes where a Point3D stored in a Dictionary is updated when the Instance is moved. Could this be exploited to store the model transformation of the Instance? (I am unable to test this now)

Does it work with a Transformation?

You may not have noticed, but the Dynamic Components extension defines a couple of global hashes, that store transforms (with object_id as key I think, or perhaps just object reference,) as the user clicks down into instance nesting.

They are:

$global_edit_transforms

$local_edit_transforms

SketchUp will download it as a new component instance in your model – as opposed to replacing your the selected component.

FYI

The root of the model has the IDENTITY transform (which is a global constant that the API adds to the Ruby objectspace.)

There is also the model instance method:
Sketchup::Model#edit_transform

Yes that I know. Anyway since my last topics I have started to shift my mind towards how SU is actually operating, and realizing its a pretty pure MV pattern, now I know how to handle its data and my needs for realtime sync with an external app :), thanks for all the hints.