CamBam
News:
 
*
Welcome, Guest. Please login or register. August 01, 2014, 23:01:25 pm


Login with username, password and session length


Pages: [1] 2
  Print  
Author Topic: script advise on getting a number entered from operator.  (Read 3558 times)
Desertrunner
Wookie
****
Offline Offline

Posts: 429


View Profile
« on: March 18, 2012, 03:52:18 am »

I want to get advise on what the code is for a JScript to ask a question then get a number back that can be used in a formula.  I have had a couple of goes and can't seem to get it right.
Tony
Logged
10bulls
Administrator
CNC Jedi
*****
Offline Offline

Posts: 1964


Coding Jedi


View Profile WWW
« Reply #1 on: March 19, 2012, 11:40:03 am »

In JScript you can do this...

Code:
var d : double;
var x = ThisApplication.PromptForValue("Enter a value", "Long description goes here", d.GetType());
if (x==null)
ThisApplication.MsgBox("Cancel Pressed");
else
ThisApplication.MsgBox(x.ToString());

and in VBScript

Code:
sub main
dim d as double
dim x = ThisApplication.PromptForValue("Enter a value", "Long description goes here", d.GetType())
if x is nothing then
ThisApplication.MsgBox("Cancel Pressed")
else
ThisApplication.MsgBox(x.ToString())
end if
end sub

PromptForValue will remember the value entered for each prompt (the first parameter), and will use this as the default value the next time the function is called.

You can also pass an optional 4th string parameter which is the default value.

The third parameter is the type of value you want to prompt for.
To change this type, change the type after the 'd' variable.
For example:
var d : string;
or
var d : int;
Logged
Desertrunner
Wookie
****
Offline Offline

Posts: 429


View Profile
« Reply #2 on: March 19, 2012, 18:02:40 pm »

Thanks Andy have a great day.
Tony
Logged
Desertrunner
Wookie
****
Offline Offline

Posts: 429


View Profile
« Reply #3 on: March 19, 2012, 18:59:28 pm »

What I am playing with Andy is your script called "Tapered" I have done a real rough and I do mean rough change so it makes a spiral of a give inside dia and a given outside dia witht he out side being adjust for the tool size.  Its my rough attempt to make it a bit easier to do spiral cuts.
Tony
Logged
Desertrunner
Wookie
****
Offline Offline

Posts: 429


View Profile
« Reply #4 on: March 20, 2012, 09:21:11 am »

I must be missing somthing as I can't get the script to run as per Andy suggestion.  I want to use the Java version but can't get it sort,
Change the extension to JS and load it into the scripts in Cambam.  All advise about were I have stuffed up will be appricated.
Tony

* JScript test.txt (0.22 KB - downloaded 89 times.)
Logged
10bulls
Administrator
CNC Jedi
*****
Offline Offline

Posts: 1964


Coding Jedi


View Profile WWW
« Reply #5 on: March 20, 2012, 09:50:29 am »

Hi Tony,

Try changing this...

var x = ThisApplication.PromptForValve(60, "enter a value for  inside dia",d.Int());

To this...

var x = ThisApplication.PromptForValue("Inside Diameter","enter a value for inside dia",d.GetType(),"60");

There was a small typo 'Valve' rather than 'Value'.
Parameter 1 needs to be the prompt...this is the text immediately to the left of the text entry box.
Parameter 2 is informational text which is display underneath the text entry.
Parameter 3 is the type of information to return.  In this example you need to use d.GetType()
Parameter 4 is the default value and can usually be left off as PromptForValue will remember the last entered value.

Logged
Desertrunner
Wookie
****
Offline Offline

Posts: 429


View Profile
« Reply #6 on: March 20, 2012, 18:32:16 pm »

Thanks Andy its all good.

Question why is it that we can't copy & paste with in the Script, is there a way to do it?
Tony
Logged
Desertrunner
Wookie
****
Offline Offline

Posts: 429


View Profile
« Reply #7 on: March 20, 2012, 20:22:59 pm »

Here is your friendly pain in the ass back for the next question.

