Selection From Polyline

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
PeterR
Junior Member
Posts: 10
Joined: Thu Oct 21, 2010 7:34 pm

Selection From Polyline

Post by PeterR » Wed Feb 16, 2022 2:34 pm

Linux: Ubuntu 20.04 and Wayland
qcad-3.27.1-pro-linux-qt5.14-x86_64

Hello,

I want to change a rectangle build by 4 lines to a rectangle made by one polyline using a script. I use your script "ExThreePoints.js" to test functions for my script and copied it to my script ExTrial.js for modifications.

I found two entries in your forum for the solution:
https://qcad.org/rsforum/viewtopic.php?f=107&t=7210
https://qcad.org/rsforum/viewtopic.php?f=32&t=7057

But none of this will work. I put the code to my script and got in both case the error (running qcad in debug mode): "Uncaught exception at scripts/PPeters/ExTrial/ExTrial.js:111: ReferenceError: Can't find variable: PolylineFromSelection"
(attached screenshot)

How do I have to change my code that it works?

Regards
Peter
Attachments
ExTrial.js
(6.59 KiB) Downloaded 263 times
qcad forum 01.png
error message
qcad forum 01.png (123.71 KiB) Viewed 4170 times

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

Re: Selection From Polyline

Post by andrew » Wed Feb 16, 2022 8:52 pm

You have to include the script before using it:
include("scripts/Pro/Draw/Polyline/PolylineFromSelection/PolylineFromSelection.js");

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

Re: Selection From Polyline

Post by CVH » Thu Feb 17, 2022 1:41 pm

PeterR wrote:
Wed Feb 16, 2022 2:34 pm
I want to change a rectangle build by 4 lines to a rectangle made by one polyline using a script.
Remark that di.selectAll(); will select all selectable entities in a drawing.

Poly from selection would than merge everything that can be considered as a chain of segments.
And not only some rectangles build by 4 lines.

For that you need to evaluate all entities first on whether they make up a quadrilateral.
Deselecting those that don't or merely selecting those that will.

Without selecting all first in your script, it would run on those that are selected before you initiate it.

In the way you are scripting right now is nothing more than TA followed by OC. :wink:

Remark also that the QCAD shape tools create quadrilaterals as 4 lines or optionally as a polyline.
Maybe it is just a question of using the correct option on creation.

Regards,
CVH

PeterR
Junior Member
Posts: 10
Joined: Thu Oct 21, 2010 7:34 pm

Re: Selection From Polyline

Post by PeterR » Thu Feb 17, 2022 2:23 pm

Thank you for the fast and helpful answer. After I added the "include" it works in the intended way.

I suggested, that there is "include" missing, but I could not find it in the "Source Code" that I downloaded from your website(https://github.com/qcad/qcad/archive/v3.27.1.0.zip) or in the documentation of the "QCAD Application Framework" (https://www.ribbonsoft.com/doc/qcad/3.0 ... index.html).

For future use: Where shall I find a documentation about such objects and functions?

Regards
Peter

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

Re: Selection From Polyline

Post by andrew » Thu Feb 17, 2022 2:28 pm

Please keep in mind that PolylineFromSelection is not part of the public API but part of the proprietary API of QCAD Professional. Feel free to call this from your script, but keep in mind that this API might change in a future version.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”