Plugin documentation?

Request and discuss new features
robertspark
Posts: 117
Joined: Thu Feb 26, 2015 12:11 am
Location: nr Liverpool, England

Plugin documentation?

Post by robertspark » Sun Sep 02, 2018 12:17 pm

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:
Rob

User avatar
Les Newell
Site Admin
Posts: 2280
Joined: Thu May 11, 2006 8:12 pm

Re: Plugin documentation?

Post by Les Newell » Mon Sep 03, 2018 10:50 am

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

Les

robertspark
Posts: 117
Joined: Thu Feb 26, 2015 12:11 am
Location: nr Liverpool, England

Re: Plugin documentation?

Post by robertspark » Mon Sep 03, 2018 7:19 pm

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
Rob

User avatar
Les Newell
Site Admin
Posts: 2280
Joined: Thu May 11, 2006 8:12 pm

Re: Plugin documentation?

Post by Les Newell » Tue Sep 04, 2018 1:45 pm

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.

Jolbas
Posts: 21
Joined: Sat Feb 02, 2019 8:59 am

Re: Plugin documentation?

Post by Jolbas » 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. 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.

robertspark
Posts: 117
Joined: Thu Feb 26, 2015 12:11 am
Location: nr Liverpool, England

Re: Plugin documentation?

Post by robertspark » Sun Feb 10, 2019 5:29 pm

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
Rob

User avatar
Les Newell
Site Admin
Posts: 2280
Joined: Thu May 11, 2006 8:12 pm

Re: Plugin documentation?

Post by Les Newell » Mon Feb 11, 2019 12:39 pm

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

Jolbas
Posts: 21
Joined: Sat Feb 02, 2019 8:59 am

Re: Plugin documentation?

Post by Jolbas » Mon Feb 11, 2019 6:41 pm

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.

Jolbas
Posts: 21
Joined: Sat Feb 02, 2019 8:59 am

Re: Plugin documentation?

Post by Jolbas » Fri Sep 13, 2019 2:16 pm

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

LesNewell
Posts: 904
Joined: Sat May 13, 2006 2:34 pm

Re: Plugin documentation?

Post by LesNewell » Fri Sep 13, 2019 5:18 pm

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

Jolbas
Posts: 21
Joined: Sat Feb 02, 2019 8:59 am

Re: Plugin documentation?

Post by Jolbas » Sat Sep 14, 2019 5:07 am

Thank you.

The code I needed was:

Code: Select all

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

Jolbas
Posts: 21
Joined: Sat Feb 02, 2019 8:59 am

Re: Plugin documentation?

Post by Jolbas » Sat Sep 14, 2019 8:48 am

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

User avatar
Les Newell
Site Admin
Posts: 2280
Joined: Thu May 11, 2006 8:12 pm

Re: Plugin documentation?

Post by Les Newell » Sat Sep 14, 2019 10:01 am

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)

Jolbas
Posts: 21
Joined: Sat Feb 02, 2019 8:59 am

Re: Plugin documentation?

Post by Jolbas » Sat Sep 14, 2019 10:40 am

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.

LesNewell
Posts: 904
Joined: Sat May 13, 2006 2:34 pm

Re: Plugin documentation?

Post by LesNewell » Sat Sep 14, 2019 10:56 am

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.

Post Reply