What is the JScript to draw a arc.  I see from existing code that I can draw a spiral by,
pAdd(x,y,z Math.tan(th2go/4.0),1e-5)

so what changes for a arc?
Please.
Tony
Logged
dh42
CNC Jedi
*****
Offline Offline

Posts: 1625



View Profile WWW
« Reply #8 on: March 20, 2012, 21:00:52 pm »

Thanks Andy its all good.

Question why is it that we can't copy & paste with in the Script, is there a way to do it?
Tony

Hello Tony,

There are no menu, but you can use Ctrl C and Ctrl V to copy/paste in the script editor Wink

++
David
Logged
Desertrunner
Wookie
****
Offline Offline

Posts: 429


View Profile
« Reply #9 on: March 21, 2012, 20:56:39 pm »

I have figured the arc out its all good.
Tony
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 3766



View Profile
« Reply #10 on: March 21, 2012, 21:28:42 pm »

Hey!  Wait a minute, Tony!

GIVE!  Wink

Lloyd
Logged

Automation Machine Design, LLC.
--
"Doing the impossible in pyro automation every day."
Desertrunner
Wookie
****
Offline Offline

Posts: 429


View Profile
« Reply #11 on: March 22, 2012, 09:45:25 am »

Hi Lloyd,

Load this JScript into a CamBam JScript file and give it a run, please remember I am a dumb farmer  who can't spell so everything I say could be totally wrong but it works for me.

The "Add" part applies to a number of different possiable formulas will explain later.

var p : Polyline = new Polyline();

p.Add(0,-10,0,1,1e-5);    // p is the poly line Add the action, (x,y,z, ( 1 is radius of the arc equals distance between the spot x,y,z in the first equation and the x,y,z in the second),1e-5 explain down further)
p.Add(0,110,0,0,1e-5);   // the 4th parmeter is zero unless you want to continue drawing a new arc/line or what ever.
doc.Add(p);     //this code draws it in CamBam, everytime you want to end a ployline and draw a new one you need to do this.

The 4th parmeter does all the magic if you want to draw a striaght line between 2 point the first Add needs the fourth parnmeter to be "0".  Pretty well you can draw any shape using the "Add"

Next part is a BIG BIG GUESS so if I am wrong please for give me,
1e-5 is not as it seems, I think the 1e is the type of parmeter that Add is dealing with the "-" is just a spacer and 5 refers to a parmeter of 1e.  You can try 1b and JSript asks for more parmeter so there are other functioning codes controled by the last parmeter.  As I said this point about "1e-5" could be just my wild brain.

Given what I have learnt I think we should be able to do a script that will draw the trochoidal parths in the corners for us.

Hope this helps, I am working on a scrip that will draw a spiral and adjust its OD and ID for the tool width as well as any x, y, z, plus final clearance with one last lap of the spiral at a constant diameter.  Also at desired cut with per pass of the spiral.

Have a great day all.
Tony
Logged
dwc
Wookie
****
Offline Offline

Posts: 310



View Profile WWW
« Reply #12 on: March 22, 2012, 10:44:52 am »

I am working on a scrip that will draw a spiral and adjust its OD and ID for the tool width as well as any x, y, z, plus final clearance with one last lap of the spiral at a constant diameter.

Yes! yes! yes!
Exactly that is on my to-do list, but I don't know when I would have time.

FWIW I read 1e-5 as scientific notation for the number 0.00001, 1 with the decimal point moved 5 places to the left.

Have fun,
Don
Logged

Dragonfly
CNC Jedi
*****
Offline Offline

Posts: 738



View Profile
« Reply #13 on: March 22, 2012, 10:54:26 am »

Like dwc, I think <1e-5> is the scientific notation of a number and perhaps it is the precision parameter.
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 3766



View Profile
« Reply #14 on: March 22, 2012, 15:18:46 pm »

THANKS, Tony!

One more bullet in the bandolier.

LLoyd
Logged

Automation Machine Design, LLC.
--
"Doing the impossible in pyro automation every day."
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.248 seconds with 18 queries.

Copyright © 2008 HexRay Ltd. | Sitemap