Hello Guest it is October 16, 2019, 08:47:20 AM

Author Topic: Modifying an old Mach3 macro to engrave sequential serial numbers  (Read 1140 times)

0 Members and 1 Guest are viewing this topic.

I have a little project where I need to engrave serial numbers on about 200 pieces. I found this old post in another area of the forum and this macro sort of does the trick.  I started to modify it to get it to work the way I wanted but ran into trouble with some of the deprecated commands. It would be pretty helpful if I could get it to work as I can call the macro as part of a larger program to get the serial number on the part.

The macro is attempting to set each of these variables to the current X and Y axis DRO readouts. This doesn't work and I think the 'getdro' command is obsolete. Plus I think the syntax is wrong anyway.
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

Here is the original topic:
https://www.machsupport.com/forum/index.php/topic,11018.0.html

What I really need help with is what is the proper syntax to define a new variable, then set the variable to the current X axis DRO (and similar for the Y axis)? I played with the getOEMdro() command but I don't understand the syntax and how you would turn that dro reading into something that can be used as an integer. I'm not much of a programmer so the syntax and logic is a bit tough for me to figure out. I'd greatly appreciate any advice or alternative options!

 
Code: [Select]
It wil start off by engraving       S/N:     then adds the serial number    IE:    S/N: 090300001  ,  next run  S/N: 090300002 , ETC


CODE EXAMPLE:
' Macro for consecutive S/N engraving from MACH

Sub main
Dim A As String
Dim Ch As String
Dim Cnt As Integer
SetVar(1303 , .250)  'LetterSpacing
Setvar(1300 , -0.005) ' Z Depth cutting
Setvar(1200 , 0.050) ' Safe Z
'CPx= Getoemdro(0)
'CPy= Getoemdro(1)
SETIJMODE(1)
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "S"
Code "g90 G0  Z#1200 X[#1301 + .2250] Y#1302 "
code "G91G0 x -.0706"
code " y-.0449"
code "G90 G1Z#1300 F20."
code "g91 g1X.0159Y-.0361I.05J.0004"
code "X.0375Y-.0151I.0377J.0395"
code "G1X.0348"
code "G3X.0373Y.0151I-.0001J.0539"
code "X.0157Y.0361I-.0346J.0365"
code "X-.016Y.0383I-.0551J-.0004"
code "X-.037Y.0164I-.0378J-.0356"
code "G1X-.0352"
code "G2X-.0373Y.0157I.0003J.0528"
code "X-.0157Y.0372I.0371J.0376"
code "X.0157Y.0374I.0535J-.0004"
code "X.0373Y.016I.0377J-.0365"
code "G1X.0706"
code "G90 G0Z[#1200]"
Code "G0 Z#1200 X[#1301 + .2250] Y#1302 "

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "/"
Code "G0 Z#1200 X[#1301 + .2250] Y#1302 "
code "G91G0X.0357Y.1071"
code "G90 G1Z#1300 F20."
code "G91 g1X-.1071Y-.2142"
code "G90 G0Z[#1200]"
Code "G0  Z#1200 X[#1301 + .2250] Y#1302 "

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend 
 
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "N"
Code "G90  g0 X[#1301 + .2250] Y#1302 "
code "G91G0X-.0706 Y-.1078"
code "G90 G1Z#1300 F20."
code "G91 g1y.2156"
code "x.1412 Y-.2156" 
code "y.2156"
code "G90 G0 Z#1200"
Code "G0 Z#1200X[#1301 + .2250] Y#1302"

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message ":"
Code "G90  g0 X[#1301 + .2250] Y#1302 "
code "G91G0y-.0559"
code "G90 G1Z[#1300 -.010] F20."
Code "Z#1200"
code "G91 Y.1118"
code "G90 G1Z[#1300 -.010] F20."
Code "Z#1200"
Code "G0 Z#1200X[#1301 + .2250] Y#1302"

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend


P10= GetOEMDRO(1050)
A=Str(P10)
For Cnt=1 To Len(A)
  Ch=Mid(A,Cnt,1)
  Select Case Ch
    Case "0" ZERO
    Case "1" ONE
    Case "2" TWO
    Case "3" THREE
    Case "4" FOUR
    Case "5" FIVE
    Case "6" SIX
    Case "7" SEVEN
    Case "8" EIGHT
    Case "9" NINE
  End Select
Next
P10=P10+1
SetOEMDRO(1050,P10)
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))
SETIJMODE(1)
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend   

End Sub

Sub ZERO
message "Zero"
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

