Need script example [solved]

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
jooogger
Junior Member
Posts: 15
Joined: Sun Nov 22, 2020 4:34 am

Need script example [solved]

Post by jooogger » Sun Feb 07, 2021 3:05 pm

OS: Windows 7x64, QCAD 3.25.2.
I need auto-draw some lines to drawing, but can't find example of minimal script. Would someone give me example or link to example?

Task is very easy: make line x1,y1 to x2, y2, then to x3,y3 and so on. Script will be generated by other software.
Last edited by jooogger on Sun Feb 07, 2021 10:18 pm, edited 1 time in total.

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

Re: Need script example

Post by andrew » Sun Feb 07, 2021 9:32 pm


Markz
Junior Member
Posts: 19
Joined: Fri Jan 29, 2021 4:32 am

Re: Need script example

Post by Markz » Sun Feb 07, 2021 9:38 pm

jooogger wrote:
Sun Feb 07, 2021 3:05 pm
OS: Windows 7x64, QCAD 3.25.2.
I need auto-draw some lines to drawing, but can't find example of minimal script. Would someone give me example or link to example?

Task is very easy: make line x1,y1 to x2, y2, then to x3,y3 and so on. Script will be generated by other software.
Here's the first script I've written for QCAD! It may be a terrible approach e_surprised I put the points in the variable pointStr, where each point is separated by a slash, and each coordinate by a comma. That should make it easy to generate your own string (depending on your source data). The code and data structure will need to be revised if your locale uses commas instead of periods to specify decimals.

What I learned is that the ecma used by Qcad doesn't support the x of array syntax that would have made the task easier.

Code: Select all

pointStr="0,0/5,5/11,3/-3,6,7" ;
pointSet = pointStr.split("/") ;
var pt = pointSet[0] ;
var p1 = [ pt.split(",")[0] , pt.split(",")[1] ] ;
for ( i=1 ; i<pointSet.length; i++) {
    pt=pointSet[i] ;
    p2 = [ pt.split(",")[0] , pt.split(",")[1] ] ;
    addLine(p1,p2) ;
    p1 = p2 ;
}


jooogger
Junior Member
Posts: 15
Joined: Sun Nov 22, 2020 4:34 am

Re: Need script example

Post by jooogger » Sun Feb 07, 2021 10:18 pm

Markz wrote:
Sun Feb 07, 2021 9:38 pm
Here's the first script I've written for QCAD!
Thank you! Works fine!

Post Reply

Return to “QCAD 'How Do I' Questions”