OnTransactionStart/Commit oddities?
-
Tested in SU 7.1.6860 : Same as SU8
Tested in SU 6.4.265 : Works as expected! One onTransactionStart and one onTransactionCommit
This looks to be a regression bug.
One that's turning out to be very troublesome... -
However, this didn't work as expected under SU 6.4.265
Sketchup.active_model.start_operation('test')
-onTransactionStart:#Sketchup::Model:0x10c1f660
onTransactionCommit:#Sketchup::Model:0x10c1f660
true
Sketchup.active_model.active_entities.add_cpoint [10,10,10]
-onTransactionStart:#Sketchup::Model:0x10c1f660
onTransactionCommit:#Sketchup::Model:0x10c1f660
#<Sketchup::ConstructionPoint:0x10c1bdf0>
Sketchup.active_model.active_entities.add_cpoint [20,10,10]
-onTransactionStart:#Sketchup::Model:0x10c1f660
onTransactionCommit:#Sketchup::Model:0x10c1f660
#<Sketchup::ConstructionPoint:0x10c1bb20>
Sketchup.active_model.commit_operation
-onTransactionStart:#Sketchup::Model:0x10c1f660
onTransactionCommit:#Sketchup::Model:0x10c1f660
true
-
So this is perhaps why the poster, over at GG was having problems ??
GoogleGroup: "transaction model question"
Would my idea of a "manual" callback be a valid workaround ?? (If not as I've shown, perhaps moving the call after the commit call?)
-
I was trying to use the observer because I wanted to catch any actions performed while my tool is active. It draws a UI based on the model geometry so I need to refresh when the geometry changes. And I wanted to catch events where a custom action from outside my plugin was triggered.
-
Does the
disable_ui
flag have any difference in the effect ??
Also.. I wonder about the transparency flags.But it does seem like a bug. We would want them to trigger only once, per operation, per model.
-
@thomthom said:
... I wanted to catch any actions performed while my tool is active. ...
And that stickin'
ToolsObserver
still will not fire for Ruby tools, right? -
@dan rathbun said:
Does the disable_ui flag have any difference in the effect ??
I tried both. Same results.
@dan rathbun said:
And that stickin' ToolsObserver still will not fire for Ruby tools, right?
onActiveToolChanged
triggers, but notonToolStateChanged
.
Besides, many actions are not triggered by a tool.Once more I seem stomped by observers. I swear, they'll be the bane of me.
-
@thomthom said:
@dan rathbun said:
And that stickin' ToolsObserver still will not fire for Ruby tools, right?
onActiveToolChanged
triggers, but notonToolStateChanged
.As I remember,
onActiveToolChanged
didn't give us any useful data.
Thetool_id
just says50000
(or similar,) for ANY Ruby tool, and "RubyTool" for thetool_name
.
I wish they would fix this...@thomthom said:
Once more I seem stomped by observers. I swear, they'll be the bane of me.
I suppose the built-in Standard Ruby
Observer
class won't work ether huh? -
Some 'transparent' tools like Zoom or Pan don't trigger.
Other native-tools do trigger... BUT some have names not exactly equivalent to what you might expect.
Plugin tools all return the same value/name ! -
I can't find any combination of methods or observers that will let me know reliably when an operation has been committed.
Guess it time to brush the dust of that old State of Observers list again...
-
@thomthom said:
I can't find any combination of methods or observers that will let me know reliably when an operation has been committed.
You want the Start of the OP, and the finish of the OP ??
-
...onChange half-works, ...onCommit doesn't ?
-
@dan rathbun said:
@thomthom said:
I can't find any combination of methods or observers that will let me know reliably when an operation has been committed.
You want the Start of the OP, and the finish of the OP ??
I want to catch the commit of an operation so I know I can rebuild the geometry cache I use to draw my tool's UI.
-
OK, so are you the one writing the operation ?? or is this one of Sketchup's normal undo operations ?
-
Bummer Thom, I just played with the oncommitaction observer yesterday for the first time and I did not encounter any oddities, but I did not test it more than just drawing a few lines.
-
@dan rathbun said:
OK, so are you the one writing the operation ?? or is this one of Sketchup's normal undo operations ?
I want to catch any operation. By me, by other plugins, by SU's native commands. I'm writing a custom Select tool and therefor any operation might occur while the tool is active - and I need to know when it does.
-
@chris fullmer said:
Bummer Thom, I just played with the oncommitaction observer yesterday for the first time and I did not encounter any oddities, but I did not test it more than just drawing a few lines.
Did you draw a few lines between start/commit_operation ? and the observers triggered only once?
-
I didn't attach a startaction observer. I only cared about actions finishing. And in the end I decided I really wanted to watch for entities being added to the model, so I moved away quickly from the transaction observers.
-
Yea, its the completion of an operation I'm interested in as well. It's just that I noticed it mis-triggers just like the end does.
@chris fullmer said:
And in the end I decided I really wanted to watch for entities being added to the model, so I moved away quickly from the transaction observers.
But do you want to be notified for each entity being created - before the operation has fully completed?
-
Ugh! The only workaround I can find at the moment is a nasty filthy timer hack.
<span class="syntaxdefault"><br />class ToolModelObserver </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">ModelObserver<br /> <br /> def initialize</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> tool </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">tool </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> tool<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">delay </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 0<br /> end<br /> <br /> def onTransactionStart</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> model </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#puts 'onTransactionStart'<br /></span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">stop_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">delay </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> <br /> def onTransactionCommit</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> model </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#puts 'onTransactionCommit'<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#@tool.onModelChange( model )<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># (!) onTransactionStart and onTransactionCommit mistriggers between<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># model.start/commit_operation.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Because of this its impossible to know when an operation has completed.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Executing the cache on each change will slow everything down.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># For now a very ugly timer hack is used to delay the trigger. It's nasty,<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># filthy and only works in SU8.0+ as UI.start_timer was bugged in earlier<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># versions.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Simple tests indicate that the delayed event triggers correctly with the<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># timer set to 0.0 - so it might work even with older versions. But more<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># testing is needed to see if it is reliable and doesn't allow for the<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># delayed event to trigger in mid-operation and slow things down.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Since the event only trigger reading of geometry the only side-effect of<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># a mistrigger would be a slowdown.<br /></span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">stop_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">delay </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">delay </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> 0.001</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> false </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#puts 'Delayed onTransactionCommit'<br /> # Just to be safe in case of any modal windows being popped up due to<br /> # the called method the timer is killed. SU doesn't kill the timer until<br /> # the block has completed so a modal window will make the timer repeat.<br /> </span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">stop_timer</span><span class="syntaxkeyword">( @</span><span class="syntaxdefault">delay </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">tool</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">onModelChange</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> model </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">invalidate<br /> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> end<br /> <br /> def onTransactionUndo</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> model </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#puts 'onTransactionUndo'<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">tool</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">onModelChange</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> model </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> <br /> def onTransactionRedo</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> model </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#puts 'onTransactionRedo'<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">tool</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">onModelChange</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> model </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> <br /> end </span><span class="syntaxcomment"># class ToolModelObserver<br /></span><span class="syntaxdefault"> </span>
I don't like it, in fact, I hate it. It opens up for worms. But so far it seem to kind of work.
I'd be happy for a cleaner workaround.
Advertisement