script for spline

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
Surendranath
Junior Member
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

script for spline

Post by 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

User avatar
andrew
Site Admin
Posts: 9036
Joined: Fri Mar 30, 2007 6:07 am

Re: script for spline

Post by 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

Surendranath
Junior Member
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

Re: script for spline

Post by 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

Post by 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

User avatar
andrew
Site Admin
Posts: 9036
Joined: Fri Mar 30, 2007 6:07 am

Re: script for spline

Post by 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: 9036
Joined: Fri Mar 30, 2007 6:07 am

Re: script for spline

Post by andrew » Mon Jan 14, 2013 11:00 am

I've split the next post to a new topic:
viewtopic.php?f=30&t=2298

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”