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?




\

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?




\

But how to access this variable?

adding somthing like

circtrans = 360/(diameter*math.pi)

or

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

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

post.DefineVariable("diameter",sc.unitLINEAR,0,10)

Yes

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

LinuxCNC_XZA.scpost (4.65 KB)

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

 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

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.

Hmm that gives me nearly the same error message:

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

LinuxCNC_XZA.scpost (4.61 KB)

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.

   if diameter then
      circtrans = 360/(diameter*math.pi)
   else
      post.Error("You need to define the diameter!")
   end

Thanks that’s it!