## Change sheet name via script? Use external libs?

lindoservico
Posts: 6
Joined: Mon Dec 12, 2022 4:21 pm
Model of CNC Machine: Segmag 1060, Ouplan 3020, Vevor 3018

### Change sheet name via script? Use external libs?

Greetings Master,

We have managed to find from the SDK documentation how to create a sheet, but we cannot find how to change the name of the sheets.

This is what we have working

Code: Select all


local job = VectricJob()
local sheet_manager = job.SheetManager

-- get the id of an existing sheet
local existing_sheet_id = sheet_manager:GetSheetIds()()

-- create a new sheet with the same properties as the existing sheet
sheet_manager:CreateSheets(number_of_files, existing_sheet_id)

MessageBox("existing_sheet_id " .. sheet_manager:GetSheetName(existing_sheet_id))


We are presuming that somehow since the sheet is a child of the cadmanager that it might have some property Name that we can directly change, or that there should have been a SetSheetName that we cannot find any information on how to do it.

----

Another issue we have been facing is there is no documented information on how to load a external library, namely we would like to use io.lua and folllowing the LUA standard programming it always returns as a nill value

According to lua documentation here: https://www.lua.org/pil/8.1.html the code below should work if the io.lua file and correct dependencies was in the same folder as the gadget, why does it return a nill value?

Code: Select all

-- Import the io library
local io = require("io")

-- Open a file in write mode
local file = io.open("test.txt", "w")

-- Write some text to the file
file:write("Hello, Vectric Aspire!")

-- Close the file
file:close()


Vectric Wizard
Posts: 3441
Joined: Sat Jul 27, 2013 10:08 pm
Model of CNC Machine: AXYZ 4008

### Re: Change sheet name via script? Use external libs?

lindoservico wrote:
Wed Feb 08, 2023 12:52 am
We have managed to find from the SDK documentation how to create a sheet, but we cannot find how to change the name of the sheets.
Short answer: you can't (probably). Longer answer: there is no method (at least not a documented one) in the API to effect renaming. Make sure you get it right the first time...
lindoservico wrote:
Wed Feb 08, 2023 12:52 am
Another issue we have been facing is there is no documented information on how to load a external library, namely we would like to use io.lua and folllowing the LUA standard programming it always returns as a nill value
Yeah. That's irriated me too. You can put your required library in the same place as strict.lua but that's not prime.

Your post spurred me to figure it out. There is a simple fix: alter a variable called "package.path".

For example if in your gadget directory you have a directory called "libs" where you are storing all your "require" modules then you can have the gadget find them by using the following:

Code: Select all

function main(scriptPath)
package.path = package.path .. ";" .. scriptPath .. "\\libs\\?.lua"
require("myModule")



Default "package.path" variable

Require fails using this path

"package.path" with our path added. Require succeeds.

Attached is a test gadget to demonstrate this. Rename the zip file to package_path.vgadget and install into your Vectric program.

Running it as is will have the "require" fail—the default condition. There is a comment line that if you remove it will allow the require to succeed.

Steven
Attachments
package_path_test.zip

Vectric Wizard
Posts: 3441
Joined: Sat Jul 27, 2013 10:08 pm
Model of CNC Machine: AXYZ 4008

### Re: Change sheet name via script? Use external libs?

Vectric Wizard
Posts: 3441
Joined: Sat Jul 27, 2013 10:08 pm
Model of CNC Machine: AXYZ 4008

### Re: Change sheet name via script? Use external libs?

Hmm... It's annoying that the above solution means that you can only "require" in the main() function or other sub-function of that. It would be nice to "require" in the global area as with requiring strict or mobdebug.

Poking through the global variable table (_G) I found that "GetUserGadgetLocation" is defined.

So, I wonder if something like the following is possible?

Code: Select all

-- VECTRIC LUA SCRIPT

package.path = package.path .. ";" .. str .. "\\?.lua"

require "myGlobalModule"

function main()
...


lindoservico
Posts: 6
Joined: Mon Dec 12, 2022 4:21 pm
Model of CNC Machine: Segmag 1060, Ouplan 3020, Vevor 3018

### Re: Change sheet name via script? Use external libs?

Short answer: you can't (probably). Longer answer: there is no method (at least not a documented one) in the API to effect renaming. Make sure you get it right the first time...

Wonder if this can be done somehow via the luaUUID as written on page 70 of the API

Every object in the job has a unique id referred to as a UUID. As these id’s are difficult to save and
process from lua, the luaUUID object wraps a windows UUID and lets it be treated as a string.

Code: Select all


Constructor
luaUUID() - Constructor
A new luaUUID with a new unique id.



lindoservico
Posts: 6
Joined: Mon Dec 12, 2022 4:21 pm
Model of CNC Machine: Segmag 1060, Ouplan 3020, Vevor 3018

