Observers and deleted entity information work around

After reading other topics, I understand that, within an entity observer’s onEraseEntity method, I cannot access information from within the erased entity.

Is there an observer (or other way) to get an event that something is about to be deleted?

What I do with my current software is make the user use my UI to delete one of my entities. When this happens, I check to see what the entity is, and is it associated (via attribute information) with another entity.

For example, when a user deletes a window, I check to see what wall it belongs to. And then I close the hole in the wall as well as deleting the window.

The problem is, of course, the user can just select the window and delete it the old fashion way in sketchup. This leaves a hole in the wall. What I need to do is:
-see that the window is going to be deleted
-get relevant information out of the window’s attributes
-allow the delete to happen
-close the hole in the wall

If I cannot do this with an observer, does anyone know how I might go about this?

Thanks in advance for your help. You guys always have great insight and ideas. My project would be stuck in the mud without you.

When you create an instance of the wall you will define its initial attributes e.g.

I’m a wall1
I have several attributes like color, height and so
There are no windows: yet

When you create an instance of the windows and put on to the wall1 you will define its attributes e.g.

I’m a window1
I’m belonging to wall1, in a position here and there
My sizes are this and that

Then last part of creating this window to inform the wall1, by modifying attributes of wall1 to:

I’m a wall1
I have several attributes like color, height and so
There is a window now: window1
The window located here and there
I opened a hole for him with a size of this and that.

Now you can attach an observer to the window1 instance to listen if it is deleted.

When user delete this window1 instance the observer onEraseEntity method will fire. In that method you still can read the attributes of the wall - containing the information of opening - and take care to close the opening of the wall1, and modify back its attributes to initials.

# Class: Sketchup::EntityObserver

1 Like

Not at this time. There is an open request in the API Issue Tracker …


Generally, you attach the information you need to access to an object higher up in the entity hierarchy.
You can use a DefintionsObersever#onComponentInstanceRemoved callback to trigger the search through the “parent” object’s attributes.

@dezmo shows one scenario above.

What you might not realize is that an AttributeDictionary is an Entity sublcass object, and so can itself have an AttributeDictionaries collection of child dictionaries (say one for each window and/or opening.)

Thanks @dezmo and @DanRathbun.
My problem with these scenarios is the IFC export. Each of these items (wall, window, door, etc) is an IFC component. I need the information that I am saving in the component dictionaries to be exported to the IFC file when I do an export. If the information is not contained within the component’s dictionaries, it wont get exported to the IFC file.

Any thoughts?

This is is not the same topic as observers. Please search the forum for IFC discussions.

IFC export is slowly getting improvements.
Please fix your forum profile as there is no SketchUp Make 2021 edition.