Hi there,
I have an extension where we create our products(ComponentInstance
) from a UI::HtmlDialog
. UI::HtmlDialog
has images, on clicking the image we create a 3D model. This UI::HtmlDialog
also has tabs. One of the tabs is edit, which shows properties on the selected 3D model. The user can update these values, which will reflect in the 3D model.
I have a SelectionObserver
which I attach to selection like this Sketchup.active_model.selection.add_observer
whenever a new product is created or loaded from a saved file.
During the update operation I mentioned above(From UI::HtmlDialog
)
- I remove the observer using
Sketchup.active_model.selection.remove_observer
- Update the 3D model
- I add back the observer
Sketchup.active_model.selection.add_observer
Note: I only maintain only one observer instance
def remove_product_selection_observer
Sketchup.active_model.selection.remove_observer(@@product_selection_observer)
end
def add_product_selection_observer
if(@@product_selection_observer == nil)
@@product_selection_observer = ProductSelectionObserver.new
end
Sketchup.active_model.selection.add_observer(@@product_selection_observer)
end
Use case:
- Create a 3D model from
UI::HtmlDialog
. Call it âproduct 1â - Create another 3D model from
UI::HtmlDialog
. Call it âproduct 2â - Now switch the tab in
UI::HtmlDialog
to edit(edits âproduct 2â). Update some properties.
Point 3 code basically looks like this
product.remove_product_selection_observer
product.update(updated_properties)
product.add_product_selection_observer
Now when I select âproduct 1â none of the methods in the observer gets fired. I rely on these observer events to figure out that a different product is selected and based on that I send the selected product properties to UI::HtmlDialog
.
Q: Why the selectionObserver method is not getting triggered?
Is there any better way to debug than just making sure the observer is attached and the observerâs methods are fired?
P.S: After point 2 in the use case, if I double click on my product(componentInstance), I start getting observer events fired correctly.
How can I debug this further to figure out why my observer is not firing events.