? [Question] - A Ruby Calculator ?

? [Question] - A Ruby Calculator ?

Postby JClements » Mon Oct 12, 2009 7:49 pm

Has there ever been a Ruby Calculator developed that could do basic math functions, remember a constant, and do Unit conversions and then take the results drop them into the VCB and/or to the windows clipboard?

I was thinking it could be useful to use with Certain tools or scripts that don't recognized all units of measure.
1
John
Illustrator
Beaverton, Oregon
User avatar
JClements 
Premium Member
Premium Member
 

Re: ? [Question] - A Ruby Calculator ?

Postby NewOne » Mon Oct 12, 2009 9:03 pm

JClements wrote:Has there ever been a Ruby Calculator developed that could do basic math functions, remember a constant, and do Unit conversions and then take the results drop them into the VCB and/or to the windows clipboard?

I was thinking it could be useful to use with Certain tools or scripts that don't recognized all units of measure.

You can simply use Ruby Console for that. :D
0

NewOne 
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Mon Oct 12, 2009 11:06 pm

NewOne wrote:You can simply use Ruby Console for that. :D


Pretty terse New. :)
How do you get the console to push the result into the VCB?
0
Resistance is .... Character Forming. *Grin*

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby NewOne » Tue Oct 13, 2009 12:41 am

Gruff wrote:Pretty terse New. :)
How do you get the console to push the result into the VCB?

Code: Select all
#INPUT THIS IN Ruby Console

Sketchup.vcb_value = 5*3

#THIS WILL RETURN 15 IN VCB
0

NewOne 
 

Re: ? [Question] - A Ruby Calculator ?

Postby xrok1 » Tue Oct 13, 2009 1:56 am

wow, i can't believe its that easy and still no one has written a VCB replacement that can accept equations? i can't tell you how many times i could have used this!
0
“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!

xrok1 
 

Re: ? [Question] - A Ruby Calculator ?

Postby pilou » Tue Oct 13, 2009 1:58 am

Simple things are always a litle hidden ;)
0
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
pilou 
Top SketchUcator
 

Re: ? [Question] - A Ruby Calculator ?

Postby Jim » Tue Oct 13, 2009 1:59 am

(it's not that easy.)
0
Hi

Jim 
Global Moderator
 

Re: ? [Question] - A Ruby Calculator ?

Postby NewOne » Tue Oct 13, 2009 11:38 am

Jim wrote:(it's not that easy.)

you are right. It's easy to make a webdialog to input calculations, but in ruby you must use regexp to dispatch resulting string and make calculations (this can be tricky and I'm not sure that covers all situations). Other option (more simple for who knows js) would be to make calculations with js and send just the result to ruby.
0

NewOne 
 

Re: ? [Question] - A Ruby Calculator ?

Postby NewOne » Tue Oct 13, 2009 4:46 pm

I made a try... a unsuccessful try to make a calculator that sends value in VCB.
When pressing '=', the value is sent in VCB, but there can not be used :( It's just there, doing nothing.

Now, it sends the value in mm.
0

NewOne 
 

Re: ? [Question] - A Ruby Calculator ?

Postby TIG » Tue Oct 13, 2009 4:49 pm

You would need to set the output to a global variable like $calculator_output. Then put that into the VCB AND have any tool also accept $calculator_output as it's input IF $calculator_output has changed since it launched ??? :?:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: ? [Question] - A Ruby Calculator ?

Postby NewOne » Tue Oct 13, 2009 4:56 pm

TIG wrote:You would need to set the output to a global variable like $calculator_output. Then put that into the VCB AND have any tool also accept $calculator_output as it's input IF $calculator_output has changed since it launched ??? :?:

hmm... i see... But, for native tools, where does SketchUp stores VCB input? Doesn't have a global variable of its own?
0

NewOne 
 

Re: ? [Question] - A Ruby Calculator ?

Postby TIG » Tue Oct 13, 2009 7:52 pm

NewOne wrote:
TIG wrote:You would need to set the output to a global variable like $calculator_output. Then put that into the VCB AND have any tool also accept $calculator_output as it's input IF $calculator_output has changed since it launched ??? :?:

hmm... i see... But, for native tools, where does SketchUp stores VCB input? Doesn't have a global variable of its own?

If it does then it's avery well kept secret ! :cry:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: ? [Question] - A Ruby Calculator ?

Postby Jim » Sat Oct 17, 2009 5:43 pm

NewOne wrote:hmm... i see... But, for native tools, where does SketchUp stores VCB input? Doesn't have a global variable of its own?


It is not likely the built in tools are using global variables. If they were, they would be visible using the " global_variables " method.

The issue is that the tool has control over the measurements box. You know from using sketchup that a tool can be suspended and resumed. Take the orbit tool as an example. It suspends the current tool and then returns control on exit.

It is possible to write a tool to the accept and evaluate expressions, and place the value in the measurements box. But the tool which was suspended and then resumed would need to be programmed to look for the change in value.

I don't think it is possible to modify the built in tools in order to look for the change. A replacement set of tools would need to be written.
0
Hi

Jim 
Global Moderator
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Wed Oct 28, 2009 3:14 pm

It would be possible to create an external Windows Calculator program that pumped a value directly into the VCB as though it was typed from the keyboard. I would hesitate to do such a thing though because such programs work with zero feedback. They can also be broken by a new release of SU.

Much better to do it internally if at all possible.

If however there is an interest in such a program I might be persuaded to knock one out.
0
Resistance is .... Character Forming. *Grin*

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Thu Oct 29, 2009 12:27 am

Turns out I don't need much persuading. :lol:

Attached is an Windows equation editor I slapped together.
It pumps the value into Sketchup via keyboard strokes.
Unzip and run the 'Setup.exe'. Create a shortcut to your Desktop.

It is setup to be a 'Top Most' window so it should float over SU.
It can handle a number of math functions and has a history dropdown. Values from history will be pasted into the equation when selected.

To use make sure your Measurement tool bar is ready to accept a value.
Press <ENTER> Once to resolve the equation. Press <ENTER> again to send the value to SU.

If you have problems running the calculator check the following.

1) Make sure the tools|options|Target Application is set for '- SketchUp'

2) Set the number of decimal places to 3. (Not sure why that affects things.) (Also under the tools menu.)

