DefineVariable in Post Processor

Posts redirected from the Yahoo mailing list
Post Reply
jnvines

DefineVariable in Post Processor

Post by jnvines »

I'm having some difficulty getting DefineVariable to work.

My post processor looks something like this:

DefineVariable("myVar",sc.unitLINEAR,0,10)

function OnInit()
....

//to the end of file

When I save the file it says:
This post has thrown an error:
Lua: Error while running chunk..... global 'DefineVariable' (a nil value)


What am I doing wrong here?





------------------------------------
Les Newell

DefineVariable in Post Processor

Post by Les Newell »

You need:
post.DefineVariable("myVar",sc.unitLINEAR,0,10)

Les

On 04/10/11 15:23, jnvines wrote:
[quote]I'm having some difficulty getting DefineVariable to work.

My post processor looks something like this:

DefineVariable("myVar",sc.unitLINEAR,0,10)

function OnInit()
....

//to the end of file

When I save the file it says:
This post has thrown an error:
Lua: Error while running chunk..... global 'DefineVariable' (a nil value)


What am I doing wrong here?





------------------------------------
hans
Posts: 114
Joined: Sun Feb 02, 2020 8:26 pm

Re: DefineVariable in Post Processor

Post by hans »

But how to access this variable?

adding somthing like

Code: Select all

circtrans = 360/(diameter*math.pi)
or

Code: Select all

circtrans = 360/(var.diameter*math.pi)
either in function OnInit() or outside a function
gives me the error:

An unexpected error has occurred:
..LinuxCNC_XZA.scpost:43: attempt to perform arithmetic on global 'diameter' (a nil value)
Post processing failed
User avatar
Les Newell
Site Admin
Posts: 3661
Joined: Thu May 11, 2006 8:12 pm

Re: DefineVariable in Post Processor

Post by Les Newell »

Did you define the variable using post.DefineVariable? For example:

Code: Select all

post.DefineVariable("diameter",sc.unitLINEAR,0,10)
hans
Posts: 114
Joined: Sun Feb 02, 2020 8:26 pm

Re: DefineVariable in Post Processor

Post by hans »

Les Newell wrote: Sun Jan 03, 2021 5:30 pm Did you define the variable using post.DefineVariable? For example:

Code: Select all

post.DefineVariable("diameter",sc.unitLINEAR,0,10)
Yes
User avatar
Les Newell
Site Admin
Posts: 3661
Joined: Thu May 11, 2006 8:12 pm

Re: DefineVariable in Post Processor

Post by Les Newell »

It should work then. Could you send me a copy of your post.
hans
Posts: 114
Joined: Sun Feb 02, 2020 8:26 pm

Re: DefineVariable in Post Processor

Post by hans »

LinuxCNC_XZA.scpost
(4.65 KiB) Downloaded 189 times
User avatar
Les Newell
Site Admin
Posts: 3661
Joined: Thu May 11, 2006 8:12 pm

Re: DefineVariable in Post Processor

Post by Les Newell »

You are running into a sequencing issue. Code ouside of a function is run once when the post is loaded. For instance you have

Code: Select all

 post.DefineVariable("diameter", sc.unitLINEAR, 0, 100)
circtrans = 360/(diameter*math.pi)
This defines the 'diameter' variable correctly but then immediately tries to do something with the value, before it has been set. The variable 'diameter' will only become valid after your 'Set post variable' opertion has been executed. Try putting the line

Code: Select all

circtrans = 360/(diameter*math.pi)
in function OnNewOperation(). While you are at it, take out the feed and plunge rate warnings. Your set post variable operation will trigger them.
hans
Posts: 114
Joined: Sun Feb 02, 2020 8:26 pm

Re: DefineVariable in Post Processor

Post by hans »

Hmm that gives me nearly the same error message:

Code: Select all

Set variable diameter = 100 mm
An unexpected error has occurred:
...home/hans/.SheetCamTNG-dev/posts/LinuxCNC_XZA.scpost:109: attempt to perform arithmetic on global 'diameter' (a nil value)
Post processing failed
Attachments
LinuxCNC_XZA.scpost
(4.61 KiB) Downloaded 180 times
User avatar
Les Newell
Site Admin
Posts: 3661
Joined: Thu May 11, 2006 8:12 pm

Re: DefineVariable in Post Processor

Post by Les Newell »

Sorry, I didn't think it through fully. OnNewOperation is called before the operation is executed so it checks for diameter just before diameter is set.
Thinking about it, the safest thing to do is put it in OnRapid. It won't try to move until the first operation that uses a tool.

Code: Select all

   if diameter then
      circtrans = 360/(diameter*math.pi)
   else
      post.Error("You need to define the diameter!")
   end
hans
Posts: 114
Joined: Sun Feb 02, 2020 8:26 pm

Re: DefineVariable in Post Processor

Post by hans »

Thanks that's it!
Post Reply