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 asactivatehavedeactivate(), 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 endThis is a basic solution... Remember to [pre]format
@lengthin 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
@lengthis aLengthclass 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement