Page 1 of 1

Custom scripts not working on QCAD pro 3.32.2.0 on Windows 11 pro

Posted: Tue May 13, 2025 10:15 am
by skarda.lt
I am writing to report an issue I have encountered while attempting to run custom ECMAScript scripts in QCAD Professional on Windows 11 Pro.

Despite following the recommended practices for organizing and loading scripts, I have experienced inconsistent behavior — including cases where QCAD fails to start entirely after placing tool-style scripts in the expected scripts/ directory structure.

🔍 Issue Description

When I include a custom tool script (e.g., CreatePointsAtEqualIntervals.js) along with an Init.js initializer file, QCAD crashes silently on startup (i.e., it does not open, and no error dialog appears).
If I rename or remove the Init.js file, QCAD starts normally again.
I’ve verified that the scripts are syntactically valid and follow the documentation’s recommendations regarding RGuiAction registration and use of basePath.
💻 Environment

QCAD Version: 3.32.2.0
OS: Windows 11 Pro (64-bit)
User Account Control (UAC): Enabled
Script Location: C:/Program Files/QCAD/scripts/MyTools/CreatePointsAtEqualIntervals/
⚠️ Possible Issues

Script engine may not report or log errors properly during startup.
File path referencing in include(...) seems to fail when using nested script folders.
QCAD does not fail gracefully when an invalid or misreferenced Init.js file is present.
✅ Request

Could you please advise if there are any known issues with script execution on Windows 11 Pro?
Is there a proper way to validate tool scripts before startup or to force QCAD to log script loading errors?
Would you consider improving error reporting for Init.js-related issues during startup?
I appreciate your support and the powerful scripting engine QCAD provides — it is a crucial part of our tool development workflow for generating CAD elements used in custom metal fabrication.

Please let me know if you need any of my script files or error logs for further investigation.

Re: Custom scripts not working on QCAD pro 3.32.2.0 on Windows 11 pro

Posted: Tue May 13, 2025 10:58 am
by andrew
You can start QCAD with the command line argument -enable-script-debugger to show the script debugger when a script exception appears. This should be used for debugging only as the script debugger itself can cause problems.

Code: Select all

qcad.exe -enable-script-debugger
You might also want to launch QCAD in a console to see its output to stderr which usually gives you a good idea of what is wrong. If no output is shown, your console does not support stderr output for GUI applications. You can still redirect the output to a file instead:

Code: Select all

qcad.exe 2> error.log

Re: Custom scripts not working on QCAD pro 3.32.2.0 on Windows 11 pro

Posted: Tue May 13, 2025 6:19 pm
by CVH
skarda.lt wrote:
Tue May 13, 2025 10:15 am
When I include a custom tool script (e.g., CreatePointsAtEqualIntervals.js) along with an Init.js initializer file, QCAD crashes silently on startup (i.e., it does not open, and no error dialog appears).
Then there is a major JS syntax fault preventing the script from loading.
Crashing on startup also means that the collection of scripts gets corrupted.
A missing closing bracket may already be an issue.
skarda.lt wrote:
Tue May 13, 2025 10:15 am
If I rename or remove the Init.js file, QCAD starts normally again.
This prevents the script to be considered as an Addon.
It is disregarded and QCAD starts without it.

If attached I would gladly have a look at it.
Per Private message is also fine.
Creating points at an interval can already be achieved in several ways.

Regards,
CVH

Re: Custom scripts not working on QCAD pro 3.32.2.0 on Windows 11 pro

Posted: Wed May 14, 2025 12:04 pm
by skarda.lt
Debugger helps allot, also Grok3 AI helps to modify script, and finally it works with both polylines and lines.
Thank you

Re: Custom scripts not working on QCAD pro 3.32.2.0 on Windows 11 pro

Posted: Thu May 15, 2025 5:56 am
by CVH
Thanks for the tool package per PM.
I was writing a reply for answering that ...

So eager to move on that you rely on an AI.
Q: Is this AI so well trained that it can write flawless QCAD specific JS code?

Sorry that I have deep-seated doubts about that.
But curious about what it proposed to fix your script(s).
Please resend the fixed tool package for additional advice by a human.

How did it fix: getInteger("Number of points to place:", 5) ?

Have a look at this recent reply on how an Addon is initialized.
I used part of my obsolete reply to you for answering that.
Your CreatePointsAtEqualIntervalsInit.js was/is not what is expected.

Also have a look at the last item about setting the GroupSortOrder, 20 is simply invalid.

MyTools I associate with this contribution by user smf .
Typically to create a custom menu and toolbar but yours does nothing meaningful.

Regards,
CVH

Re: Custom scripts not working on QCAD pro 3.32.2.0 on Windows 11 pro

Posted: Fri May 16, 2025 7:08 am
by skarda.lt
Hello, I've tried latest versions of Gemini, ChatGPT without success, Grok with less errors, but when i prompted with debugger logs, it helped well almost with some tries.

I tried to change native script example of ThreePoints, after some modifying it works with both poly and lines

Original and modified scripts attached

Re: Custom scripts not working on QCAD pro 3.32.2.0 on Windows 11 pro

Posted: Sat May 17, 2025 8:42 am
by CVH
Hi,

Pfff... Really a very artificial code, but I didn't expect otherwise.

First, replacing the ExThreePoints.js code is not permanent, this might be overwritten on an update.
But of course you can supersede it by adding a copy to the user data location where it will not be affected.
The better option is to rename it by replacing the term 'ExThreePoints' throughout, including folders and filenames.
Essentially adding a new Addon tool.

We don't set an initial state in the class constructor (Line 28).
> The main action in the beginEvent of an interactive script is setting the initial state.
We might set up some defaults and I count 3 objects:

Code: Select all

    this.selectedEntity = undefined;
    this.isLineEntity = undefined;    // Pretty obsolete flag
    this.numSegments = 16;    // Default number of segments
You define (kept) 3 states but there is just 1 single state: Selecting an entity.
Also reflected in escapeEvent(), this terminates directly instead of throttling back: 2 > 1 > 0 > Cancel or finished.

Entering a number of segments on the Command Line is not regarded as a tool state.
The Command Line line may also be used to pass on a certain coordinate instead of a mouse action.
Typically this would be a tool option displayed on the Option Toolbar but then you need to define an UI.
Changing this then sets this.numSegments and that can indeed also be set by a commandEvent.

getState() is totally obsolete and never called for.
The current tool state, if any, is stored in this.state.

In the beginEvent you check for a valid Document Interface.
A: The check should be isNull(di).
B: Pretty obsolete because in the init section it is required to have a document and thus an associated interface.
C: I tend to not use qDebug or related. On Windows that can not be shown on the fly.
Any user warning/info/message is listed in the Command History.
For that my Command Line is docked at the right showing more than 1 line.

As said above, the beginEvent sets the SelectingLine state and the action enters the PickEntity mode.
Further handled by a entityPickEvent() when indicating near an entity.

In the entityPickEvent you check for a valid entity.
A: The check should be isNull(entity) and it should set this.selectedEntity = undefined;.
B: Verifying that it is a Line or a Polyline entity is simplified by better suited standard functions (library.js).

Code: Select all

    if (isLineEntity(entity) || isPolylineEntity(entity)) {
        this.selectedEntity = entity;
    }
    else {
        this.selectedEntity = undefined;
        // Perhaps issue warning
    }
C: About your TODO ... Use the predefined and named things, don't bother by their enumeration.
D: We don't have to set a flag like this.isLineEntity because such a test is straightforward.


At this point it start to deviate a lot.
Not a Line or Polyline it never exits the PickEntity mode.
If yes, state SettingSegments is set but that is not a state that relies on mouse actions.
Eventually only handled by a commandEvent and passed on to the divideEntity function.

For an interactive tool that would be called by getOperation in preview or final mode.
It is there that we warn the user of having picked an unsupported entity type.
Typically with this.warnNotLineArcPolyline(); because your tool may also be coded to support Arcs.


Further I will be brief.
Line an Polyline entities both support getPointsWithDistanceToEnd(distance, from)
But that is intended for snapping to points on the entity and per line or polyline segment.
Entity based:
REntity.getPointsWithDistanceToEnd(..)

To handle things mathematically we cast the queried entity to an RShape by var shape = this.selectedEntity.castToShape();
Shape based:
RLine.getPointsWithDistanceToEnd(..)
RPolyline.getPointsWithDistanceToEnd(..)

Something an untrained AI is probably not aware of. :wink:

There is a difference between distributing N points or dividing an entity in N virtual segments adding a point in between.
With default = 16 you get 16 points for the first and 15 points for the second method.
You can add points along the entity including at start and end or not. Preferable not for a closed Polyline.
A Polyline can be logically open and geometrically closed when start and end coincides.

Remark that at the end of the divideEntity function the state SettingPosition is set.
The tool enters the PickCoordinate mode and on a coordinateEvent it will draw 3 points (Three Points example)

Regards,
CVH