Code " G0 X[#1301 + .2250] Y#1302 "
code "G90 G0 z#1200"
code "G91 G0 X-.0004Y.1076"
code "G90 G1 Z#1300 F20."
code "G91 G1X.0176 "
code "G2X.0374Y-.0194I-.0021J-.05"
code "X.0164Y-.0417I-.0488J-.0432"
code "G1X-.0009Y-.1012"
code "G2X-.0157Y-.0372I-.0527J.0004"
code "X-.0372Y-.0157I-.0375J.0371"
code "G1X-.0353"
code "G2X-.0372Y.0157I.0004J.0528"
code "X-.0157Y.0372I.0371J.0376"
code "G1Y.1059"
code "G2X.0157Y.0389I.0585J-.001"
code "X.0372Y.0175I.0382J-.033"
code "G1X.0177 "
Code "G90 Z#1200"
Code "G0 Z#1200X[#1301 + .2250] Y#1302"

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend
End Sub

Sub ONE
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "One"
Code "G90  g0 X[#1301 + .2250] Y#1302 "
code "G91G0X-.0359Y.0719"
code "G90 G1Z#1300 F20."
code "G91 X.0357Y.0361"
code "Y-.2156"
code "X-.0357"
code "X.0718"
code "G90 G0 Z#1200"
Code "G0 Z#1200X[#1301 + .2250] Y#1302"

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend
End Sub

Sub TWO
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "Two"
Code "G90 G0 Z#1200 X[#1301 + .2250] Y#1302 "
code "G91G0X-.071Y.0531 "
code "G90 G1Z#1300 F20. "
code "G91 G2X.0157Y.0375I.0535J-.0004 "
code "X.0377Y.0159I.0379J-.0371"
code "G1X.0352 "
code "G2X.0375Y-.0159I-.0005J-.0531 "
code "X.0159Y-.0375I-.0373J-.038 "
code "X-.0164Y-.0383I-.0527J-.0001"
code "G1X-.1256Y-.1213"
code "X.142"
code "G90 G0Z#1200"
Code "G0 Z#1200 X[#1301 + .2250] Y#1302 "

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend   
End Sub

Sub THREE
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "Three"

code "g90 G0 Z#1200 X[#1301 + .2250] Y[#1302 ]"
code "G91G0X-.0605Y.0917"
code "G90 G1Z#1300 F20."
code "G91 G2X.0362Y.0159I.0366J-.0341"
code "G1X.034"
code "G2X.0357Y-.0159I-.0006J-.0494"
code "X.0151Y-.0379I-.04J-.0379"
code "X-.0151Y-.0379I-.0552 "
code "X-.0357Y-.0159I-.0363J.0335"
code "X.0357Y-.0159I-.0006J-.0494"
code "X.0151Y-.0379I-.04J-.0379"
code "X-.0151Y-.0374I-.0546J.0002 "
code "X-.0357Y-.0159I-.0363J.0335"
code "G1X-.034 "
code "G2X-.0362Y.0154I.0002J.0505 "
code "G90 G0Z[#1200]"
Code "G0 Z#1200X[#1301 + .2250] Y#1302"

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend 
End Sub

Sub FOUR
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "Four"
Code "g90 G0 Z#1200 X[#1301 + .2250] Y#1302 "
code "G91G0X.0353Y-.1059"
code "G90 G1Z#1300 F20."
code "G91 Y.2117"
code "X-.1059Y-.1411"
code "X.1412"
code "G90 G0Z#1200"
Code "G0  Z#1200 X[#1301 + .2250] Y#1302 "

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend   
End Sub

Sub FIVE
 Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "Five"
Code "G90 G0  Z#1200 X[#1301 + .2250] Y#1302 "
code "G91G0X.0714Y.1071"
code "G90 G1Z#1300 F20."
code "G91 X-.1428"
code " Y-.0714"
code "X.0895"
code "G2X.0374Y-.0159I-.0005J-.0531"
code "X.0159Y-.0374I-.0372J-.0379"
code "G1Y-.0358"
code "G2X-.0159Y-.0378I-.0537J.0003"
code "X-.0374Y-.0159I-.0379J.0372"
code "G1X-.0357"
code "G2X-.0379Y.0159I.0002J.0536"
code "X-.0159Y.0374I.0372J.0379"
code "G90 G0Z#1200"
Code "G0 Z#1200 X[#1301 + .2250] Y#1302 "

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend   
End Sub

Sub SIX

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))


message "Six"
Code "G90 G0 Z#1200 X[#1301 + .2250] Y#1302 "

