Hello Guest it is December 06, 2019, 09:25:00 PM

Author Topic: VBscripting Macro with Expressions Variables and Operators for Dummies  (Read 1320 times)

0 Members and 1 Guest are viewing this topic.

  Trying to wrap my mind around a condition while teaching myself VBScripting. Never had much trouble with the easier languages like LUA. I have no sense about VBS currently. Usually can find an example, but haven't had much luck looking into the guts of this type of macro. The normal functions are simple and go well, "DoTHIS, GetTHAT". Anything past this is unworkable with my experience. I've been using Mach for nearly a decade without needing more than simple macros, but figured I'd take it for a spin and try to hit the gas, right into a ditch! Any insight is welcome.

My example expression to achieve functions as follows:


  To subtract the next axis movement  from the current axis position

        "ex. NextZ-CurrentZ. *Produce the increment*

IF the difference is greater than

(ex. IF NextZ - CurrentZ > +1.234)

THEN

      Subtract (1.234) and Replace new value of Z axis in DRO while program running.



Is there a good example available (with Headers)? I use this expression quite a bit in my post processors. I'd like to make macros also if possible.

Currently so far down the rabbit hole you can call me Alice.

Thanks

Re: VBscripting Macro with Expressions Variables and Operators for Dummies
« Reply #1 on: December 01, 2016, 02:51:24 AM »
Hi steelroot,
I have real problems with LUA and less so with VB.

In a Gcode program you cant use instructions like getOEMDRO(802) as such an instruction
is VB and needs to be compiled before it will run but you can use pound variables like #99802.
I used these as an example but they relate to your question.

OEMDRO(802) is the current Z axis DRO and #99802 is exactly the same.
So if you wish to subtract from the Z DRO in Gcode:
#99802=[#99802-1.234]
Section 10 of Mach3Mill_1.84.pdf from the Artsoft website tells how pound variables work
and names a few of them...there are 10,000 of them!

Unfortunately you can't use conditionals in Gcode. Pound variables are useful but wont
in themselves solve your problem.

If I understand your question correctly you want to calculate the difference in the current
Z DRO with the next programmed Z axis move. Mach hasn't read that line yet so unless it
reads ahead until it finds a new Z instruction how can it do as you want?

If you wait until Mach reads the line with the next Z move the move is committed to the buffer before
the next line, your conditional, is read and executed. I dearsay it is possible to intervene between the
interpreter and the motion control but that is internal to Mach and I have no idea how to go about it.

The only alternative as I see it is to have a macro that reads your Gcode line by line until it finds your next
anticipated Z move. There are some useful string functions in VB which should make it possible. I have a macro
for instance that does a correction on the X axis of a large Gcode file. It achieves it by reading a line, indentifying
the next X coord if there is one, extract the string value of X move, apply an arithmetic correction, reassemble
the line as a string and outputting that line to a new or 'Corrected' file.

For this idea to work would depend on the regularity of you Gcode. If for instance you can safely assume that
a Z coord is on every line then you only need to read one line ahead. If not, and a lot of my Gcode files are this
way, many intervening lines of XY moves before the next Z move then you have a lot more reading ahead to do.
Also you would have to decide whether G0 moves or in fact any other Gcode Z moves like helical interpolation should
be included in your conditional.

If the idea sound workable to you let me know and I can write some code fragments that might help.

Craig



My wife left with my best friend...
     and I miss him!