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

    ? [Question] - A Ruby Calculator ?

    Scheduled Pinned Locked Moved Developers' Forum
    40 Posts 12 Posters 33.7k Views 12 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.
    • G Offline
      Gruff
      last edited by

      Chris:
      This one was coded in VB6. I find it best for quick development.
      If you want to look at the Source code I could post it for you.

      Rather than write my own equation parser I made use of the MS Scripting Control to evaluate text expressions. While this supports a wide range of functionality it also opens the door to user input errors. It is extensible. In fact for this implementation I swapped out the Trig functions so that they work with Decimal Degrees instead of Radians. i.e. SIN(30) = 0.50

      This means conversion functions as the original poster asked about could be added fairly easily.
      I suppose I could write it such that it imports a text file that contains user defined conversion procedures. (Of course they would have to be written in VBScript.)

      This brings up a possiblity that this might be written as a Web form.
      As I see it the only missing elements for you would be the VB Sendkeys() command and some way of setting the focus to SU while Sendkeys does the job. Hey! I believe there is a Win32API equivalent.
      I'll root around for it.

      xrok1:
      The App was compiled under WinXP. I suspect you are using some other OS.
      This might also account for how it looks on your system.

      Run-Time Error 5 (Invalid Procedure Call or Argument) can be attributed to an out of range floating point error or more likely an incompatible OS.

      Just downloaded the zip from the forum and installed it on my other WinXP box.
      Runs fine here.

      As far as how it looks. Could you post a screen shot? I was concerned about size so I made it as compact as possible.

      Resistance is .... Character Forming. Grin

      1 Reply Last reply Reply Quote 0
      • G Offline
        Gruff
        last edited by

        Hmmm there is a User32.dll sendkeys function but why not use ruby entirely.

        I tried this code but it fails on the: require 'win32ole'
        I downloaded and installed full ruby but it doesn't seem to make a difference.

        Perhaps you can get this to work?

        
        require 'Sketchup'
        require 'win32ole'
        #---
        
        def drive_vcb  
          wsh = WIN32OLE.new('Wscript.Shell')
        
          # Do not know if we need to put the focus on SU since we are in SU.
          if wsh.AppActivate('- SketchUp')
            sleep(1)
        
            # Push Test keystrokes into SU
            wsh.SendKeys('100.00{ENTER}')
        
          end
        end
        if( not file_loaded?("test_me.rb") )
            add_separator_to_menu("Draw")    
            UI.menu("Draw").add_item($exStrings.GetString("test_me")) { drive_vcb }
        end
        #---
        
        file_loaded("test_me.rb")
        
        

        Resistance is .... Character Forming. Grin

        1 Reply Last reply Reply Quote 0
        • A Offline
          a4chitect
          last edited by

          perhaps this thread might help
          http://forums.sketchucation.com/viewtopic.php?f=180&t=21281

          put the attached file into plugins folder, no more load errors


          win32ole.zip


          this script sends "20" into sketchup - when vcb is active - this gets put in

          1 Reply Last reply Reply Quote 0
          • G Offline
            Gruff
            last edited by

            A4chitect:
            Thanks! It works on my PC now as well.

            Chris:
            There you go. You can write a calculator with a Web page front end that uses code like that in 'test_me.rb' to drive the VCB. That would be a better solution as it would be native to SketchUp for Windows. Much much better than my Compiled app.

            Resistance is .... Character Forming. Grin

            1 Reply Last reply Reply Quote 0
            • K Offline
              ktkoh
              last edited by

              This looks like a great tool for me as I need a calculator quite often. The way it seems to work best for me is.

              1. Put the formula in the calculator and press enter once.
              2. Back in SU select the tool ie Move and the handle point then click on the TG Cal and return the mouse to show the move direction and then press Enter.

              Thanks
              Keith

              1 Reply Last reply Reply Quote 0
              • X Offline
                xrok1
                last edited by

                running windows7 here.


                Capture.JPG

                “There are three classes of people: those who see. Those who see when they are shown. Those who do not see.”

                http://www.Twilightrender.com try it!

                1 Reply Last reply Reply Quote 0
                • G Offline
                  Gruff
                  last edited by

                  Ah! that would be the problem then. Definite version issue.
                  Since I do not have Windows7 I cannot say that it will ever work for you.

                  Are there modifications you can do to get it to run as though it were launched from WinXP? XP has tools to run older OS products through it's shortcut options.

                  Looks nice though. 😄

                  Resistance is .... Character Forming. Grin

                  1 Reply Last reply Reply Quote 0
                  • X Offline
                    xrok1
                    last edited by

                    tried it in XP compatibility mode. still crashed,

                    “There are three classes of people: those who see. Those who see when they are shown. Those who do not see.”

                    http://www.Twilightrender.com try it!

                    1 Reply Last reply Reply Quote 0
                    • X Offline
                      xrok1
                      last edited by

                      arrrrg!


                      Capture.JPG

                      “There are three classes of people: those who see. Those who see when they are shown. Those who do not see.”

                      http://www.Twilightrender.com try it!

                      1 Reply Last reply Reply Quote 0
                      • G Offline
                        Gruff
                        last edited by

                        Tell you what xrok1,

                        Here is a small Ruby script Calculator that binds to the Tools menu.
                        Bind it to a shortcut key and your in business.

                        [Edit]
                        See the attached zip file two posts down...
                        [/Edit]

                        Resistance is .... Character Forming. Grin

                        1 Reply Last reply Reply Quote 0
                        • JClementsJ Offline
                          JClements
                          last edited by

                          Thanks, Gruff!

                          John | Illustrator | Beaverton, Oregon

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            Jim
                            last edited by

                            A minor thing - require 'Sketchup' causes sketchup.rb to load a second time. Loading sketchup.rb again doesn't really break anything, but it does create a duplicate Ruby Console entry in the Window menu.

                            It should be - require 'sketchup' (small s)

                            Hi

                            1 Reply Last reply Reply Quote 0
                            • G Offline
                              Gruff
                              last edited by

                              You are really having a bad day, Huh. Sorry for any confusion.

                              Attached is a zip file that contains both ruby_calc.rb and win32old.so.

                              Unzip and place them both in your plugins folder under sketchup.

                              I found it handy to bind the menu 'Tool/Ruby Calc' to a shortcut key. (I use Alt+Q)

                              This calculator doesn't have a history, but it will take any Ruby formatted Math equation and use it to drive the VCB.


                              Latest Ruby_Calc. (This is not TG_Calc)

                              Resistance is .... Character Forming. Grin

                              1 Reply Last reply Reply Quote 0
                              • G Offline
                                Gruff
                                last edited by

                                Thanks for the advice Jim.

                                I updated the Ruby_Calc Zip attachment with your change. For any who get this far there are two calculators in this thread.

                                1. TG_Calc.exe which is a Compiled Windows program. It has a number of features.
                                2. Ruby_Calc.rb which is just a simple calc with no features.

                                Both only work with Windows and require the win32ole.so file.
                                both work by pumping keystrokes into the SU environment.

                                Resistance is .... Character Forming. Grin

                                1 Reply Last reply Reply Quote 0
                                • JClementsJ Offline
                                  JClements
                                  last edited by

                                  I thought this worked. I tried the zip file contents in both SU2013 and SU2014.
                                  I also tried installing via the SketchUcation Plugin Store.

                                  ruby_calc load error.JPG

                                  John | Illustrator | Beaverton, Oregon

                                  1 Reply Last reply Reply Quote 0
                                  • TIGT Offline
                                    TIG Moderator
                                    last edited by

                                    The script hasn't got require 'langhandler'
                                    Add that after the require 'sketchup'
                                    If an earlier loading script has already required it it might mask the lack of it.
                                    However the line:
                                    UI.menu("Tools").add_item($exStrings.GetString("Ruby Calc")) { rubycalc }
                                    will also fail if $exStrings is undefined as it loads - as that might get setup by another script too.
                                    Frankly I'd forget about the langhandler completely, and change it to read:
                                    UI.menu("Tools").add_item("Ruby Calc"){rubycalc}

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • JClementsJ Offline
                                      JClements
                                      last edited by

                                      Thanks TIG. Works now per your post.

                                      If I wanted to add info to the taskbar below such as:

                                      = Subtract, [
                                      ] = Multiply, [/] = Divide, [%] return remainder, [**] = exponent, [ ( ) ] = group functions"*
                                      what would be the proper ruby format and where should it be inserted?

                                      *# Ruby Calc

                                      by Gruff

                                      Oct 29th 2009

                                      Many thanks to a4chitect for the win32ole section

                                      Ruby Calc is a simple SketchUp for Windows calculator.

                                      Feel free to hack and wack it.

                                      Since it is run as a loose procedure rather than a class

                                      it does not kick SU out of the currently running tool

                                      Bind the Menu Item 'Ruby Calc' to a short cut key

                                      For ease of use. (I use Alt-Q)

                                      require 'sketchup'
                                      [highlight=#ff0000:rs61bj0c]require 'langhandler'[/highlight:rs61bj0c]
                                      require 'win32ole'

                                      #---

                                      def rubycalc
                                      prompt = [""]
                                      default = [" "]
                                      input = UI.inputbox prompt, default, "Ruby Calc"
                                      fanswer = eval input[0]
                                      sanswer = fanswer.to_s + "{ENTER}{ENTER}"

                                      Create an instance of the Wscript Shell

                                      wsh = WIN32OLE.new('Wscript.Shell')

                                      #Try to activate the Sketchup window:
                                      if wsh.AppActivate(' - SketchUp Pro') || wsh.AppActivate(' - SketchUp')
                                      wsh.SendKeys(sanswer)
                                      else
                                      puts "Impossible"
                                      end
                                      end

                                      #---
                                      if( not file_loaded?("ruby_calc.rb") )
                                      add_separator_to_menu("Tools")
                                      [highlight=#ff0000:rs61bj0c]UI.menu("Tools").add_item("Ruby Calc")[/highlight:rs61bj0c] { rubycalc }
                                      end

                                      file_loaded("ruby_calc.rb")*

                                      John | Illustrator | Beaverton, Oregon

                                      1 Reply Last reply Reply Quote 0
                                      • Dan RathbunD Offline
                                        Dan Rathbun
                                        last edited by

                                        ❗

                                        v 2.0.0 cleanup by Dan Rathbun : 16 Aug 2014

                                        1. Module wrapped in Gruff::RubyCalc

                                        2. Method renamed: Gruff::RubyCalc::command()

                                        • statusbar help text displayed during input
                                        • evaluation rescue wrapped with retry
                                        • exits for empty input and cancellation
                                        1. Tweekable text placed in module constants

                                        ruby_calc_2.rb

                                        I'm not here much anymore.

                                        1 Reply Last reply Reply Quote 0
                                        • Dan RathbunD Offline
                                          Dan Rathbun
                                          last edited by

                                          Gruff has not logged in to SCF for a year and 4 months. Is he OK ?

                                          I'm not here much anymore.

                                          1 Reply Last reply Reply Quote 0
                                          • JClementsJ Offline
                                            JClements
                                            last edited by

                                            Thank you for your help, Dan and TIG.

                                            John | Illustrator | Beaverton, Oregon

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

                                            Advertisement