Batch Line Drawing

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
erikquinn
Registered Member
Posts: 1
Joined: Sat May 28, 2016 8:05 am

Batch Line Drawing

Post by erikquinn » Sat May 28, 2016 8:36 am

Hello! Happy new qCAD user here.

You'll have to excuse me; I come from the AutoCAD world, and may be overlooking something that's staring me in the face-- but here's my question:

How can I quickly draw many lines for which I already have the data points?

For example, in AutoCAD, I would simply make a script (*.scr) and run it while in the desired layer:

Code: Select all

LINE -122.306186110,47.437839992 -122.306179851,47.438775413

LINE -122.306179851,47.438775413 -122.306172252,47.439686358

LINE -122.306172252,47.439686358 -122.306162417,47.440171167

LINE -122.306162417,47.440171167 -122.306149900,47.440794781

LINE -122.306149900,47.440794781 -122.306155264,47.441400960

LINE -122.306155264,47.441400960 -122.306154817,47.441822067

LINE -122.306154817,47.441822067 -122.306133360,47.442687750

LINE -122.306133360,47.442687750 -122.306131124,47.443001568

LINE -122.306131124,47.443001568 -122.306149900,47.443550751

LINE -122.306149900,47.443550751 -122.306135148,47.444038577

LINE -122.306135148,47.444038577 -122.306158394,47.444795966

LINE -122.306158394,47.444795966 -122.306156605,47.445383370

LINE -122.306156605,47.445383370 -122.306163311,47.445783019

LINE -122.306163311,47.445783019 -122.306163758,47.446150146

LINE -122.306163758,47.446150146 -122.306151688,47.446835116

LINE -122.306151688,47.446835116 -122.306147665,47.447595522

LINE -122.306147665,47.447595522 -122.306165546,47.448795140

LINE -122.306165546,47.448795140 -122.306190580,47.449975312

LINE -122.306190580,47.449975312 -122.306227822,47.452322190

LINE -122.306227822,47.452322190 -122.306188792,47.455723877

LINE -122.306188792,47.455723877 -122.306152582,47.457037233

LINE -122.306152582,47.457037233 -122.306154817,47.460014820

LINE -122.306154817,47.460014820 -122.306156605,47.462684289

LINE -122.306156605,47.462684289 -122.306159288,47.463446707

LINE -122.308007777,47.431509979 -122.307304144,47.431507967

LINE -122.307304144,47.431507967 -122.306596488,47.431505956

LINE -122.306596488,47.431505956 -122.306139171,47.431676947

LINE -122.306139171,47.431676947 -122.305810601,47.431966625

LINE -122.305810601,47.431966625 -122.305638045,47.432323694

LINE -122.305638045,47.432323694 -122.305566072,47.432502732

LINE -122.305566072,47.432502732 -122.305554450,47.433433458

LINE -122.305554450,47.433433458 -122.305530310,47.435394488

LINE -122.305530310,47.435394488 -122.305727452,47.435679473

LINE -122.305727452,47.435679473 -122.306185216,47.435980886

LINE -122.306185216,47.435980886 -122.306178510,47.436952181

LINE -122.306178510,47.436952181 -122.306186110,47.437839992
I've come across:
Misc --> Import/Export --> Import Points (sounds relevant, but doesn't seem to support lines, despite a few creative efforts)
Misc --> Script Examples --> Import/Export --> Dump Polyline (sounds like the opposite of what I'm asking; this will be useful later)
Misc --> Development --> Script Shell (sounds like the place you go to run your scripts)

The lines can be drawn one-by-one via the command line using the "line" command, but this is wholly unpractical for the 10000+ lines of data I'm working with. It makes me rather inclined to think, however, that there is a straightforward method for achieving this. And if I'm missing something glaringly obvious, my apologies; I really did spend a lot of time searching for answers and reading documentation before resorting to asking you all to take the time to help me.

I am well-versed in reformatting/rearranging the data (thanks Sublime!) and ECMAScript, so I am willing to "get my hands dirty" if the easiest solution necessitates it. So can anybody provide some guidance on how to go about having qCAD draw long lists of lines and/or polylines from delimited-text data?

Thanks in advance for your help.

Erik
Win7x64, QCAD 3.15.1 (rev0b70090)

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

Re: Batch Line Drawing

Post by andrew » Sat May 28, 2016 9:07 am

Write your script into a text file in the format:
addLine(x1,y1,x2,y2)
addLine(x1,y1,x2,y2)
...
This can be any valid ECMAScript, so feel free to use more advanced functions, loops, conditions, formulas, read data from a database or XML, etc.

You can then either copy / paste this into the script shell (Misc > Development > Script Shell) or run QCAD and execute the script from the command line:

Code: Select all

qcad.exe -exec myscript.js
addLine is part of the relatively new 'Simple API' defined in simple.js. The Simple API is intended to be easier to use than the standard QCAD API, but might be slightly less efficient in some cases.

riverbuoy
Senior Member
Posts: 121
Joined: Thu Oct 03, 2013 5:37 pm

Re: Batch Line Drawing

Post by riverbuoy » Sat May 28, 2016 6:13 pm

Hi erikquinn,

I also come from the Autocad world, and I miss the ability to run scripts and/or lisp functions, at any time, in any drawing. So I have written a command 'RunScript' which allows you to run a script when you want to, and as many times as you want to, without having to restart QCAD. So, in your example, you could load the drawing, change to the appropriate layer, then use 'RunScript' to run your script.
I did post this some time ago, but either Andrew missed it, or he decided it wasn't something users were crying out for. But I think you would find this useful. It works very like the open function, but shows script (.js) files. You select the script you want to run, and click open. This runs the script.
Note: this won't provide any feedback of any kind, so it won't help you develop the script.

I have attached a zip file containing a directory 'RunScript'. Extract this, and put it into the 'scripts/File' directory. The command appears in the File menu, and on the File toolbar. The shortcut for this command is 'XC'.

Hope you find this useful.

Regards

riverbuoy
Attachments
RunScript.zip
(10.83 KiB) Downloaded 430 times

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

Re: Batch Line Drawing

Post by andrew » Mon May 30, 2016 7:57 am

riverbuoy wrote:either Andrew missed it, or he decided it wasn't something users were crying out for.
There are some other implications with that. The QCAD script interface is extremely powerful: a script can do virtually anything that any software can do, including crashing QCAD, wiping out all your files, killing other processes or sending out spam e-mails into the world, etc.

Having a menu that allows the user to run any script from disk makes it just a bit too easy for an unexperienced user to do something potentially very harmful by downloading and executing a script from somewhere. I agree that there should be such a tool, but we have to keep these potential pitfalls in mind.

The proper solution would be sandboxing the script (VFS, etc). Unfortunately, sandboxing is far from trivial.
Reducing the API to remove certain classes and functions would also be a possibility but would also make scripts less useful (no file removed, no system commands, etc).
A simpler way could be a user preference that forces the user to tick a checkbox with some warnings to explicitly enable that tool. Or alternatively a dialog that pops up before the user can run a script, with an option to not show the dialog again..

What do you think?

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

Re: Batch Line Drawing

Post by andrew » Tue May 31, 2016 10:11 am

Update: QCAD 3.15.2 has a slightly modified version of the RunScript under Misc > Development > Run Script. A warning dialog is shown by default before a script is run. This was the easiest way to make such a tool available for now.

Post Reply

Return to “QCAD 'How Do I' Questions”