DefineVariable in Post Processor
DefineVariable in Post Processor
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?
------------------------------------
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?
------------------------------------
DefineVariable in Post Processor
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?
------------------------------------
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?
------------------------------------
Re: DefineVariable in Post Processor
But how to access this variable?
adding somthing like
or
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
adding somthing like
Code: Select all
circtrans = 360/(diameter*math.pi)
Code: Select all
circtrans = 360/(var.diameter*math.pi)
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
- Les Newell
- Site Admin
- Posts: 3679
- Joined: Thu May 11, 2006 8:12 pm
Re: DefineVariable in Post Processor
Did you define the variable using post.DefineVariable? For example:
Code: Select all
post.DefineVariable("diameter",sc.unitLINEAR,0,10)
Re: DefineVariable in Post Processor
YesLes 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)
- Les Newell
- Site Admin
- Posts: 3679
- Joined: Thu May 11, 2006 8:12 pm
Re: DefineVariable in Post Processor
It should work then. Could you send me a copy of your post.
- Les Newell
- Site Admin
- Posts: 3679
- Joined: Thu May 11, 2006 8:12 pm
Re: DefineVariable in Post Processor
You are running into a sequencing issue. Code ouside of a function is run once when the post is loaded. For instance you have
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 in function OnNewOperation(). While you are at it, take out the feed and plunge rate warnings. Your set post variable operation will trigger them.
Code: Select all
post.DefineVariable("diameter", sc.unitLINEAR, 0, 100)
circtrans = 360/(diameter*math.pi)
Code: Select all
circtrans = 360/(diameter*math.pi)
Re: DefineVariable in Post Processor
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 376 times
- Les Newell
- Site Admin
- Posts: 3679
- Joined: Thu May 11, 2006 8:12 pm
Re: DefineVariable in Post Processor
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.
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
Re: DefineVariable in Post Processor
Thanks that's it!