### Re: Change sheet name via script? Use external libs?

On jimandi's code for the Gadget EasyBoxMaker he has the commands split by multiple files, is this not similar to what we need when importing a library?

Code: Select all

function OnLuaButton_InquiryHelp01()
Helper = assert(loadfile(Project.AppPath .. "\\Box_Help\\EasyBoxMakerHelp01_Ver" .. string.format(Project.ProgramVersion) .. ".xlua")) (Helper)
HTMLHelp01()
local Wx, Wy = DialogSize(DialogWindow.HelpSubXY)
dialog:ShowDialog()
DialogWindow.Help01 = nil
DialogWindow.HelpSubXY = tostring(dialog.WindowWidth) .. " x " .. tostring(dialog.WindowHeight)
RegistryWriter()
return  true
end


Vectric Wizard
Posts: 3441
Joined: Sat Jul 27, 2013 10:08 pm
Model of CNC Machine: AXYZ 4008

### Re: Change sheet name via script? Use external libs?

And how does a UUID relate to a sheet name? That is if you have the former how are you going to change the latter?

lindoservico
Posts: 6
Joined: Mon Dec 12, 2022 4:21 pm
Model of CNC Machine: Segmag 1060, Ouplan 3020, Vevor 3018

### Re: Change sheet name via script? Use external libs?

Yeah... I dunno

Supposedly the UUID on the sheet is R/W, i'm guessing since it inherits from the Job it should have a .Name property but that not only is not listed it does not work, so i was thinking the UUID and the name was the same but i'm just wild guessing.

There is a Get Sheet name but no Set Sheet name unfortunately

Anyone from the Vectric team we can Tag for a answer?

bnewman
Posts: 9
Joined: Sun Feb 27, 2022 5:30 pm
Model of CNC Machine: One Finity Woodworker X-35

### Re: Change sheet name via script? Use external libs?

Would I be correct in assuming there is also no way to set the name of sheet when you create it from the API?

So what are the names of sheets set to when you create them from the API?

Vectric Archimage
Posts: 13678
Joined: Thu Nov 23, 2006 2:19 pm
Model of CNC Machine: ShopBot PRS Alpha 96x48
Location: Surrey, UK

### Re: Change sheet name via script? Use external libs?

I would assume they follow the same naming convention as if they were created via the UI. They start from 1 and increase by 1 skipping any used sheets including number if it's there. Might start from the base sheet if that option is used in the call but I haven't tested that. Either way they are always in the format Sheet xx.

I expect there is no option to set a sheet name when creating it as that option doesn't exist in the UI during the creation phase. It's a separate user action after the sheet has been created.

All IMO of course. There may be a way of doing it that just hasn't been documented or isn't clear from the documentation. I certainly can't see a way.

Generally I use a scripting language like AutoIt to when I can't find a method in LUA or can't figure out how to do it. I'd say 75% of my day to day automated processes are a mixture of script and LUA rather than pure LUA.

One of the many reasons I don't write gadgets for others anymore. I can make the code as clunky as I like and not worry about others setups when it's just for me.

lindoservico
Posts: 6
Joined: Mon Dec 12, 2022 4:21 pm
Model of CNC Machine: Segmag 1060, Ouplan 3020, Vevor 3018

### Re: Change sheet name via script? Use external libs?

Fri Feb 10, 2023 9:28 pm
Hmm... It's annoying that the above solution means that you can only "require" in the main() function or other sub-function of that. It would be nice to "require" in the global area as with requiring strict or mobdebug.

Poking through the global variable table (_G) I found that "GetUserGadgetLocation" is defined.

So, I wonder if something like the following is possible?

Code: Select all

-- VECTRIC LUA SCRIPT

package.path = package.path .. ";" .. str .. "\\?.lua"

require "myGlobalModule"

function main()
...

----

So i've been testing and documenting for internal use and this and this works perfectly

Code: Select all

-- VECTRIC LUA SCRIPT

package.path = package.path .. ";" .. str .. "\\?.xlua"
require "myLibrary"

-- Meaning:
-- (the_list_of_path_values) = (itself) + (new;value) + (Z:\Path\to\your\file\) + (require?file?var)(.extension)

function main()
return true
end

It can be outside of the main function or inside, difference is if you have it outside and you do not place your required file in one of the search folders of package.path you will get a nil value error and not much information.
If however one puts the function inside the function Main there will be a error listing the paths that package.path is searching

Code: Select all

-- Another thing worth of note is if one wants to assign the require a new name it is a matter of doing
mynewname = require "myLibrary"

-- And then one can access the library functions and properties via the new name
mynewname.somefunction()
mynewname.someproperty


lindoservico
Posts: 6
Joined: Mon Dec 12, 2022 4:21 pm
Model of CNC Machine: Segmag 1060, Ouplan 3020, Vevor 3018