Python or Lua for scripting QCAD?

Drop in here to discuss whatever you want.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
alexbottoni
Newbie Member
Posts: 9
Joined: Wed Nov 26, 2014 5:21 pm

Python or Lua for scripting QCAD?

Post by alexbottoni » Sat Nov 29, 2014 3:31 pm

Hi All,
Just out of curiosity, is there any plan to implement a Python or Lua scripting interface in any future version of QCAD?

Could Python or Lua be a useful/appreciated alternative to ECMAscript as a QCAD scripting language?

How hard (or labour-demanding) could it be to expose the QCAD API to Python or Lua?

Thanks for your attention

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

Re: Python or Lua for scripting QCAD?

Post by andrew » Sat Nov 29, 2014 4:39 pm

First of all, I'd like to point out that ECMAScript was the natural choice for QCAD simply because Qt comes with built-in support for ECMAScript (QScriptEngine). I do know and appreciate both Python and Lua and if Qt came with one of those out of the box, QCAD would very likely be using whatever Qt came with.

The initial effort for an additional language would be likely at least 1-2 months work per script language to get started. Once an automated mechanism is in place, keeping a script API up to date should be a small to zero effort (as it is the case with the ECMAScript interface for which script bindings are generated fully automatically from Qt / QCAD C++ headers).

Another aspect to keep in mind is fragmentation. The ECMAScript interface is much more for QCAD than just a bunch of optional scripts that extend it: Almost every single tool of QCAD is at least on the highest level of user interaction implemented in ECMAScript. Many tools are entirely implemented in ECMAScript (for example the part library browser). Scripts written in another script language would not have access to some essential functionality (and of course the other way around). This is a pretty big deal considering the fact that the bare QCAD community edition comes with 75'000+ lines of ECMAScript code.

To answer your question: personally, I have no plans to implement support for any additional scripting languages in the future. Perhaps, it's because I don't have any strong feelings about programming languages in general. In my opinion, the language is just a tool to write algorithms. I've never felt that the language was the problem, the algorithm usually is.

Having said that, QCAD is of course open source and if someone feels like writing a plugin that exposes an alternative script API, go for it :)

alexbottoni
Newbie Member
Posts: 9
Joined: Wed Nov 26, 2014 5:21 pm

Re: Python or Lua for scripting QCAD?

Post by alexbottoni » Sat Nov 29, 2014 5:23 pm

andrew wrote:Having said that, QCAD is of course open source and if someone feels like writing a plugin that exposes an alternative script API, go for it :)
I'm afraid that having a not negligible part of the system implemented in ECMAScript makes virtually impossible to add another scripting engine to QCAD with the amount of time and human resources that are usually available to any individual volunteer programmer or event to many small teams. It would be crazy to re-write at least 75.000 LOC just to get the same system you started with (accessible from another language). This look like a quite ultimative tombstone on this idea.

Once said that, let me also say that I understand you very well. Qt exposes a very good interface to ECMAScript (Qt Quick and QML) and it would have been totally crazy not to use it just because it is Javascript. You made the right decision (the most rational one) when you decided to use this interface. If a bad choice was even made, it was made by the Trolltech/Nokia manager when they decided to use ECMAScript instead of a more acceptable language. They were not alone, anyway: even the GTK team supports ECMAScript/Javascript as one of their official and supported bindings.

Since a long time, QCAD is by far the most complete and the most versatile open source 2D CAD system available on the market and this is possible largely because of rational decisions like the one you took about the scripting language.

Thanks for your attention and your time.

artisanicview
Junior Member
Posts: 12
Joined: Sat Jun 19, 2010 6:23 pm

Re: Python or Lua for scripting QCAD?

Post by artisanicview » Fri May 27, 2016 10:20 am

I'm learning Python, so I'm interested on the python scripting in Qcad:

Embedding Python into Qt Applications

PythonQt

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

Re: Python or Lua for scripting QCAD?

Post by andrew » Fri May 27, 2016 10:30 am

artisanicview: As outlined above, support for other script languages is very unlikely to be added to QCAD (unless someone from the community picks up on this).

User avatar
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Re: Python or Lua for scripting QCAD?

Post by hungerburg » Mon May 30, 2016 7:54 pm

Its the chat forum, so here to my take: ECMA-Script is not a bad choice. It looks like C yet is so much more expressive. People starting to code can use acquired skills on the web and many other places. There are lots of free tutorials, references and code samples.

ECMA-Script sure is not the hammer to hit any nail, but qCAD is proof, that it can scale to tens of thousands of lines, which is all but due to the genius of Andrew's of course! I do not remember the last time that qCAD crashed on me, must have been in the beta days :)

Dacicusan
Active Member
Posts: 49
Joined: Sat Oct 14, 2017 1:44 am

Re: Python or Lua for scripting QCAD?

Post by Dacicusan » Sun Oct 15, 2017 7:56 pm

I'm also very interested on seeing some Python scripting support in Qcad/CAM.

Making some research I discovered this PythonQt binding project: pypi.python.org/pypi/PyQt5. Hopefully wont be difficult to implement this module in Qcad.

Post Reply

Return to “Chat”