code "G91G0X.0555Y.091"
code "G90 G1Z#1300 F20."
code "G91 G3X-.0379Y.0155I-.0376J-.038"
code "G1X-.0352"
code "G3X-.0377Y-.0159I.0002J-.053"
code "X-.0157Y-.0375I.0378J-.0379"
code "G1Y-.1062"
code "G3X.0157Y-.0377I.0533J.0001"
code "X.0377Y-.0157I.0378J.0376"
code "G1X.0352"
code "X.0375Y.0157I-.0004J.0535"
code "X.0159Y.0377I-.0371J.0379"
code "G1Y.0352"
code "G3X-.0159Y.0375I-.0531J-.0005"
code "X-.0375Y.0159I-.038J-.0372"
code "G1X-.0352"
code "G3X-.0377Y-.0159I.0002J-.053"
code "X-.0157Y-.0375I.0378J-.0379"
code "G90 G0Z[#1200]"
Code "G0  Z#1200 X[#1301 + .2250] Y#1302 "
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend   
End Sub

Sub SEVEN
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))


message "Seven"
Code "G0 Z#1200 X[#1301 + .2250] Y#1302 "
code "G90 z#1200"
code "G91G0X-.0714Y.1071"
code "G90 G1Z#1300 F20."
code "G91 X.1428"
code "X-.1071Y-.2142"
code "G90 G0Z[#1200]"
Code "G0  Z#1200 X[#1301 + .2250] Y#1302 "

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend   
End Sub

Sub EIGHT

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

message "Eight"
Code "g90 G0  Z#1200 X[#1301 + .2250] Y#1302 "

code "G91G0X0.Y.1061"
code "G90 G1Z#1300 F20."
code "G91 X.0176"
code "G2X.0373Y-.016I-.0004J-.0525"
code "X.0157Y-.0374I-.0378J-.0378"
code "X-.0157Y-.0372I-.0528J.0004"
code "X-.0373Y-.0157I-.0376J.0371"
code "G1X-.0352"
code "G3X-.0373Y-.0164I.0005J-.0519"
code "X-.0157Y-.0383I.0398J-.0386"
code "X.0159Y-.0361I.05J.0004"
code "X.0375Y-.0151I.0377J.0395"
code "G1X.0348"
code "G3X.0373Y.0151I-.0001J.0539"
code "X.0157Y.0361I-.0346J.0365"
code "X-.016Y.0383I-.0551J-.0004"
code "X-.037Y.0164I-.0378J-.0356"
code "G1X-.0352"
code "G2X-.0373Y.0157I.0003J.0528"
code "X-.0157Y.0372I.0371J.0376"
code "X.0157Y.0374I.0535J-.0004"
code "X.0373Y.016I.0377J-.0365"
code "G1X.0176"
code "G90 G0Z[#1200]"
Code "G0 Z#1200 X[#1301 + .2250] Y#1302 "

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend   
End Sub

Sub NINE
Setvar(1301, getdro(0))
Setvar(1302, getdro(1))


message "Nine"
Code "G90 G0  Z#1200 X[#1301 +.2250] Y#1302 "

code "G91G0X-.0555Y-.091"
code "G90 G1Z#1300 F20."
code "G91 G3X.0379Y-.0155I.0376J.038"
code "G1X.0352"
code "G3X.0375Y.0157I-.0004J.0535"
code "X.0159Y.0377I-.0371J.0379"
code "G1Y.1062"
code "G3X-.0159Y.0375I-.0532J-.0005"
code "X-.0375Y.0159I-.038J-.0372"
code "G1X-.0352"
code "G3X-.0377Y-.0159I.0002J-.053"
code "X-.0157Y-.0375I.0378J-.0379"
code "G1Y-.0352"
code "G3X.0157Y-.0377I.0533J.0001"
code "X.0377Y-.0157I.0378J.0376"
code "G1X.0352"
code "G3X.0375Y.0157I-.0004J.0535"
code "X.0159Y.0377I-.0371J.0379"
code "G90 G0Z#1200"
Code "G0  Z#1200 X[#1301 +.2250] Y#1302 "

Setvar(1301, getdro(0))
Setvar(1302, getdro(1))

While IsMoving()
Wend
End Sub

SETIJMODE(0)
CODE"G90"
CODE"M30"               


Offline RICH

*
  • *
  •  7,367 7,367
    • View Profile
Re: Modifying an old Mach3 macro to engrave sequential serial numbers
« Reply #1 on: June 19, 2017, 08:15:28 PM »
helmholtz,

