DefineVariable in Post Processor

Posts redirected from the Yahoo mailing list
Post Reply
jnvines

DefineVariable in Post Processor

Post by jnvines » Tue Oct 04, 2011 10:11 pm

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 » Wed Oct 05, 2011 7:49 am

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

Les

On 04/10/11 15:23, jnvines wrote:
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: 30
Joined: Sun Feb 02, 2020 8:26 pm

Re: DefineVariable in Post Processor

Post by hans » Sun Jan 03, 2021 4:01 pm

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: 2789
Joined: Thu May 11, 2006 8:12 pm

Re: DefineVariable in Post Processor

Post by Les Newell » 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)

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

Re: DefineVariable in Post Processor

Post by hans » Thu Jan 07, 2021 9:42 am

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: 2789
Joined: Thu May 11, 2006 8:12 pm

Re: DefineVariable in Post Processor

Post by Les Newell » Thu Jan 07, 2021 3:37 pm

It should work then. Could you send me a copy of your post.

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

Re: DefineVariable in Post Processor

Post by hans » Fri Jan 08, 2021 9:50 pm

LinuxCNC_XZA.scpost
(4.65 KiB) Downloaded 4 times

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

Re: DefineVariable in Post Processor

Post by Les Newell » Sat Jan 09, 2021 11:19 am

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: 30
Joined: Sun Feb 02, 2020 8:26 pm

Re: DefineVariable in Post Processor

Post by hans » Sat Jan 09, 2021 2:18 pm

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 4 times

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

Re: DefineVariable in Post Processor

Post by Les Newell » Sat Jan 09, 2021 2:51 pm

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: 30
Joined: Sun Feb 02, 2020 8:26 pm

Re: DefineVariable in Post Processor

Post by hans » Sat Jan 09, 2021 3:17 pm

Thanks that's it!

Post Reply