What is this error: NotImplementedError : there is no tool manager

I get this error NotImplementedError : there is no tool manager.

This happens on Mac, in the context of closing a model via the API (model#close), when trying to access the current toolname via model.tools.active_tool_name.

Similarly, it looks like when closing a model on Mac, there is a brief moment where there is no model (i.e. Sketchup.active_model == nil), which is an issue because a refresh of the toolbar icons (equivalent to UI.refresh_toolbar) is also triggered when closing a model.

... withdrawn.

Which model’s toolstack are you wanting t access during the close?
The closing model or the next one on the Mac’s modelstack ?

I would think that we should be using the AppObserver#onActivateModel() callback to get a reference to the next model (on the Mac’s model collection) that will be activated.

Okay, if speaking of a validation proc, you could use a conditional to test if Sketchup.active_model is falsey and/or if it’s valid. If not then MF_DISABLED|MF_GRAYED, otherwise MF_ENABLED if perhaps some other condition test is true.

I suppose it also would not hurt if the validation was wrapped within a begin ... rescue to trap such exceptions with the collection objects as they are not Entity subclasses so do not have a valid? method.

    cmd.set_validation_proc {
        if Sketchup.active_model && Sketchup.active_model.valid? &&
        Sketchup.active_model.tools.active_tool_id == SOME_TOOL
      rescue => error

The execption is better than SketchUp crashing.

The original question is about the WHAT, not a workaround.

This error happens when you call: model.tools.active_tool_name.

When it occurs,

  • model is not nil
  • model is valid (i.e. model.valid? returns true)
  • model.tools is not nil

So, it is useful to understand what this error is, so that I can know what else can be tested?

And the error happens when

  • you close a model (manually or via Ruby)
  • when you open a model via the API