RApplication Problem

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
LemanKendrick
Registered Member
Posts: 2
Joined: Sun Aug 24, 2025 3:54 pm

RApplication Problem

Post by LemanKendrick » Sun Aug 24, 2025 4:09 pm

Hello All,

I am new to QCAD and really like it so far. I am recently retired and did some personal programming in AutoCAD years ago and thought I would like to learn scripting in QCAD. I am having trouble getting scripts created with Gemini AI to run. If I enter "print(RApplication.getScriptPaths()); " in the script shell, I get the message "ReferenceError: Can't find variable: RApplication". I did a fresh reinstall of QCAD version 3.32.3.0 (3.32.3) on Windows 11. Since I'm a novice, any insight on how to resolve the issue will be greatly appreciated!!

CVH
Premier Member
Posts: 5082
Joined: Wed Sep 27, 2017 4:17 pm

Re: RApplication Problem

Post by CVH » Sun Aug 24, 2025 8:18 pm

Hi, and welcome to the QCAD forum.

An AI that can understands a bit of Java, JavaScript or ECMAScript is not really trained to write QCAD code.
With a bit of luck it constructs something usable under HTML as there are millions and millions examples to learn (steal) from.
Remind that AI also adopts things from partially wrong or fully bogus code.

RApplication in a signature like RApplication.getScriptPaths() is typically a variable that holds a reference to an object of the type RApplication.
Of which getScriptPaths() is a function what is called without arguments.

A search in the vast QCAD API doesn't reqognise "RApplication" nor "getScriptPath" (singular or plural).
See QCAD Application Framework reference


There are 2 basic places where custom tool scripts reside.
Under the script folder of your QCAD installation or under the scripts folder of the user data location.

Stand alone scripts activated by 'Run Script' (XC) can be stored anywhere.
The ideal place for Command Line tools scripts is the application folder itself.

Installed with an msi it might that you need Admin rights to access application folders under the Program Files folder.
It is advicable to use a plain text editor that understands a bit of and can format JavaScript, for example Notepad++.

Most QCAD drawing tools are implemented in ECMAScript.
One can find an overview of the open source on Github.
This does not include all the QCAD Pro resources, these are proprietary.

Chances are that you don't find a copy of a script or sub-folder under the script folder of your installation.
Most QCAD scripts are only available as compiled in a standard installation.

Some common rules must be obeyed.
Not everything is documented in full detail, some trial and error is involved.
The QCAD site includes some examples and directives.
See QCAD Tutorials under the section 'Developers'.
Digging deeper through all the information leads to some more example snippets.


Perhaps you can share what you want to accomplish.
Then we can help you more efficiently ... More to the point.

Regards,
CVH

LemanKendrick
Registered Member
Posts: 2
Joined: Sun Aug 24, 2025 3:54 pm

Re: RApplication Problem

Post by LemanKendrick » Tue Aug 26, 2025 12:41 am

This is what I entered into the AI:
I need a script for qcad to plot deed descriptions that works as follows: the user is prompted to enter a beginning point by either selecting a point onscreen. then the user is prompted to enter a quadrant as follows: 1 is for northeast (0 - 90 degrees), 2 is for southeast (270 - 0 degrees), 3 is for southwest (270 - 180 degrees), and 4 is for northwest (90 - 180 degrees). After the quadrant is entered, the user enters the bearing between 0 and 90 degrees. the bearing is entered as a string and parsed for degrees, minutes, and seconds. for example 34.2312 would be 34 degrees 23 minutes 12 seconds,: 34.23 would be 34 degrees 23 minutes: 34 would be 34 degrees. After the bearing is entered, the user is prompted for a distance. the distance is also a string. if the distance string contains a + then the string is parsed with the left of the + being poles and right of the + being links. A conversion is made to feet by multiplying the poles by 16.5 for feet and links by 7.92 / 12. If no + is in the string then the string represents feet. Next the script draws the line defined by the quadrant, bearing, and distance. the script repeats from the endpoint of the line just drawn until cancelled by user.

The attached file is what AI suggested. I am trying to re-create in QCAD a lisp program that I did almost 30 years ago and used frequently until my recent retirement. At this point, I realize that I have a lot of learning to do and any guidance will be greatly appreciated!!
Attachments
DeedPlotter.js
(6.97 KiB) Downloaded 283 times

CVH
Premier Member
Posts: 5082
Joined: Wed Sep 27, 2017 4:17 pm

Re: RApplication Problem

Post by CVH » Tue Aug 26, 2025 10:34 am

Hi,

Basically an interactive script addon similar to the LI drawing tool with some twists. (Tutorial: Interactive Script Actions)
The main differences are:
- Only segment mode, never a ray or an endless line
- The direction format
- The distance format

Other differences are that you did not specify a closing sequence or an undo/redo for the last point.

It has two event driven states like LI:
- First point (By indicating a position or by Coordinate input)
- Next point repeated until canceled (By specific formatted text)
The attached script is not event driven, each step calls the next step or terminates.

You must now decide on a method to enter your values.
A) Typically QCAD extensively uses the Option Toolbar for displaying tool options. (See LI with 'Restrict Angle or Length' active)
B) By dialog and then Quadrant - Bearing - Distance can be 3 input fields in the same dialog.
C) By typing in the custom formatted values in the Command Line when prompted.

I would avoid C as the Command Line is not really an analogue for that of other CAD applications.
It is not intended to enter commands with arguments but rather geared to enter coordinates or a list of.
But it should be feasible.
In that case I would simplify things with a complex textual input:
For example: 1 34.2312 2+6 followed by Enter
Chopped up at spaces for: NE - 34 degrees 23 minutes 12 seconds - 36.96'

For A and B you need to create a specific UI with for example Qt Designer.
In case B the dialog would constantly obstruct what is drawn in the drawing area until canceled.
Don't see the 3 input dialogs, 2 warning dialogs and that for continuing as minimalistic textfields near a last point.
Warnings are typically issued on the Command History.

Then A seems the logical choice for QCAD minded users.
But options are persistent and you need to overwrite them (all) for a next point.
An additional button to draw the next line and one to cancel the tool are also required.
There are no coordinates picked with the mouse for any of the next points.

The shortcut key sequence would conflict with 'Duplicate' (DP).
To be honest, there are almost no good sequences left with 2 keys ...
... And for 3 the first 2 may not be in use ... :(
There is also no action button included anywhere and QCAD would not know how to sort these in a list of.

action.triggered.connect or addGuiActionTo are typically not seen in the init section.
Adding an addon tool is standardized because about all tools are implemented like this.
If QCAD comes across a script in the scripts folder it attempts to initiate it by calling the init function.
Most things are then handled by default.
For that DeedPlotter.js must be located in a sub-folder DeedPlotter.
Initialization may also be done by a separate script in the same folder: DeedPlotterInit.js

Another issue I see is that DeedPlotter.js is based on the Line.js script.
Line.js is the common core for all QCAD Line tools.
Among others it implements shared functions that you don't exploit at all.

The last question I have at the moment concerns your drawing unit.
Remind that values in CAD are typically unit-less, '1.23' may mean 1.23 inch, 1.23 mm or even 1.23km
The feet symbol in 1'2" simply stands for 'times 12' and would result in 14 drawing units ... Whatever that unit is.
And the inch symbol in 1'2" is simply ignored.
parseDistance returns feet or poles/links converted to feet.
That would only be correct in a drawing using the foot as drawing unit. :wink:
It is further not verified and/or not converted to current drawing units.

Please let me know what route to take.
Writing a simple QCAD addon script is not that hard.
Several parts of your code can already be used when fixed at some points.

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”