A few observations …
This method call may be asynchronous. The view may not be done redrawing before subsequent Ruby statements (saving the model) are executed.
Your code may need to use a temporary ViewObserver
and detect that the view has been changed and save the model in the in onViewChanged()
callback.
The temporary observer can be detached just before the file save in the observer callback. (Be careful here with saving. Internally, saving is moving towards a multi-threaded operation.)
Just noting that , if the path is changed, there will still be an old file with the old name
property and the view unzoomed at the previous file location.
Try to leverage existing library methods.
String concatenation creates excessive intermediate String
objects.
Ie:
file_new_path = File.join(dossier_cible, File.basename(file))
The File.join
method will automatically join the string arguments with the File::SEPARATOR
character (which is set to "/"
for the two operating systems SketchUp Desktop runs on.)
Note that you do not really need the else
clause in the above snippet, as you have a return
within the if
clause. Replace the else
with end
; and delete the unneeded end
after the puts
statement.
Also, you could replace …
if status == false
erreur = "#{erreur}\n#{file}"
return erreur
end
… with a one-liner using the conditional expression in modifier position. Ex:
return "#{erreur}\n#{file}" unless status
Generally it is poor practice to use boolean test expressions like :
if status == false
This is because the if
and unless
statements are already testing for truth and falsehood (respectively). So calling the #==
method upon the preceding object (and passing a true
or false
argument) is just adding unnecessary time to the execution of your code.
So use:
if !status
… or …
unless status
… in such places.