May want to have a look at Page 18 of the Macro Programmers Reference Manual.

      STANDARD DRO'S    OEM DRO'S 
X DRO  0                 800
Y DRO  1                 801

Since the referenced macro in the mach tool box was posted in March 0f 2009 that "MAY" imply that use of dro code in Mach3 release 3.042.021 at the earliest. Only Terry would know more , but he retired from this site.

FWIW,

RICH
Re: Modifying an old Mach3 macro to engrave sequential serial numbers
« Reply #2 on: June 19, 2017, 08:48:47 PM »
Hi Rich,
I did read in the programming manual that it was now recommended to use getOEMdro(). The issue for me was when I updated the macro to something like:

SetVar(1301, getOEMdro(800))

where I expected it to return the current x-axis position into variable #1301 I got nothing. so i figured that I didn't understand the syntax?

with the exception of the use of the old 'getdro' command everything else actually worked and I think it will be a really handy little macro if I can get it working.


helmholtz,

May want to have a look at Page 18 of the Macro Programmers Reference Manual.

      STANDARD DRO'S    OEM DRO'S 
X DRO  0                 800
Y DRO  1                 801

Since the referenced macro in the mach tool box was posted in March 0f 2009 that "MAY" imply that use of dro code in Mach3 release 3.042.021 at the earliest. Only Terry would know more , but he retired from this site.

FWIW,

RICH

Offline RICH

*
  • *
  •  7,367 7,367
    • View Profile
Re: Modifying an old Mach3 macro to engrave sequential serial numbers
« Reply #3 on: June 20, 2017, 08:19:40 AM »
Not the sharpest tack on all this. ;)
I ran the macro as posted and did not change the scripting and it works in version R3.043.062.
I added a user dro 1050 to the screen set so I could define the increment.
Read the original info in the original topic.

Note that the macro needs to be in the macro folder that applies to the screen set.
IE; C:\Mach3\macros\Mach3Mill if your using that screen set.

Click the "Operator" tab at the top of the screen and select "GCode Var Monitor" and in the
flyout, change one of the  input box values to 1301 for the Var Adress and click THE "UPDATE" BUTTON.
The current stored value for the variable will be shown under stored value. If you run the macro you will see the
stored value change while the macro is running.

I did not air run the macro on the mill to see how the actual movements.

FWIW....have fun, :D
RICH
« Last Edit: June 20, 2017, 08:24:15 AM by RICH »
Re: Modifying an old Mach3 macro to engrave sequential serial numbers
« Reply #4 on: June 20, 2017, 09:04:09 AM »
Rich,
when you tried it based on the original info did you run it as just M1500 entered into the command line? When I first started playing with I confirmed that it worked as well. I should have posted that I did get it to work based on the instructions in the original author post.

The issue popped up when I tried to use the macro inside of another program. Say for example you wanted to execute the macro at a position other then G54 X0 Y0 Z0. maybe you wanted the S/N in the middle of your workpiece. When I tried that out on the machine (also running ver .62) it would place the 'S' in the correct (middle) place then return to G54 x0 y0 z0 and run the rest of the program. In the variable monitor I started seeing large integers that didn't make sense when looking at var1301 and var1302.

this led me to believe that the getdro() function was not working as originally intended. Perhaps there is something in the program that I used to call the macro and the macro needs some preample gCode to work well. I'm not sure. But, thanks for taking the time to confirm that you were able to get to work also.

It's no haas G47, but not a bad little program. I may just run it from the MDI and not try and integrate it into a program. I only need to do a 200 parts and this sure beats making 200 CAM files!

I'd still like to re-write the macro to use getoemdro instead of getdro but like I said, that didn't seem to work. thanks again for looking at it.

Offline RICH

*
  • *
  •  7,367 7,367
    • View Profile
Re: Modifying an old Mach3 macro to engrave sequential serial numbers
« Reply #5 on: June 20, 2017, 09:39:21 AM »
Quote
when you tried it based on the original info did you run it as just M1500 entered into the command line?

YES, just to see that the variables were getting set and that it worked so could give you some info.

Never had a need for it as every thing here is a one of a kind, but one never knows what they will need.

The thought came to mind to make a screen for it such that I could have inputs for letter spacing, height,
etc that the macro would use. Additionally to place the text where I wanted it on the piece.
Thus additional coding would be required and  would want it to work in line with how I work / setup.

Don't have much desire to spend time fooling with it.

What more can one say, ;)

RICH