Let me know how it goes.
0
Resistance is .... Character Forming. *Grin*

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby Chris Fullmer » Thu Oct 29, 2009 5:13 am

Excellent Gruff :)

What language is it that you code in?

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: ? [Question] - A Ruby Calculator ?

Postby xrok1 » Thu Oct 29, 2009 5:26 am

thats just awsome, thankyou! now you could pretty it up a bit :lol:
0
“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!

xrok1 
 

Re: ? [Question] - A Ruby Calculator ?

Postby xrok1 » Thu Oct 29, 2009 5:30 am

oops! draw a line type 22*2 (or any equation) enter enter runtime error 5 invalid....
0
“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!

xrok1 
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Thu Oct 29, 2009 11:31 am

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

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Thu Oct 29, 2009 1:28 pm

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?

Code: Select all
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")
0
Resistance is .... Character Forming. *Grin*

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby a4chitect » Thu Oct 29, 2009 4:52 pm

perhaps this thread might help
viewtopic.php?f=180&t=21281

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

a4chitect 
PluginStore Author
PluginStore Author
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Thu Oct 29, 2009 11:10 pm

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

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby ktkoh » Fri Oct 30, 2009 12:15 am

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
0

ktkoh 
PluginStore Author
PluginStore Author
 

Re: ? [Question] - A Ruby Calculator ?

Postby xrok1 » Fri Oct 30, 2009 12:50 am

running windows7 here.
0
“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!

xrok1 
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Fri Oct 30, 2009 1:59 am

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

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby xrok1 » Fri Oct 30, 2009 2:01 am

tried it in XP compatibility mode. still crashed,
0
“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!

xrok1 
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Fri Oct 30, 2009 2:23 am

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]
0
Last edited by Gruff on Fri Oct 30, 2009 6:13 pm, edited 1 time in total.
Resistance is .... Character Forming. *Grin*

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby xrok1 » Fri Oct 30, 2009 3:21 am

arrrrg!
0
“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!

xrok1 
 

Re: ? [Question] - A Ruby Calculator ?

Postby Gruff » Fri Oct 30, 2009 4:36 am

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.
1
Last edited by Gruff on Sun Nov 08, 2009 2:48 pm, edited 1 time in total.
Resistance is .... Character Forming. *Grin*

Gruff 
 

Re: ? [Question] - A Ruby Calculator ?

Postby JClements » Fri Nov 06, 2009 5:13 pm

Thanks, Gruff!
1
John
Illustrator
Beaverton, Oregon
User avatar
JClements 
Premium Member
Premium Member
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Developers' Forum

Who is online

Users browsing this forum: Pomelo_930 and 11 guests

Visit our sponsors: