script for spline

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

script for spline

Postby Surendranath » Sat Jan 12, 2013 2:51 am

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
Surendranath
Junior Member
 
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

Re: script for spline

Postby andrew » Sat Jan 12, 2013 11:04 am

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
User avatar
andrew
Site Admin
 
Posts: 2368
Joined: Fri Mar 30, 2007 6:07 am

Re: script for spline

Postby Surendranath » Sat Jan 12, 2013 4:44 pm

Thanks!
It more or less set me on my way.
Surendranath
Junior Member
 
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

Re: script for spline

Postby Surendranath » Sun Jan 13, 2013 3:19 am

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
Surendranath
Junior Member
 
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

Re: script for spline

Postby andrew » Sun Jan 13, 2013 12:11 pm

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.
User avatar
andrew
Site Admin
 
Posts: 2368
Joined: Fri Mar 30, 2007 6:07 am

Re: script for spline

Postby andrew » Mon Jan 14, 2013 11:00 am

I've split the next post to a new topic:
viewtopic.php?f=30&t=2298
User avatar
andrew
Site Admin
 
Posts: 2368
Joined: Fri Mar 30, 2007 6:07 am


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 2 guests