-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ModelObserver: onSaveModel / onPostSaveModel wrong path in case of SaveAs. #8
Comments
Logged as SU-38305 |
@thomthom When will this bug be fixed? |
With the timer block delay suggested by @Eneroth3 ... module Issue8
class ModelSpy < Sketchup::ModelObserver
# Attach this observer to the model object.
def attach(model = Sketchup.active_model)
model.add_observer(self)
end
### AppObserver callbacks:
#
def expectsStartupModelNotifications
return true
end
def onNewModel(model)
attach(model)
end
def onOpenModel(model)
attach(model)
end
### ModelObserver callbacks:
#
def onSaveModel(model)
puts "onSaveModel (no delay): #{model.path.inspect}"
UI.start_timer(1.0,false) {
puts "onSaveModel (delayed): #{model.path.inspect}"
}
end
def onPostSaveModel(model)
puts "onPostSaveModel (no delay): #{model.path.inspect}"
UI.start_timer(1.0,false) {
puts "onPostSaveModel (delayed): #{model.path.inspect}"
}
end
end
if !defined?(@loaded)
# Instantiate and attach an new ModelSpy to SketchUp:
Sketchup.add_observer(ModelSpy.new)
@loaded = true
end
end ... the following is returned ...
~ |
Thank you. But this plan can't completely solve my problem. I open ‘a.skp’, and I modify the model, then I open ‘b.skp’. |
I think we all agree that ALL the model object's properties should to be updated before the observer callbacks fire.
On Windows the save for "a.skp" should occur before the file browser ever let's the user select "b.skp".
Again, nobody ever suggested you call Are we misunderstanding your problem ? Can you post a reproduceable code snippet ? |
A timer with a value of puts "Before timer line"
UI.start_timer(0, false) { puts "Hello Timer" }
puts "After timer line" Output:
|
Okay. I stand technically corrected. However this fact still will not give enough delay to allow the model's properties to be updated as the engine is still working it's way through the Model "onSave" callback queue, and the timer block will run before @LItterBoy-GB's callback returns. So we could modify what I said to be ... the use of a timer with a So it is really "six and one-half dozen the other". |
@DanRathbun I'm very sorry for my previous reply was too messy. I want to explain that timer can't solve all the problems of saving. I hope the government can pay attention to this issue. new file => save 'a,skp'
open 'a.skp' => save as 'b.skp'
open 'a.skp' =>modify 'a,skp' => new file
open 'a.skp' =>modify 'a,skp' => open 'b.skp'
class TestOb
def onSaveModel(model)
id = UI.start_timer(0.001, false) do
UI.stop_timer id
puts "model.active_path=>#{model.path}"
puts "Sketchup.active_model.active_path=>#{Sketchup.active_model.path}"
end
end
def onNewModel(model)
model.add_observer(self)
end
def onOpenModel(model)
model.add_observer(self)
end
end
test_ob = TestOb.new
Sketchup.add_observer(test_ob)
Sketchup.active_model.add_observer(test_ob) |
a. You do not need to use b. Your code snippet is setting the delay to ONE MILLISECOND ! Once again, any c. I CLEARLY showed that setting a full 1 second delay was enough of a delay to get the proper model path (with a small number of extensions loaded.) It MAY take even more of a delay if many extensions attach model observers with def count_callbacks
num = 0
ObjectSpace.each_object {|o|
num += 1 if o.respond_to?(:onSaveModel)||o.respond_to?(:onPostSaveModel)
}
return num
end |
I would add that the problem persists in SU2023.1 even with the Consider this code: def save_observer_launch
Sketchup.add_observer MyObserver.new
end
class MyObserver
#Sketchup events
def expectsStartupModelNotifications ; true ; end
def onNewModel(model) ; model.add_observer(self) ; end
def onOpenModel(model) ; model.add_observer(self) ; end
#Model events
def onPreSaveModel(model) ; puts "PRE-SAVE: #{model.path.inspect}" ; end
def onSaveModel(model) ; puts "ON-SAVE: #{model.path.inspect}" ; end
def onPostSaveModel(model) ; puts "POST-SAVE: #{model.path.inspect}" ; end
end When saving a New model to a given path, this produces:
|
1). RubyAPI - SketchUp 2017,
2). Windows.
Sketchup.active_model.path is not updated properly in case of SaveAs - ModelObserver is unable to get new model.path.
Simple plugin:
https://www.dropbox.com/s/36gmiw0bfo6njos/ModelObserver_SaveAs.rbz?dl=0
The text was updated successfully, but these errors were encountered: