Page 1 of 2

Plugin documentation?

Posted: Sun Sep 02, 2018 12:17 pm
by robertspark
Les, I was wondering if there was any documentation on (attempting ;) ) to create user plugins?

:roll:
{Famous last words.... How complicated can it be.... } :lol:

Re: Plugin documentation?

Posted: Mon Sep 03, 2018 10:50 am
by Les Newell
Unfortunately there isn't much. What do you want to do and how much programming experience do you have?

Les

Re: Plugin documentation?

Posted: Mon Sep 03, 2018 7:19 pm
by robertspark
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

Re: Plugin documentation?

Posted: Tue Sep 04, 2018 1:45 pm
by Les Newell
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.

Re: Plugin documentation?

Posted: Sun Feb 10, 2019 9:38 am
by Jolbas
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.

Re: Plugin documentation?

Posted: Sun Feb 10, 2019 5:29 pm
by robertspark
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

Re: Plugin documentation?

Posted: Mon Feb 11, 2019 12:39 pm
by Les Newell
Jolbas wrote: Sun Feb 10, 2019 9:38 am I would like to develop a plugin that replaces the tool choice in the operation dialog with three choices.
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

Re: Plugin documentation?

Posted: Mon Feb 11, 2019 6:41 pm
by Jolbas
Les Newell wrote: Mon Feb 11, 2019 12:39 pm 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.
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.

Re: Plugin documentation?

Posted: Fri Sep 13, 2019 2:16 pm
by Jolbas
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

Re: Plugin documentation?

Posted: Fri Sep 13, 2019 5:18 pm
by LesNewell
You can access the tool table from a plugin or the post

Code: Select all

   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:

Code: Select all

   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

Re: Plugin documentation?

Posted: Sat Sep 14, 2019 5:07 am
by Jolbas
Thank you.

The code I needed was:

Code: Select all

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

Re: Plugin documentation?

Posted: Sat Sep 14, 2019 8:48 am
by Jolbas
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

Re: Plugin documentation?

Posted: Sat Sep 14, 2019 10:01 am
by Les Newell
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:

Code: Select all

operation:SetDirty(sc.DIRTY_OFFSET)

Re: Plugin documentation?

Posted: Sat Sep 14, 2019 10:40 am
by Jolbas
Ok.

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

Code: Select all

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.

Re: Plugin documentation?

Posted: Sat Sep 14, 2019 10:56 am
by LesNewell
startValue is a StartPoint instance

Code: Select all

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.