passing command line params to lua script.

passing command line params to lua script.

Anonymous
Not applicable
1,337 Views
5 Replies
Message 1 of 6

passing command line params to lua script.

Anonymous
Not applicable

Hello,

I am running a lua script on Netfabb startup using following method

C:\Program Files\Autodesk\Netfabb Ultimate 2020\netfabb.exe /startluascript="D:\MyLuaScript.lua" 

I want to pass a parameter to MyLuaScript.lua, like

C:\Program Files\Autodesk\Netfabb Ultimate 2020\netfabb.exe /startluascript="D:\MyLuaScript.lua" "param1" "param2"

 

Is it possible to send the custom command line arguments (i.e. param1, param2) and access them in MyLuaScript.lua during its execution?

 

Thanks.

0 Likes
1,338 Views
5 Replies
Replies (5)
Message 2 of 6

steffen_anders_adsk
Autodesk Support
Autodesk Support

Hello,

 

No, this is currently not supported. However, in the script you're calling, you could hard-code reading from a configuration file which you would auto-generate similar to how you would auto-generate the command-line you want to use for calling Netfabb.

 

Best regards,

Steffen

 

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online helpKnowledge baseForumsHomepageYouTube

How to get Netfabb Basic: VideoHelpDownload

0 Likes
Message 3 of 6

Anonymous
Not applicable

Hello Steffen,

 

The parameters I want to pass to the lua are decided dynamically, so they can not be read from a config file from inside the lua.

so since the parameters are not allowed, I need to do a very very dirty workaround.
1. create a template lua script (with a special character sequence where the parameters will be replaced)

2. Create a copy of the template script in %temp% folder

3. replace the special char sequence in the lua with param string

4. run the script in net fabb

5. delete after use.

 Repeat above steps whenever needed.

 

I hope you provide capability of passing parameters in future releases. Smiley Frustrated

 

Thanks.

0 Likes
Message 4 of 6

steffen_anders_adsk
Autodesk Support
Autodesk Support

Hello,

 

Remember that you can read files not only of plaintext but also of JSON and XML. These formats are accessible very conveniently through objects, making reading and also writing very streamlined. Instead of replacing string sequences in an actual Lua script, you could auto-generate a new configuration file from your dynamic parameters every time you wish to run the actual Lua script. This would be more robust to debug and to maintain.

An example of reading a configuration of sorts during runtime from a JSON file is realised in the NAS scripts in the Examples folder, NAS standing for Netfabb Application Service.

 

Best regards,

Steffen

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online helpKnowledge baseForumsHomepageYouTube

How to get Netfabb Basic: VideoHelpDownload

Message 5 of 6

Anonymous
Not applicable

Instead of replacing string sequences in an actual Lua script, you could auto-generate a new configuration file from your dynamic parameters every time you wish to run the actual Lua script. This would be more robust to debug and to maintain.

 

Agreed, 

But, creating a json file at run time and accessing it in the lua isn't an elegant way either, especially if I want to access only a couple of parameters.

Command line params to the lua script would be the best way.

0 Likes
Message 6 of 6

steffen_anders_adsk
Autodesk Support
Autodesk Support

Please bear in mind that those would be command-line parameters not so much to the Lua script (or in fact a Lua interpreter) but to Netfabb for which /startluascript itself is a command-line parameter already. Provisioning for yet more parameters that may or may not be relevant to netfabb.exe itself would defeat the purpose as to why Lua was made available in Netfabb in the first place.

And besides, there is really not much difference between (hypothetical example, does not work!)

REM launchNF.cmd:
start "" "C:\Program Files\Autodesk\Netfabb Ultimate 2020\netfabb.exe" ^
    /startluascript="path\to\startupscript.lua" %1 %2
-- startupscript.lua:
parameter1 = arg[0]
parameter2 = arg[1]

and (this does work)

REM launchNF.cmd:
echo {"parameter1":"%1","parameter2":"%2"} > startupparameters.json
start "" "C:\Program Files\Autodesk\Netfabb Ultimate 2020\netfabb.exe" ^
    /startluascript="path\to\startupscript.lua"
-- startupscript.lua:
paramJ = system:loadjson("path\\to\\startupparameters.json")
parameter1 = paramJ:getstring("parameter1")
parameter2 = paramJ:getstring("parameter2")

so that you could use

launchNF.cmd Alice Bob

to launch the whole thing in both cases.

 

Best regards,

Steffen

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online helpKnowledge baseForumsHomepageYouTube

How to get Netfabb Basic: VideoHelpDownload

0 Likes