Demonstration of methods for unloading an extension during main application is running
Objectives
- Create the simplest and functional extension on C#;
- Use various methods to unload extensions.
Practical part
Order of actions:
- Open SprutCAM because we will be editing the list of utilities while the application is running.
- Open the repository in our GitVerse account and clone it.
- Find the directory
GCodeGeneration\ExtensionUtilityNCMakerNet- this is what you will base your new extension on. - The extension is already correct. In this lesson, we will not modify it but will only change the configuration file.
- Open .NET project and compile it -
bin/debug/ExtensionUtilityNcMakerNet.dllshould appear; - Copy
ExtensionUtilityNcMakerNet.settings.jsonintobin/debug/; - Add extension in the first time:
- Archive both files (
dllandsettings.json) into file with*.dextextension; - Execute created
*.dextfile - it will be added to SprutCAM. It has nounload_modesetting, so it will be set to defaultumJustAfterExecution;
- Archive both files (
- In SprutCAM open utilities menu and press
Generate G code by C#. Then close notepad window with results. - Don't close SprutCAM and add extension in the second time:
- Modify
bin/debug/ExtensionUtilityNcMakerNet.settings.json:- Add unload mode
umManuallyFromUI; - Change caption;
{ "name": "Extension on C# to generate G code", "description": "Extension on C# to generate G code", "module_path": "${extensionJsonFolder}/ExtensionUtilityNcMakerNet.dll", "unload_mode": "umManuallyFromUI", "extensions": [ { "utility": { "name": "Generate G code by C#", "caption": "Generate G code by C# (version 2)", "id": "Extension.Utility.NcMaker.Net" } } ] } - Add unload mode
- Archive json and dll files into file with
*.dextextension; - Execute created
*.dextfile - it will be added to main application. Library will be overwritten, because it was unloaded. Otherwise, you will encounter an error. - In SprutCAM open utilities menu - there should be item, called
Generate G code by C# (version 2). This means that with the previous action, you successfully updated the extension - now it has new caption. - Press
Generate G code by C# (version 2)and close notepad with opened results. - Now try to execute early created
*.dextextension. You'll get an errorAccess to the path 'ExtensionUtilityNcMakerNet.dll' is denied. This means that the extension was not unloaded from memory - as it should be, since we specified the unload method asumManuallyFromUI. - But we still can unload it from UI:
- Open
Settings->Extensions; - Choose
Generate G code by C#(here is value fromnamefield insettings.json); - Click
unload- if the library unloads successfully, theunloadbutton will become inactive, otherwise, you will encounter an error.
- Open
- Now execute early created
*.dextextension - you will succeed, because extension was manually unloaded from memory;
- Modify
- Don't close SprutCAM and add extension in the third time:
- Modify
bin/debug/ExtensionUtilityNcMakerNet.settings.json:- Add unload mode
umBeforeProgramFinalization; - Change caption;
{ "name": "Extension on C# to generate G code", "description": "Extension on C# to generate G code", "module_path": "${extensionJsonFolder}/ExtensionUtilityNcMakerNet.dll", "unload_mode": "umBeforeProgramFinalization", "extensions": [ { "utility": { "name": "Generate G code by C#", "caption": "Generate G code by C# (version 3)", "id": "Extension.Utility.NcMaker.Net" } } ] } - Add unload mode
- Archive json and dll files into file with
*.dextextension; - Execute created
*.dextfile - it will be added to main application. - In SprutCAM open utilities menu - there should be item, called
Generate G code by C# (version 3). This means that with the previous action, you successfully updated the extension - now it has new caption. - Press
Generate G code by C# (version 2)and close notepad with opened results. - Try to execute early created
*.dextextension. You'll get an errorAccess to the path 'ExtensionUtilityNcMakerNet.dll' is denied. - Check unloading manually from UI:
- Open
Settings->Extensions; - Choose
Generate G code by C#(here is value fromnamefield insettings.json); - Ensure that the
unloadbutton is inactive. You can't unload it, because ofumBeforeProgramFinalization.
- Open
- Modify
- Now you can close SprutCAM and execute created
*.dext- the library was unloaded from memory when SprutCAM closed.