Scripting #256

smcmurray opened this Issue Dec 15, 2011 · 28 comments


None yet

dxli mentioned the desire for some kind of scriptability.

I'd like to hear what thoughts are bouncing around on this topic.


Python scripting would be cool!

LibreCAD member

I feel we have to implement more command system functions first. My own option though.

We got so many new features requested, but need more developers.


It would be nice to structure the command system and the scripting scheme into a single concept. It might save a lot of work to try to think them out together before adding a lot more command system functions.

LibreCAD member


I know scripting for post people is HUGE and effectively we can drop the command system all together if we can control LibreCAD with a script. let's say we have a script called : createStuff.lcscript

Then we can simply do this : ./LibreCAD --script createStuff.lcscript

And LibreCAD will load and run the script createStuff.lcscript.
The script can load dxf file, do work on it, do a export and things that make sense and should be possible.

Just a though that I think scripting would be more important then command tools.


I don't think scripting is more important than command tools. I think they can be the same thing. Command tools are just a DSL. Why not expose the command tools as the API for scripting?

@smcmurray smcmurray closed this Feb 12, 2012
@smcmurray smcmurray reopened this Feb 12, 2012

Oops. I didn't mean to close the issue. Sorry.

LibreCAD member


that would be possible if the command line tool is a one line script (I guess).

Scripting has been a frequent request in my inbox (since 2010) though... command line tools has never been a request.

There where mails send to me personally..


I recognize that I have not contributed any code to this end, so I submit my ideas as such. Having said that, here is what I hope to see: By command line tools, I don't think we are talking about the OS shell/cli. I thought we were talking about the commands represented by buttons, etc. in the UI and that can be typed into the "Command:" box within LC. Eventually, one of those commands could be to read and execute a script from file. And there could be an OS command switch to load and execute a script file on LC startup.

It seems to me that the Command box within LC does not have to be limited to a one line script. That might be where it starts as indeed it already has that functionality. It would be nice to see those one-liners appear in the Command box even as they get built though GUI clicks. A scroll through the Command window would be a scroll through the history of your work during the session. The contents would, in fact, constitute a script.

Eventually, the scripting DSL might grow more sophisticated than the command API represented by the tools available in the GUI. For instance, it might grow while or for loops, etc. I don't know. I'd be happy just to see it get this far. Then I will imagine further.


My suggestion: Don't go for a DSL, use Lua since it is made for exactly this kind of scripting needs it has really simple syntax and performs fast. You could actually go ahead and post something about using Lua on LibreCAD on the Lua mailing list and see the kind of response you get.

LibreCAD member

I feel we don't have enough resource to add script support for 2.0 series, as all our current developers are busy on other stuff. Help is welcome here, because we still want it for LibreCAD the 3.0 series.

LibreCAD member

I feel we don't have enough resource to add script support for 2.0 series, as all our current developers are busy on other stuff. Help is welcome here, because we still want it for LibreCAD the 3.0 series.


Just throwing ideas out there:

It'd be awesome if scripting were like VMD (molecular graphics viewer) where scripts could allow you to select portions of the drawing and do calculations on it. For instance, if I'm drawing a road and I select a curve, I could invoke a script to give me the max speed (and other parameters) for that curve.

Also, the speed of lua is pretty good, I wonder if it'd be possible to implement new features as lua scripts instead of C++. This could allow for faster prototyping and allowing more people to contribute features (to 3.x).


