Do we have a observer that can observe if there is a changes in the component definition?

Lets consider I have one rectangular solid(eg. 4x4x4 (cm)). If I change its size (eg. 5x4x4 (cm)), then it should notify us that shape is changed.

I have used following APIs. But their behavior is not meeting with our requirement.

class MyDefinitionsObserver < Sketchup::DefinitionsObserver
        def onComponentAdded(definitions, definition)
            UI.messagebox("onComponentAdded: #{}")

        def onComponentPropertiesChanged(definitions, definition)
            UI.messagebox("onComponentPropertiesChanged: #{definition}")

        def onComponentRemoved(definitions, definition)
            UI.messagebox("onComponentRemoved: #{definition}")

        def onComponentTypeChanged(definitions, definition)
            UI.messagebox("onComponentTypeChanged: #{definition}")

Let me know if there is any other way to achieve this.

Maybe: Class: Sketchup::EntityObserver — SketchUp Ruby API Documentation

or depending on how you modify the component maybe: Class: Sketchup::ToolsObserver — SketchUp Ruby API Documentation

I just did a quick test, and EntityObserver#onChange() does not fire when attached to a definition and it’s Entities collection members are modified.

However, attaching an EntitiesObserver subclass instance to the definition’s Entities collection will fire the onElementModified callback for each child Face that changes.

  • Weirdly, even though the edges bounding the 6 faces must also change, they are not sent to the callback when I use Entities#transform_entities to scale the entire collection of elements.
  1. Editing the component:
  2. Editing Completed:

When I edit the component definition and changed its size, then the callback is not getting called.

But when I revert that, then callback is getting called

I want a callback should get called at the time when I commit the definition changes.

I again refer you to what I wrote in my previous reply.

Are you suggesting following approach:

        definitionss = model.definitions
        definitionss.each do |definition|
            entitiesToObserve = definition.entities
            UI.messagebox("Def Name: #{}: enitities count: #{entitiesToObserve.count}")

If yes, this is not working. OR if anything else you are suggesting, can you please provide code snippet. It will be more helpful.

I understand that @DanRathbun meant this

I wanted to do something similar to what you intend but came to the conclusion that it needed too many observers and was not good for the user.
To analyze all the behavior of a component, I needed the following observers:

DefinitionsObserver → onComponentPropertiesChanged.

  • the first time that I classify a component as IFC
  • if you change the classification to another category
  • If you change definition data

EntitiesObserver → onElementModified

  • when I change the scale of an instance of the component

InstanceObserver → onOpen & InstanceObserver → onClose.

  • modifying the interior of the geometry, i.e. changing the position of an edge, changing the size of a hole or generating a hole, etc.

Some were running multiple times and I decided that this was not the best option. Finally I generated a script that went through all the components and updated the information in one go.


I suppose your are using entities (each entity inside the component definition) wrongly. You need to observe instances (each component with the same definition)

I am aware of the activity in this topic. It is RUDE to ping me when I am already participating in this topic.

NO, I am not going to do your work for you. Just because I posted some comments, does not mean that I guarantee that the API will work for you in the way that you wish. (Ie, there are still many API bugs yet unfixed listed in the tracker at GitHub, some for observers.)

My comments are likely to only be part of the information you may need to solve your challenge.
See the examples in the API documentation and the comments by others in this topic.

I sincerely apologize if my previous message came across as rude or disruptive. My intention was not to ping you inappropriately but rather to seek guidance from someone with your expertise, as you have consistently provided valuable insights in this forum.

I understand that you are already actively participating in the topic, and I appreciate your contributions. I realize now that my approach may not have been ideal, and I’m committed to respecting the community guidelines moving forward.

If you have any specific suggestions or recommendations regarding the code snippet I posted, I would be grateful for your input. However, I completely understand if you prefer not to provide direct solutions and appreciate any guidance or resources you can share.

Thank you for your understanding!

I accept your apology.


Yes. I reserve the right to contribute where and when I choose. Some coding challenges interest me, others not as much. Sometimes I know that there are other gurus here who know more on a topic, so I’ll wait and let them weigh in.

Often, I am busy with other things and cannot get deep into posted coding challenges. It depends. If I can, and it interests me, I may contribute. I may not.

I do not care for having the “spotlight put on me” in that manner. I also prefer that a coder first make an honest attempt at coding the solution themselves. (I have arthritis in my hands and it is usually easier to edit prewritten code than code it all from scratch.)

With regard to observers, their use is complex and there are many open bugs with them yet unfixed.
So, providing a working example may not be a simple few minute thing. It requires coding, loading code into SketchUp and testing, editing code, reloading testing, repeat, repeat, etc.

If you cannot find a solution, please open a bug report or a feature request in the official API tracker.

1 Like