Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

first macro program


LEV
 Share

Recommended Posts

Hi!

Can anybody take a look at my first macro program and tell me if it make any sense to you.

 

I need to engrave serial # on my parts.

every four parts need to have the same serial #.

 

here is what I came up with:

 

O0010(MAIN PROGRAM)

………..

 

IF [#501 LE 4] GOTO 1

IF [#501 GE 5] AND [#501 LE 8] GOTO 2

IF [#501 GE 9] AND [#501 LE 12] GOTO 3

IF [#501 GE 13] AND [#501 LE 16] GOTO 4

IF [#501 GE 17] AND [#501 LE 20] GOTO 5

……………..

………..

N1C0.

G54M98P301

/C90.

/G55M98P301

/C180.

/G56M98P301

/C270.

/G57M98P301

GOTO 200

 

N2C0.

G54M98P302

/C90.

/G55M98P302

/C180.

/G56M98P302

/C270.

/G57M98P302

GOTO 200

 

N3C0.

G54M98P303

/C90.

/G55M98P303

/C180.

/G56M98P303

/C270.

/G57M98P303

GOTO 200

 

N4C0.

G54M98P304

/C90.

/G55M98P304

/C180.

/G56M98P304

/C270.

/G57M98P304

GOTO 200

 

N5C0.

G54M98P305

/C90.

/G55M98P305

/C180.

/G56M98P305

/C270.

/G57M98P305

GOTO 200

 

N200 #501 = [#501+4]

……………….

M30

 

O301 (SUB PROGRAM TO ENGRAVE FIRST #)

……

……..

M99

 

O302 (SUB PROGRAM TO ENGRAVE SECOND #)

……

……..

 

M99

 

Thanks in advance.

Link to comment
Share on other sites

Well its been a half a decade, but in a past life I wrote this guy to engrave serial numbers and other such numerical engraving requirements.   Feel free to use it.  I am not 100% on what all of the inputs are, but...  its pretty powerful and ran for about a year engraving julian date, shift, and time info on parts.  So it is pretty well proven.  If you have fixed inputs and it does what you ask, it would save you the need to write sub programs for each place.  Just call as below

 

Looking at this,

 

V is number to engrave ( I was setting this elsewhere in this case)

H is Letter Height

Z is Height of surface to Engrave on.

D is depth of engraving (incremental from above)

E has to do with leading zeros, and this was somewhat finicky if I recall, I think it works, but sometimes blunders, nothing major, just doesn't engrave the right thing try it set to zero if you don't need leading  

F is feedrate

A is G08P1 lookahead (you could change this if you need for your machine)

 

Other Functionality

R is rotation angle if you have G68

 

G65 P9123 V#3 H.125 Z-.025 D-0.005 E2. F45. A1.0

 

The text format is mastercam text, equal width text works best, you can change the text by rewriting the incremental code in sections N0 thru N9 the #30 statement, at the end controls the letter width and spacing between letters.  I think I programmed it as if the letters were .1" tall.  Then it can scale from there safely.

 

I never got around to doing the alphabet, and making it so I could engrave text, I always just posted that out by the job,  I have a date macro that uses this macro and has the month abbreviations set up.  Started tinkering with the framework for doing words and never got the time or need to finish.

 

Good Luck.

% 
O9123(NUMBER ENGRAVING MACRO)
(DEVELOPED BY N. GIBBS)
(9/16/2010)
 
(MACRO SETUP PREP SECTION) 
#30=#5001(STORE ABS X POS) 
#31=#5002(STORE ABS Y POS) 
#32=#4003(STORE ABS-INC) 
#33=#4005(STORE IPR-IPM) 
IF[#3EQ#0]THEN#3=0.05(CHECK FOR CLEARANCE INPUT & DEFAULT) 
IF[#1EQ#0]THEN#1=1.0(CHECK FOR G08 INPUT & DEFUALT)
IF[#26EQ#0]THEN#26=0.0(CHECK FOR Z PLANE INPUT & DEFAULT)
IF[#7EQ#0]THEN#7=0.005(CHECK FOR ENGRAVING DEPTH & DEFAULT)
#7=ABS[#7](FIXING THE DEPTH #7)
IF[#9EQ#0]THEN#9=45.0(CHECK FOR FEEDRATE & DEFAULT)
IF[#11EQ#0]THEN#11=0.1(CHECK FOR FEEDRATE & DEFAULT) 
#11=#11/0.1(MORPH #11 INTO SCALE FACTOR) 
IF[#18EQ#0]THEN#18=0.0(SET COORIDINATE SYSTEM ROTATION DEFAULT)
 
(SAFETY CHECKS)
IF[#22EQ#0]GOTO991(MAKE SURE NUMBER WAS SPECIFIED) 
IF[#7GT0.05]GOTO992(ENGRAVING DEPTH TOO DEEP)
IF[[#3+#7]LT[#7+0.025]]GOTO993(NOT ENOUGH CLEARANCE) 
IF[#5003NE[#26+1.]]GOTO994(SAFE Z START HEIGHT CHECK)
IF[#4008EQ0.0]GOTO995(CHECK FOR TOOL OFFSET) 
(LOOP SETUP) 
#15=#22(PUT #22 INTO #15 FOR USAGE)
#16=#15(SETUP SCRATCH VARIABLE)
#21=0.0(INITIALIZE THE NUMBER OF DIGITS) 
WHILE[#16GE1.]DO1(COUNT NUMBER OF DIGITS)
#16=FIX[#16/10.] 
#21=FIX[#21+1.]
END1 
 
#8=FIX[ABS[#21-#8]]
 
#16=0.(REINITIALIZE #16) 
N50(COORDINATE ROTATION) 
IF[#18EQ#0]GOTO55(SKIP IF OMITTED) 
G68X#30Y#31R#18
N55(NO COORDINATE ROTATION)
 
N100WHILE[#21GT0.0]DO1(MAIN ENGRAVING LOOP)
IF[#8GT0.]GOTO108(LEADING ZEROS BRANCH)
#16=#15
IF[#16LT10.]GOTO109
#17=0.(INITIALIZE CURRENT COUNT OF DIGITS) 
N101WHILE[#16GE10.]DO2(MAKE NUMBER TO ENGRAVE LT TEN)
#16=FIX[#16/10.] 
#17=FIX[#17+1.]
END2 
IF[FIX[#17+1.]NE#21]GOTO111
 
#19=#16(TRANSFER FOR CORRECTION) 
WHILE[#17GT0.]DO2
#19=FIX[#19*10.] 
#17=#17-1. 
END2 
#15=[#15-#19]
GOTO110
 
N108#8=FIX[#8-1.0](DECREMENT NUMBER OF LEADING ZEROS)
#16=0.(SET TO ZERO FOR ENGRAVING)
GOTO#16(BRANCH TO ENGRAVE ZERO)
 
N111(MIDDLE ZEROS) 
#21=FIX[#21-1.](DECREMENT DIGIT COUNTER) 
#16=0.(SET TO ZERO FOR ENGRAVING)
GOTO#16(BRANCH TO ENGRAVE ZERO)
 
N109(SET TO ENGRAVE LAST DIGIT)
IF[#21GE2.]THEN#16=0.0 
#16=FIX[#16] 
IF[#21EQ1.]THEN#15=#16 
N110#21=FIX[#21-1.](DECREMENT DIGIT COUNTER) 
GOTO#16(BRANCH TO ENGRAVING PORTION) 
 
END1 
 
WHILE[#21GT0.0]DO1(ENGRAVE TRAILING ZEROS) 
#21=FIX[#21-1.]
#16=FIX[0.]
GOTO#16
END1 
IF[#18EQ#0]GOTO99
G69
N99
G08P0
G0G90Z[#26+1.0]
#130=#30 
#131=#31 
G#33(REPLACE IPR-IPM)
G#32(REPLACE ABS-INC)
M99
 
 
(TEXT MOTION SECTION)
N0(ENGRAVE NUMBER ZERO)
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[[.0059*#11]+#30]Y[[.0163*#11]+#31] 
Z[#3+#26]
G1Z[#26-#7]F#9 
G91G2Y[.0674*#11]R[.0986*#11]
X[.0467*#11]R[.0248*#11] 
Y[-.0674*#11]R[.0985*#11]
X[-.0467*#11]R[.0247*#11]
G1G90Z[#3+#26] 
#30=#30+[.0586*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
N1(ENGRAVE NUMBER ONE) 
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[0.+#30]Y[[.0857*#11]+#31]
Z[#3+#26]
G1Z[#26-#7]F#9 
G91X[.0143*#11]Y[.0143*#11]
Y[-.1*#11] 
G90Z[#3+#26] 
G91X[-.0143*#11] 
G90Z[#26-#7] 
G91X[.0286*#11]
G1G90Z[#3+#26] 
#30=#30+[.0286*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
N2(ENGRAVE NUMBER TWO) 
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[[.0021*#11]+#30]Y[[.0857*#11]+#31] 
Z[#3+#26]
G1G94Z[#26-#7]F#9
G2G91X[.0248*#11]Y[.0143*#11]R[.0286*#11]
G1X[.0022*#11] 
G2X[.0285*#11]Y[-.0273*#11]R[.0286*#11]
X[-.0073*#11]Y[-.0179*#11]R[.0285*#11] 
X[-.0257*#11]Y[-.0192*#11]R[.2373*#11] 
G3X[-.0246*#11]Y[-.0356*#11]R[.0482*#11] 
G1X[.0598*#11] 
G1G90Z[#3+#26] 
#30=#30+[.0576*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
N3(ENGRAVE NUMBER THREE) 
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[0.+#30]Y[[.0143*#11]+#31]
Z[#3+#26]
G1G94Z[#26-#7]F#9
G3G91X[.0249*#11]Y[-.0143*#11]I[.0249*#11]J[.0145*#11] 
G1X[.0065*#11] 
G3X[.0208*#11]Y[.0078*#11]I0.J[.0315*#11]
X[.0078*#11]Y[.0172*#11]I[-.0151*#11]J[.0172*#11]
X[-.0227*#11]Y[.0251*#11]I[-.0252*#11]J0.
G1X[-.0071*#11]
X[.0071*#11] 
G3X[.0213*#11]Y[.0249*#11]I[-.004*#11]J[.0249*#11] 
X[-.0078*#11]Y[.0172*#11]I[-.0229*#11]J0.
X[-.0208*#11]Y[.0078*#11]I[-.0208*#11]J[-.0237*#11]
G1X[-.0037*#11]
G3X[-.0249*#11]Y[-.0143*#11]I0.J[-.0288*#11] 
G1G90Z[#3+#26] 
#30=#30+[.06*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
N4(ENGRAVE NUMBER FOUR)
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[[.0518*#11]+#30]Y[0.+#31]
Z[#3+#26]
G1G94Z[#26-#7]F#9
G91Y[.1*#11] 
X[-.0518*#11]Y[-.0764*#11] 
X[.0664*#11] 
G1G90Z[#3+#26] 
#30=#30+[.0664*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
N5(ENGRAVE NUMBER FIVE)
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[0.+#30]Y[[.0142*#11]+#31]
Z[#3+#26]
G1G94Z[#26-#7]F#9
G3G91X[.0056*#11]Y[-.0064*#11]R[.0318*#11] 
X[.021*#11]Y[-.0079*#11]R[.0318*#11] 
G1X[.0045*#11] 
G3X[.0272*#11]Y[.0158*#11]R[.0314*#11] 
X[-.0012*#11]Y[.0343*#11]R[.0326*#11]
X[-.0116*#11]Y[.0103*#11]R[.0303*#11]
X[-.0169*#11]Y[.004*#11]R[.0378*#11] 
X[-.0286*#11]Y[-.0086*#11]R[.0461*#11] 
G1Y[.0443*#11] 
X[.0605*#11] 
G1G90Z[#3+#26] 
#30=#30+[.0626*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
N6(ENGRAVE NUMBER SIX) 
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[[.0037*#11]+#30]Y[[.0226*#11]+#31] 
Z[#3+#26]
G1G94Z[#26-#7]F#9
G2G91X[.0578*#11]Y[.014*#11]R[.0297*#11] 
X[-.0006*#11]Y[-.016*#11]R[.0297*#11]
X[-.0572*#11]Y[.002*#11]R[.0297*#11] 
X[.002*#11]Y[.0571*#11]R[.0891*#11]
X[.0542*#11]Y[.0054*#11]R[.0297*#11] 
G1G90Z[#3+#26] 
#30=#30+[.0623*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
N7(ENGRAVE NUMBER SEVEN) 
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[0.+#30]Y[[.1*#11]+#31] 
Z[#3+#26]
G1G94Z[#26-#7]F#9
G91X[.06*#11]
G3X[-.03*#11]Y[-.1*#11]R[.1817*#11]
G1G90Z[#3+#26] 
#30=#30+[.060*#11]+[.02*#11] 
GOTO100(RETURN TO ENGRAVING LOOP)
 
N8(ENGRAVE NUMBER EIGHT) 
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[[.0268*#11]+#30]Y[[.0536*#11]+#31] 
Z[#3+#26]
G1G94Z[#26-#7]F#9
G91X[.0064*#11]
G3X[.0232*#11]Y[.0232*#11]R[.0232*#11] 
X[-.0232*#11]Y[.0232*#11]R[.0232*#11]
G1X[-.0064*#11]
G3X[-.0108*#11]Y[-.0026*#11]R[.0232*#11] 
X[.0108*#11]Y[-.0438*#11]R[.0233*#11]
G1X[.0064*#11] 
G2X[.0268*#11]Y[-.0268*#11]R[.0268*#11]
X[-.0268*#11]Y[-.0268*#11]R[.0268*#11] 
G1X[-.0064*#11]
G2X[-.022*#11]Y[.0115*#11]R[.0268*#11] 
X[.022*#11]Y[.0421*#11]R[.0268*#11]
G1G90Z[#3+#26] 
#30=#30+[.060*#11]+[.02*#11] 
GOTO100(RETURN TO ENGRAVING LOOP)
 
N9(ENGRAVE NUMBER NINE)
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[[.0023*#11]+#30]Y[[.0149*#11]+#31] 
Z[#3+#26]
G1G94Z[#26-#7]F#9
G3G91X[.0542*#11]Y[.0054*#11]R[.0297*#11]
X[.002*#11]Y[.0571*#11]R[.0891*#11]
X[-.0571*#11]Y[.002*#11]R[.0297*#11] 
X[.0566*#11]Y[-.018*#11]R[.0297*#11] 
X[.0005*#11]Y[.016*#11]R[.0297*#11]
G1G90Z[#3+#26] 
#30=#30+[.0623*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
N10(ENGRAVE DECIMAL POINT) 
IF[FIX[#1]EQ0.]GOTO21
G08P01 
N21G0G90X[0.+#30]Y[[.005*#11]+#31] 
Z[#3+#26]
G1G94Z[#26-#7]F#9
G2G91X[.01*#11]R[.005*#11] 
X[-.01*#11]R[.005*#11] 
G1G90Z[#3+#26] 
#30=#30+[.01*#11]+[.02*#11]
GOTO100(RETURN TO ENGRAVING LOOP)
 
 
(ALARMS) 
N991#3000=1(NO NUMBER OR VARIABLE NUMBER SPECIFIED TO ENGRAVE) 
N992#3000=2(ENGRAVING DEPTH TOO DEEP)
N993#3000=3(NOT ENOUGH CLEARANCE)
N994#3000=4(NOT AT SAFE Z START HEIGHT - POSITION TOOL 1" ABOVE PART)
N995#3000=5(NO TOOL HEIGHT OFFSET CALLED UP) 
%
Link to comment
Share on other sites

 

 

 

H is Letter Height

(MACRO SETUP PREP SECTION) 
IF[#11EQ#0]THEN#11=0.1(CHECK FOR FEEDRATE & DEFAULT) 

Looks good, but the comment on the line quoted above should read (CHECK FOR LETTER HEIGHT & DEFAULT).

 

 

Umm yeah, didn't notice that.   Just a comment.... Will revise....  Copy and paste while writing code, oh my.  Comments are not my strong suit.  Usually once I have something that functions, all else goes out the window.  :cheers:

Link to comment
Share on other sites

I've done a couple different serialization routine, but never set it up so any one of the numbers repeats. I've used this code to skip portions of a toolpath that only had to run every so many parts. #500 is the frequency I want to run this path (so I want it every fourth part)

 

#500=4.
#103=1.
#501=#501+#103
IF[#501LT#500]GOTO100

 

which I put in front of the section I want to skip. Then after the section that I want to skip I put this;

 

#501=0.
N100G0Z.1M9

 

code in to reset the counter. Shouldn't take much to alter it to do what you want. Basically you'd use this to skip you counter/ increment routine. I have 1 machine that I had to get a little fancy with because it was moving before it would complete the math for the start point of the next number and it would engrave on an upward slope. Not good. I also have an engraving macro where you can insert the height of the numbers you want and it would automatically scale up or down (mostly down because my default value size was 1") amongst other things but I never got enough time on a machine to prove it out 100%. Ir ran through a simulator ok, but that's no guarantee.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...