sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Best way to return a value from a tool ?

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 4 Posters 120 Views 4 Watching
    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.
    • Didier BurD Offline
      Didier Bur
      last edited by

      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
      • TIGT Offline
        TIG Moderator
        last edited by

        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
        • thomthomT Offline
          thomthom
          last edited by

          @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
          • Didier BurD Offline
            Didier Bur
            last edited by

            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
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              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
              • Didier BurD Offline
                Didier Bur
                last edited by

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

                DB

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

                Advertisement