I come from an AutoCAD Background, no matter what scripting language is used (For those that don't know, AutoCAD uses a custom LISP that allows access to commands), will we be able to easily convert addons from AutoCAD. I don't have the smarts to help out with the scripting system, but I would love to get involved and implement stuff so we can have more of a Revit/MEP system addon.

@r-a-v-a-s r-a-v-a-s added the request label Aug 8, 2015
LibreCAD member

We use boost, which has:

I'm interested in hearing more about things people actually plan on writing if scripting is implemented.

if I'm drawing a road and I select a curve, I could invoke a script to give me the max speed (and other parameters) for that curve.

Curve analysis could be a nice feature by itself. You might consider opening a separate issue.


My background, other than AutoCAD as mentioned above, covers HVAC (High Volume Air Conditioning) design. In the past, before the Revit/MEP edition's of AutoCAD I had written several Dialog implemented AutoLISP scripts to help facilitate creating duct work systems faster, and more accurately. I wouldn't mind re-implementing those in an Open Source capacity.

LibreCAD member

Thank you. 😎
I'm curious, could you list the equivalent Revit/MEP tools?


I would need to recreate them, as they were developed when working for an employer that retains the copyright on the scripts as they were built in house.
I'm not sure how AutoDESK have implemented the extra tools of Revit/MEP, as in C, AutoLISP, or even in .net.
Not sure exactly what your asking to list, but here ( is the site explaining what Revit/MEP is.

LibreCAD member

For anyone interested in implementing python scripting:

It looks like no one has worked on these since this repository was created.
I wouldn't use it much so it's not on my list.


CAD manager, mech/electrical designer here. Python is fantastic, however, so many of us have so many lisp routines, macros, etc already written in lisp that it would be nice to see that functionality from the command line. Now, I'm willing to commit to this issue as it is imperative that we all have a free lisp interpreting drafting machine at our disposal. My big question is, how does LibreCAD take the C functions and actually draw what's being coded, i.e. in librecad/src/cmd/ ? If I could get that information, I think we can get to the next step.


That sounds like a plan.
If we could find out how Python uses the API to draw, then it may not be too difficult to build something to convert from LISP to Python.

LibreCAD member

We'll take what we can get, and hope that whatever we get doesn't add a complicated dependency. ;-]
I wonder if it makes sense / is possible to add a scripting language via the plugin feature...
The existing pugin interface is doc_plugin_interface.cpp

For adding files you will probably want to check out the pro files (
and read about qmake

Some files you might want to check out:
rs_painter / rs_painterqt
qg_graphicview / rs_graphicview
rs_line, rs_arc, rs_polyline, etc...

It looks like the actual drawing happens in rs_painterqt via QPainter.


@r-a-v-a-s wow, thank you that was very helpful! I'm going to sit on these files for a couple days and see what I can uncover, I'll k.i.t.


Please forgive my vast lack of knowledge about C and C++, but I believe there must be an interpreter somewhere that can at least translate function definitions and calculator stuff from LISP to C, and maybe that is suitable for a plugin (maybe, idk). The thing is, sside from special commands and functions, I also have a treasure trove of interactive custom LISP macros with icons that I made and everything like that.


There's a project called CL-VECTOR with an expanded visual lisp package called VECTO that may be suitable for what we are looking for. CL-VECTOR is essentially a vector drawing tool with very limited graphical capabilities, but the math is there and it looks good. VECTO extends the graphical capabilities by drawing a canvas of the paths generated from the vectors and then formats the canvas as the user needs, much like CAD. There are already functions for all the shapes and line formatting that we are used to in CAD.

So how do you get something written in one language and plug it into something written in another language?

The project is also on github and covered by an MIT license so we're good to credit and reuse....

LibreCAD member

I have no experience embedding a scripting language;
however, I don't think cl-vector is what you want.
The project I find in my searches is:
Unfortunately it looks like their documentation is lacking.
Does it work with C++11 / Qt? I have no idea.

The nice thing about python is that we already use boost,
and the documentation for embedding actually exists,
and we already have three files to help someone see how to approach it.
Although I do understand why you want lisp.


Python scripting would be tremendously useful for me. I do a lot of repetitive tasks in librecad that I would prefer to script. I come from a computer engineering background, so the 2D/3D CAD world is somewhat new to me. KiCAD has a python scripting frontend that is really just a wrapper around their C++ functions along with an embedded python interpreter. I think starting from there is a good approach (similar to what is in the python wrapper files in I have some experience with writing python library wrappers (primarily using SWIG). I'm short on time, but I will update this thread if I come up with anything useful.

LibreCAD member

I just saw this and had some pointers to help. I've embedded python and lua scripting into game engines:

You don't need boost, you can do it yourself simply with python libraries. However, I used SWIG to generate the interfaces from C++ to nearly every scripting language at once
(Python Java Perl R Scilab, to name a few)

First step is to define which functions you want to expose via this scripting api. In fact, you can expose existing functions by just telling swig to make all the functions defined in an existing header file available to the scripting engine, and it will generate all the needed code as well as the python module (or module in whatever scripting language you want) that you would import to access the API.

Second, you need to embed an interpretter - which for python and lua is super-easy (5-6 lines of code). This interpretter would load the interpretter, load the interpretter's module for the api, and run the scripts.

Tutorial on using SWIG to create bindings for nearly all scripting languages:

How to embed python in your code:

This is an example of loading and executing a script file:

I also wrote a scripting console in there too... it was a year ago so i don't remember where it is in the code!

LibreCAD member

While it's not scripting, you can at least load a command file now.
This is a .txt file with valid command line input on each line.
It also supports string rewriting using command variables,
and multiple commands on a single line using the ; delimiter.


Regarding legitimate scripting:
I think I could implement support for javascript using QJSEngine.
However, I won't be taking on any more projects until the tangent point bugs are eliminated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment