Implement a onProgressChanged-like observer for entities?


#1

Hi, I have a requirement to capture/track the changes to an entity’s bounds in realtime, I need to display the values as it progresses to a web-dialog. something like how the onProgressChanged listener works in java,

The EntityObserver has the onChangeEntity method which is triggered after the entity is modified , is there a way I could capture and track the changes e.g., say while a user is dragging an edge to resize.


#2

I’m afraid not - we have no observer mechanism that trigger for the mouse/key events of our Tools. May I ask what you are making?


#3

Thanks ! but Is there any way I can achieve a similar feature?? It’s just an add on that shows an entity’s measurement on a web-dialog, and so we decided it’l be a good feature if we’re able to reflect the realtime changes in a bigger space instead of a tiny box in the status bar


#4

Timer…? Ugly - and fragile -, but I cannot think of any other hook to use. And I’m not even sure if you are able to get the data in the middle of native tools like that any way.

By the way - is this related to your own custom Ruby tool? In which this is much easier as you actually have control over the mouse events. But for generic capture data outside the bounds of your own tool the API has nothing to offer I’m afraid.


#5

More generally… I think the idea of a Sketchup::BoundingBoxObserver superclass has merit.

In the past, others have wanted to catch when an object’s bounds changed, and especially rotated.

There would need to be some restrictions during it’s use, such as:

  • Use for informational purposes only ?
  • It’s use should not interfere with the current tool, ie:
    • Any call to select another tool would be ignored
    • Any call to push or pop the toolstack would be ignored
  • Probably should avoid firing other observers ?
    • don’t change the model
    • cache any changes or attributes to be written until the tool returns to state 0.

Others ?


#6

Thanks but out off the top of your mind are there any extensions that you’re aware of that does this or has a similar feature?
Or else can we write our own Observer to achieve it i.e capture mouse events like drag and release?


#7

I’ve not seen extensions that does such thing, no.

You’d have to hook into the low level system events your self, but I guess that could work. But remember you also have users who use keyboard shortcuts.
And note if you did do this and made it work - you really want to make sure you make no model changes as that could interfere with the active tool and probably make SketchUp crash because you change the state of the model during an operation which isn’t your own.