Bug Splat on erase!
-
Hello.
I want to erase some geometry before saving a model,so I use the onPreSaveModel observer to do this.
Erasing is executed correctly,but after it the Bug Splat screen is happening.
I would like to find a way to do it without Bug Splat screen.
Here is the code,just select one item and it will be erased before saving the model.class MyModelObserver1 < Sketchup;;ModelObserver def onPreSaveModel(model) selection = Sketchup.active_model.selection selection[0].erase! end end Sketchup.active_model.add_observer(MyModelObserver1.new) class MyAppObserver1 < Sketchup;;AppObserver def onNewModel(model) Sketchup.active_model.add_observer(MyModelObserver1.new) end def onOpenModel(model) Sketchup.active_model.add_observer(MyModelObserver1.new) end end Sketchup.add_observer(MyAppObserver1.new)
-
http://code.google.com/apis/sketchup/docs/ourdoc/modelobserver.html
Read the Introduction section:
@unknownuser said:
Performing any edit operations of your own (such as modifying the model) inside the observer callback should be avoided, as it could cause crashes or model corruption.
if
Drawingelement#erase!
causes a BugSplat!, try instead:class MyModelObserver1 < Sketchup;;ModelObserver def onPreSaveModel(model) selection = model.selection unless selection.empty? model.active_entities.erase_entities(selection[0]) model.active_view.refresh() end end end
... but may not work either.
-
Uff,your solution didn't resolved the problem(same result),but helped to understand it.
It seems that the onPreSaveModel observer is not the real pre save observer.I would need a pre-pre save observer. -
A SelectionObserver ?
-
I have a group that is generated when a tool is activated and deleted when a tool is deactivated.
The problem is when the model is saved when a tool is active (auto save or user save).
I don't want that group to be saved in the model,so I have implemented the onPreSaveModel observer to delete the group.
But I cannot get rid of the BugSplat. -
Make sure you read (and bookmark,) these topics:
And ThomThom webpage:
State of Google SketchUp's Observers
@unknownuser said:
(http://forums.sketchucation.com/viewtopic.php?f)":3um4efab]Other notes
Another thing I learned was that doing modifications to the model on observer events can cause lots of problems.β’If a script is doing something which trigger an event that modifies the model it will break the undo stack. I also seem that it can make SU unstable. You could potentially cause infinite loops.
β’After consulting with Scott it seems that queueing up a list of modifications to be done to the model and executing the list onModelObserver.onTransactionCommit
is the most reliable way to do it. -
Mat I ask what your temp group do? What is it function?
(just wondering if there might be alternatives to creating temp geometry here - such as using view.draw for instance...) -
@thomthom said:
Mat I ask what your temp group do? What is it function?
Im using it to highlight some surfaces ,because I can draw only lines (and points and text) with view.draw.
Is there any samples of using the ModelObserver.onTransactionCommit and other onTransaction functions?
I cannot figured out what are they for. -
@voljanko said:
@thomthom said:
Mat I ask what your temp group do? What is it function?
Im using it to highlight some surfaces ,because I can draw only lines (and points and text) with view.draw.
Incorrect - you can draw filled shapes with view.draw . GL_TRIANGLES, GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_POLYGON will let you do that. But note that in SU prior to version 8 the fill is always black. But as of v8 it works great. You can even use transparent fill. -
Thank you for pointing this out,I was really stacked wit this BugSplat.
So, more new functions to learn. -
But also Dan's suggestions have positive results:
In the activate method of the tool I have put theSketchup.active_model.start_operation "myTool",true,true,false
And I have put the
Sketchup.active_model.abort_operation
in the deactivate method of the tool and in the onPreSaveModel model observer.
Now the group is disappear before saving the model.
Thank you both.
Advertisement