Best way to return a value from a tool ?
-
Hi all,
After several searches here and there, I'm searching for the most simpler and clever way to code a tool that will return a value after it ends.
For instance: I've made a tool which measures the total distance as the user clicks points on his model.
When he selects another tool, I want my code to get the 'distance' property (instance variable) of that tool)Thanks for your help,
-
Make it a
class
, that's aTool
.
As well asactivate
havedeactivate()
, which runs when the user selects another tool etc.
If the total length is remembered as an@
you can use that in an exiting dialog...def deactivate(view) UI.messagebox("Total Length = #{@length}") if @length Sketchup;;set_status_text("") return nil end
This is a basic solution... Remember to [pre]format
@length
in appropriate units etc as needed...
For pressing ESC etc could invoke 'onCancel()' similarly, BUT you'd probably not want to have the output then. -
@tig said:
Remember to [pre]format @length in appropriate units etc as needed
Ensuring
@length
is aLength
class will ensure SketchUp formats the length in the model's current unit. There is rarely any need to perform any unit formatting. -
Thanks guys,
@unknownuser said:
Make it a class, that's a Tool.
That was still the case (I don't know how to create a tool without making it a class )I tested various solutions to retrieve the @distance property... except deactivate(), so thanks a lot TIG !
-
Inside the Tool class use:
attr_reader( :distance )
so you have a getter method
-
Thanks Dan,
I still had an attr_accessor :distance in that class
Advertisement