? [Question] - A Ruby Calculator ?

Re: ? [Question] - A Ruby Calculator ?

Postby Jim » Sat Nov 07, 2009 4:31 pm

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)
0
Hi

Jim 
Global Moderator
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Sun Nov 08, 2009 2:53 pm

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.
0
Resistance is .... Character Forming. *Grin*

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby JClements » Fri Aug 15, 2014 2:15 am

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
0
John | Illustrator | Beaverton, Oregon
User avatar
JClements 
Premium Member
Premium Member
 

Re: ? [Question] - A Ruby Calculator ?

Postby TIG » Fri Aug 15, 2014 11:17 am

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}
0
TIG
User avatar
TIG 
Global Moderator
 

Re: ? [Question] - A Ruby Calculator ?

Postby JClements » Fri Aug 15, 2014 6:23 pm

Thanks TIG. Works now per your post.

If I wanted to add info to the taskbar below such as:
"[+] = Add, [-] = 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'
require 'langhandler'
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")
UI.menu("Tools").add_item("Ruby Calc") { rubycalc }
end

file_loaded("ruby_calc.rb")
0
John | Illustrator | Beaverton, Oregon
User avatar
JClements 
Premium Member
Premium Member
 

Re: ? [Question] - A Ruby Calculator ?

Postby Dan Rathbun » Sat Aug 16, 2014 5:57 am

:!:

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
  3. Tweekable text placed in module constants
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: ? [Question] - A Ruby Calculator ?

    Postby Dan Rathbun » Sat Aug 16, 2014 6:12 am

    Gruff has not logged in to SCF for a year and 4 months. Is he OK ?
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: ? [Question] - A Ruby Calculator ?

      Postby JClements » Sun Aug 17, 2014 2:43 am

      Thank you for your help, Dan and TIG.
      0
      John | Illustrator | Beaverton, Oregon
      User avatar
      JClements 
      Premium Member
      Premium Member
       

      Re: ? [Question] - A Ruby Calculator ?

      Postby turbodizayn » Wed Nov 29, 2017 9:27 am

      Hi! Does it work in SU2016 ? I have a message, " Could not activate SketchUp application window."
      0

      turbodizayn 
       

      Re: ? [Question] - A Ruby Calculator ?

      Postby Dan Rathbun » Sat Dec 02, 2017 1:51 am

      turbodizayn wrote:Hi! Does it work in SU2016 ? I have a message, " Could not activate SketchUp application window."

      I just tested version 2 of "ruby_calc_2.rb" in SketchUp 2016, and this works.

      Version 2 is in this post:
      viewtopic.php?f=180&t=22660&view=unread#p535117



      What is "it" you refer to ?
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago



        Ad Machine 
        Robot
         

        Previous


         

        Return to Developers' Forum

        Who is online

        Users browsing this forum: Bing [Bot] and 7 guests

        Visit our sponsors: