• Login
sketchucation logo sketchucation
  • Login
๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Best way to return a value from a tool ?

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 4 Posters 120 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    Didier Bur
    last edited by 2 Apr 2012, 08:07

    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,

    DB

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 2 Apr 2012, 10:52

      Make it a class, that's a Tool.
      As well as activate have deactivate(), 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

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 2 Apr 2012, 13:37

        @tig said:

        Remember to [pre]format @length in appropriate units etc as needed

        Ensuring @length is a Length class will ensure SketchUp formats the length in the model's current unit. There is rarely any need to perform any unit formatting.

        Thomas Thomassen โ€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • D Offline
          Didier Bur
          last edited by 2 Apr 2012, 14:08

          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 !

          DB

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 2 Apr 2012, 15:03

            Inside the Tool class use:

            attr_reader( :distance )

            so you have a getter method

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • D Offline
              Didier Bur
              last edited by 4 Apr 2012, 17:05

              Thanks Dan,
              I still had an attr_accessor :distance in that class ๐Ÿ˜‰

              DB

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                1/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement