Skip to content

Action „Lua Command“

On the dialog Modify Objects the action „LUA Command“ is available enabling to call Lua functions which have defined in the file cnacmd.lua.

In order to select the objects concerned all features on the dialog Modify Objects are available (see Chapter 11 - Modify Objects in the manual „Introduction to CadnaA“).

Opening & editing the Lua command

In CadnaA, select the command Open Lua command file from the Extras menu to open the currently used command file cnacmd.lua in the linked Lua editor (e.g. LuaEdit).

Subsequently, the file can be edited. A command file may contain several Lua functions (function) which are listed on the dialog Lua command.

Alternatively, the code can also be inserted into a local or global text block having the name CNACMD.LUA.

Calling Lua functions

Open the dialog Modify Objects and select the action „Lua Command“. For example, select just the object type „Point Source“ in order to apply one of the functions available from the Lua command file. Select a function from the subsequent dialog Lua Command and click OK.

Dialog Lua Command with the Lua functionsfrom the following example

Example

In the following example, three functions have been defined in the command file cnacmd.lua:

-- function changes the name BEZ to "from LUA-file 3" of all objects found
function cnacmd.find3(o)
    o.BEZ = "from LUA-file 3"
    return 1
end
-- optional description, not inside the function, but outside with reference
cnacmd.find3_descr="BEZ = from LUA-file 3"`

-- function changes ID to "ST_1"
function cnacmd.myfunct_2(o)
    o.ID = "ST_1"
    return 1
end
cnacmd.myfunct_2_descr="ID = ST_1"`

-- function deletes objects foundfunction cnacmd.delete1(x)
    x:delete()
    return 1
end
cnacmd.delete1_descr="delete objects found"`

Copy the above text to an empty file cnacmd.lua (path: C:\Users\USERNAME\AppData\Local\Datakustik\CadnaA) and proceed as described to apply one of the available functions.