Page 1 of 1

script for spline

Posted: Sat Jan 12, 2013 2:51 am
by Surendranath
Can I have some code for spline please?

Where do I find the list of commands that can be used in the script file.

I am a beginner and am using qcad 3.0

Thanks

Re: script for spline

Posted: Sat Jan 12, 2013 11:04 am
by andrew
You can actually find code for pretty much anything that is possible in the scripts that come with QCAD 3 in the scripts directory.

For example search all .js files for RSpline, RSplineEntity, RSplineData.

The complete API is documented at:
http://www.qcad.org/doc/qcad/latest/developer/

Spline entity class:
http://www.qcad.org/doc/qcad/latest/dev ... ntity.html

Re: script for spline

Posted: Sat Jan 12, 2013 4:44 pm
by Surendranath
Thanks!
It more or less set me on my way.

Re: script for spline

Posted: Sun Jan 13, 2013 3:19 am
by Surendranath
One more question though.

How can the values be accepted from command line?
I want to prompt the user for input which could be strings, numbers and based on the values determine the action in a program

Re: script for spline

Posted: Sun Jan 13, 2013 12:11 pm
by andrew
If the user enters a coordinate in the command line, your class triggers 'pickCoordinate(event, preview)'.
Where 'event.getModelPosition()' is an RVector with the coordinate entered and 'preview' is 'true' if the user is still busy entering the coordinate and 'false' if the user has pressed enter to confirm the input.

'pickCoordinate' is also called when the user clicks a coordinate with the mouse, so you might already have that implemented anyway.

If the user enters anything that is not a coordinate (i.e. a double value or simply text), 'applyCommand(event, preview)' is called. 'event.getCommand()' holds the exact string that was entered by the user. You can separate between values and commands by trying to interpret the input:

Code: Select all

var value = RMath.eval(event.getCommand());
if (isNaN(value)) {
    qDebug("Entered command is: ", event.getCommand());
}
else {
    qDebug("Entered value is: ", value);
}
For a complete and simple example, have a look at the script 'scripts/Draw/Circle/CircleCR/CircleCR.js' which allows the user to enter the circle radius in the command line, followed by the circle center coordinate.

Re: script for spline

Posted: Mon Jan 14, 2013 11:00 am
by andrew
I've split the next post to a new topic:
viewtopic.php?f=30&t=2298