sketchup-ruby-api-tutorials
sketchup-ruby-api-tutorials copied to clipboard
Initial license get during load
At the bottom of the Licenseing tutorial module ...
"master/examples/99_license/ex_hello_license/main.rb"
# Fetching a license here so that it will be checked by SketchUp during
# startup. This will include the extension in the dialog that warns about
# missing licenses.
ext_id = '6cce9800-40b0-4dd9-9671-8d55a05ae1e8'
ext_lic = Sketchup::Licensing.get_extension_license(ext_id)
This is a bit contradictory to the text in the self.create_cube method.
How about wrapping it within an init method ?
def self.init
# Fetching a license here so that it will be checked by SketchUp during
# startup. This will include the extension in the dialog that warns about
# missing licenses.
ext_id = '6cce9800-40b0-4dd9-9671-8d55a05ae1e8'
ext_lic = Sketchup::Licensing.get_extension_license(ext_id)
end
self.init()
... or don't assign the results to local variables?
Sketchup::Licensing.get_extension_license(
'6cce9800-40b0-4dd9-9671-8d55a05ae1e8'
)
?
Yes, looking at this again after a long time, ... the latter would be much better.
There is no point in assigning the results to local variables within the submodule as they are never used. All we care about is that the Extension Manager gets a chance to check the licensing during the load cycle.
Also in the "ex_hello_license/main.rb" file, It is not necessary to assign local variables.
Instance variables can also be seen. The example has a blocking message box that would allow the variables to exist whilst the modal window is open. Perhaps:
unless Sketchup::Licensing.get_extension_license(
'6cce9800-40b0-4dd9-9671-8d55a05ae1e8'
).licensed?
UI::messagebox('Could not obtain a valid license.')
return
end
... or ...
ext_id = '6cce9800-40b0-4dd9-9671-8d55a05ae1e8'
license = Sketchup::Licensing.get_extension_license(ext_id)
bailout = license.licensed?
ex_id = license = nil
GC.start
if bailout
UI::messagebox('Could not obtain a valid license.')
return
end