We have moved to https://dokuwiki.librecad.org/

Lots of content was already moved to the new wiki, but there is still work to do. If you want to contribute, please register a new account at https://dokuwiki.librecad.org/

This wiki will be kept for a while to keep search engine results valid. Moved sites may be deleted here in future.

LibreCAD 3 - Lua Scripting

From LibreCAD wiki
Revision as of 18:31, 18 April 2014 by R. van Twisk (Talk | contribs)

Jump to: navigation, search

Lua is a powerful, fast, lightweight, embeddable scripting language developed by a team at PUC-Rio, the Pontifical Catholic University of Rio de Janeiro in Brazil.

LibreCAD Scripting with lua

One of the scripting languages LibreCAD support's is [Lua]. Lua is the default scripting language and will be available for most simple scripting needs. Lua is very powerful but at the same time provides a easy to understand programming language. Please see Lua's reference manual for more information.

To create entities within a document there is a builder object that allows to add new entities or append selected entities into the build. From there you can apply steps to process the entities. After each step the result of the step is passed along to the next step.


Example 1:

-- get the current document
d=app.currentDocument()

-- Create a Line
l=Line(Coord(0,0), Coord(10,100));

-- Get the builder object (will be renamed later)
b=Builder(d)

-- Append the line
b:append(l)

-- Make a copy 'in place' of the line
b:copy(Coord(0,0)) 

-- Rotate the line
b:rotate(Coord(0,0), math.rad(45))

-- Do this 7 times
b:loop(7)

-- Apply into the document
b:execute()

Result [File:LibreCAD_-20140418-132431.jpg]