The 'Sketchup.active_model.path' unable to get the correct results, and the 'trim' is time consuming

github issue
1.The user creates a new file. The ‘Sketchup.active_model.path’ (in ModelObserver events ‘onSaveModel’) is empty in ‘onSaveModel’ when the user saves the file.

2.The user has saved the file. The ‘Sketchup.active_model.path’ (in ModelObserver events ‘onSaveModel’) is not a new path when the user saves as the file.

I moved your topic to more relevant category of the forum…

1-2. Beside that the observes are a little beyond of my current knowledge… can you please elaborate some more information with examples what you want to achieve?

DefinitionList#import for importing a 3d model file as a component definition, without activating the UI for placing an instance

You may need to look for:

The add_instance method adds a component instance to the collection of entities.
The place_component method places a new component in the Model using the component placement tool…

To activate the selection tool you can refer to:

But again, it is not entirely clear what you wan to achieve, can you please elaborate some more information with examples…!

This is an expected behaviour… But again, it is not entirely clear what you wan to achieve, can you please elaborate some more information with examples…


That doesn’t sound ideal. Could be a bug. For now you can get around it using a timer (UI.start_timer(0)) to have your code run after the model save, but it’s a bit of a hack.

Feel free to log this in our API issue tracker: Issues · SketchUp/api-issue-tracker · GitHub

For 3-4 I refer to Dezmo’s response.

1 Like

Looks like the observer callbacks are firing before the model’s properties are updated.

class ModelSpy < Sketchup::ModelObserver
  # Attach the observer.
  def attach(model = Sketchup.active_model)
  def onSaveModel(model)
    puts "onSaveModel: #{model.path.inspect}"
  def onPostSaveModel(model)
    puts "onPostSaveModel: #{model.path.inspect}"
1 Like

I open ‘a.skp’, and I modify the model, then I open ‘b.skp’.
The save is triggered.
When I use UI.start_timer(0), the Sketchup.active_model.path is ‘b.skp’, not ‘a.skp’.
So it’s no use using a timer.
I think the method onSaveModel should be called after the Sketchup.active_model.path is updated.
What is 'Dezmo’s response'?

When there are two groups in the model, This method g1.trim(g2) takes 0.1s.
When there are two thousand groups, This method g1.trim(g2) takes 100s.
The (g1、g2) is always the same two groups, only the total amount of models in the model is different

yes, you are right.

If I use definitions.load, It takes more time than Sketchup.active_model.import.

I think this method (import) should be improved as follows: import(filename, show_summary,tr) ⇒ Object

That cannot happen as it would be a breaking change.

Filed 4 years ago (1 NOV 2017):

We expected you to use a bit of a time delay to let the SketchUp core update the model’s properties.
Within the timer’s block you would need to assign the new model path to a persistent @variable.

This is a different issue, please open a new topic. (It has been discussed in the past, perhaps do a search within this or the Developers category.)

This is also a different subject (but an interesting one.) Again, please begin a new topic.

P.S. - You have not yet earned your “Read Guidelines” badge. Please read them.

EDIT: Thank you for earing that badge !

1 Like