Plugin documentation?

Les, I was wondering if there was any documentation on (attempting :wink: ) to create user plugins?

:unamused:
{Famous last words… How complicated can it be… } :laughing:

Unfortunately there isn’t much. What do you want to do and how much programming experience do you have?

Les

Hi Les, I’ve been mainly curious, occasionally there is something I want to have a go at trying (uccnc export directly plugin (similar to the mach3 one))

I am not a programmer, pcs are a non paying hobby (as is CNC), I’ve done bits of programming with c, c++ (Arduino processing), c# (uccnc, macros and plugins), Lua (sheetcam mach4), visual basic , cypress VB (mach3), and bits with Linux , raspberry pi, linuxcnc etc

Never done basic, Fortran or assembly, not likely to either…

I dabble,

paid job as consulting engineer

There are two types of plugin. Lua plugins have access to most of SheetCam’s internal data and have some documentation. C++ plugins have access to pretty much everything but are difficult to set up and have very little documentation.

The Mach plugin uses a mix of Lua and C++, mainly because the Mach communication was easier in C++. You should be able to do what you want with a mix of Lua on SheetCam’s end C# on the UCCNC end. The worst bit will be the inter process communication. Probably sockets would be the easiest route. SheetCam comes with wxLua http://wxlua.sourceforge.net/ so you have access to all of the functionality in wxWidgets https://www.wxwidgets.org/. If you look in SheetCam’s installation directory you should find a folder called SDK. The .i files in there are wxLua interface files and they describe teh SheetCam internal classes that are available to Lua.

I have been working on a sort of universal version of the Mach plugin that will be able to work with a range of controllers including LinuxCNC, Mach and pretty much any other controller that can has a C++ compatible API. It comes as two parts - a server that runs as a plugin for the controller and a client that runs in SheetCam. The communications and server side uses a permissive open source license and can be seen here https://github.com/sheetcam/CNCRemote. This is a bit of a side project so development is pretty slow at the moment. The LinuxCNC server is the most complete example of a server at the moment.

I would like to develop a plugin that replaces the tool choice in the operation dialog with three choices. Material thickness and material type and from this calculate the kerf with. All the other calculations like feed rate, pierce height, cut height etc I can calculate in the post processor.
Is this at all possible and is it possible to do in lua? I can’t find any good starting point among the current plugins and I can’t download any of the contributed posts in this forum.

I did think about resurrecting this thread and ask about having a look at some / and plugin documentation you may have Les.

I’ve been playing with the idea of creating something similar to tubefit … At the moment I was going to do it via uccnc Wizard

You can’t remove the tool dropdown but you coud do the rest by using custom tool variables. post.DefineCustomToolParam also works for operations so for instance you could use something like this to define a material thickness option:
post.DefineCustomToolParam(“JetOperation”, “Material thickness”, “thickness”, sc.unitLINEAR, 6, 0.5, 50)
For material thickness you could use the material thickness defined in job options. This is available to the post as the variable materialThick.

Les

Yes, I finally got the post.DefineCustomToolParam to work so the plugin isn’t that urgent anymore. But the purpose with it was to be able to just fill in the thickness and material type instead of creating numerous of tools. 4 different materials and 10 different thickness and some different nozzles on top of that may give you over 80 tools. That seems just confusing to me, so therefore I were thinking over this plugin. The tool dropdown does not need to disappear. It would be great to chose nozzle from.

I have done some work to develop a plugin that calculates the kerf with, best feed and the THC voltage setting depending on nozzle and material. The last problem is to pass the calculated voltage to the post processor. I have a CustomToolParam defined in the post for voltage but I can’t find a way to set it from the plugin. Is there a way to save to a application wide custom variable that is accessible from both the plugin and the post processor?

/Björn

You can access the tool table from a plugin or the post

   local tools = sc.Parts:Get().tools
   local tl = tools:GetTool(tool) --tool is the tool number. Will return nil if that tool is not found
   if(tl) then
      local val = tl:GetValue("Preset volts") --will return nil if 'Preset volts' is not found
      if(val) then
         local volts = val:GetValueString() --If you want more than just the value as a string, convert to a FloatValue first (see below)
         post.Text(">>>>>volts = ", volts)
      end
   end

If you want to iterate through the tool set:

   local tools = sc.Parts:Get().tools
   for idx=0,tools:GetCount()-1 do
      local tl = tools:op_index(idx) --Get tool by index rather than by number
      local val = tl:GetValue("Preset volts")
      if(val) then
         volts = val:DynamicCast("FloatValue")  --val is a ValueBase which isn't that useful so convert to FloatValue
         if(volts) then --volts will be nil if volts isn't a FloatValue so we should check
            local v = volts:op_get()
            v = v + 1
            volts:op_set(v) --increment volts by 1
         end
      end
   end

Thank you.

The code I needed was:

local val = tool:GetValue("Preset volts")

And the next question is…
Is there a way to edit the operations default leadin length? I see there is a defaultStart parameter in the operation instance. Is this some kind of pointer to default start point settings and in that case how to edit?

/Björn

Yes, defaultStart contains the operation’s start point parameters. Take a look at startpoint.i for more info. leadin and leadout are the leadin and leadout lengths.
The lead in/out type can be one of:
sc.LEAD_NONE,
sc.LEAD_ARC,
sc.LEAD_TANGENT,
sc.LEAD_PERP
After changing the start point you need to trigger a path rebuild:

operation:SetDirty(sc.DIRTY_OFFSET)

Ok.

But how do I get the StartPoint instance from the StartValue instance?
This code

myOperation.defaultStart:GetValueString()

gives me “ERROR”
And the part about StartValue in operations.i gives me no obvious hint.
Should I use the Load method? How?

Thank you.

startValue is a StartPoint instance

myOperation.defaultStart.leadin = 10 --set leadin length to 10mm

You don’t need to mess around with casting StartPoint values. It is needed for tool and operation parameters because they can be customized.

Thanks a lot. I was so sure I had tried just that and I got an error there was no such attribute in a StartValue instance.
Well now it works. Thanks again. Maybe thera going to be some more questions soon.

It’s when I ask for the value before I set it I got the error

leadin = operation.defaultStart.leadin

“Unable to call an unknown method ‘leadin’ on a ‘StartValue’ type.”

I just checked the code and I made a mistake in the .i file, which is why that doesn’t work. This will be fixed in the next dev release.

operation.defaultStart.leadin = 10

This doesn’t throw an error but it doesn’t seem to change the operation settings either. Is it because of the this .i file mistake too or do I miss something else.

Yeah. Lua doesn’t know a StartValue is a descendant of StartPoint. However this may work:

local st = operation.defaultStart:DynamicCast("StartPoint")
local leadin = st.leadin

Although Lua doesn’t know about the relationship, C++ does. DynamicCast is implemented in C++ so this may well work.