Hello Guest it is March 28, 2024, 06:24:59 AM

Author Topic: Macro or wizard for incrementing number?  (Read 7486 times)

0 Members and 1 Guest are viewing this topic.

Macro or wizard for incrementing number?
« on: March 13, 2008, 11:40:07 AM »
I was wondering if there was any way to create in Mach a macro or canned cycle or wizard to generate an incremental lot or serial number to be engraved on a part as a machining cycle is completed. There is some dedicated software capable of doing it, 2Linc, CNCWrite, Millwrite but these would not interface with the normal CAD/CAM software. I know Haas has a canned cycle capable of doing it. Suggestions, solutions?
Re: Macro or wizard for incrementing number?
« Reply #1 on: March 13, 2008, 05:26:48 PM »
Hi,
Interestingly, a friend who has a pantographic engraving machine told me that they are still used in industry for engraving serial numbers because that's one non-repetitive operation that CNC isn't good at.
Rubbish, if you ask me. You could easily write a macro to engrave a serial number.
Here's an outline of what I suggest based on what I do to engrave hour numbers on sundials

Preparatory work:
Create ten subroutine files, each of which engraves a digit from 0 to 9 at the current XY position, then ends in an M99. This is easily done with, for instance, the Write wizard. Just run it ten times, once per digit, edit the output to add the M99, save to the subroutines folder. Call the files something like mydigit0.tap to mydigit9.tap
If the digits are bigger or smaller than you need for some items, you can always wrap the invokation inside a G51/G50 pair.

Decide on an unused DRO number to be used for serial numbers. You could add it to your screens so that you can see and set it, if you wished.
Initialise it. (I don't know how to make its value persist from session to session, but I expect it can be done. Even if DROs can't be made persistent, tool and work offsets can so you could treat the current serial number as a tool or fixture offset. Perhaps someone else can help with this issue.)

Write a macro along the lines of:

Dim serial as integer, i as integer, digit as integer
serial=GetUserDRO(nnn) +1
Call SetUserDRO(nnn, serial)
OpenTeachFile("EngraveSerial.tap") 'Create a batch file with the M98 commands in.
Call Code("(Engrave serial number " & serial & ")" )
For i=1 to 4 'or however many digits long your serial numbers are
  digit=serial MOD 10
  serial = serial/10
  Call Code ("G0 X" & <some function of i> ) 'Position each digit.
  Call Code ("M98 (mydigit" & digit & ".tap) L1")
Next i
Call Code ("M30")
Call CloseTeachFile()
Call LoadTeachFile()

..That's it. At the end of your main part file, put in code to position the tool at the serial field, zero the X and Y axes, then invoke the macro.
It will create EngraveSerial.tap, then load it. So the GCode display will look something like:
(Engrave serial number 1234)
G0 X21
M98 (mydigit4.tap) L1
G0 X14
M98 (mydigit3.tap) L1
G0 X7
M98 (mydigit2.tap) L1
G0 X0
M98 (mydigit1.tap) L1
M30

Note that, as written, this engraves the digits in order from least significant to most significant. It depends on the X and Y values having been set to 0 before the macro was invoked. You could do this with G52 or G68 (with a non-zero angle). This seems inelegant. Maybe there's a better way.

Hope this helps
Chris


Offline jimpinder

*
  •  1,232 1,232
  • Wakefield, West Yorks, UK
    • View Profile
Re: Macro or wizard for incrementing number?
« Reply #2 on: March 13, 2008, 05:33:55 PM »
I am not quite sure if you just want to generate a number that increments, or something to start up an engraving program to engrave the number.

If it is the first one, then do you mean a different number on each cycle i.e. on a run of 500, each one is numbered 1 to 500 - or - do you mean a part number to identify the part - like spare parts for cars or something.

But in either case a visual basic macro would do the trick, and you could also control the engraving program as well.

The above post arrived just before I posted mine - so just to answer the query - I have several users DRO's on my lathe front page into which I can enter information for small turning jobs - the macros pick up the numbers from these - and yes - they are persistant - they stay as set until you change them - even if you turn the computer off.
« Last Edit: March 13, 2008, 05:39:05 PM by jimpinder »
Not me driving the engine - I'm better looking.
Re: Macro or wizard for incrementing number?
« Reply #3 on: March 13, 2008, 10:10:22 PM »
Good. That clears up my concern about DROs being persistent.
By the way, I've realised that my G0 commands to position each digit don't work. You should use G68 or G52 instead, I think. This is because the digit subroutines engrave at wherever (0,0) is. G0 doesn't affect this, but G68 and G52 do. I use G68 (rotate and move the coordinate origin) a lot to engrave digits, but you have to be aware that it must have a non-zero angle or it won't move the origin. 0.1 degrees works fine, 0 does not.
By the way, as I've recorded elsewhere, G68 Xx Yy Rr doesn't rotate the coordinate system about (x,y). It moves the origin to (x,y), then rotates the coordinate system about that point. Quite different. But very useful.
Regards
Chris
Re: Macro or wizard for incrementing number?
« Reply #4 on: March 13, 2008, 10:55:24 PM »
Well this is going to take some study on my part. What would be nice to do is preset the letter/number combo and increment it for each part cycle. For example on a specific day, set your text to be engraved as 13MAR08-00101 and just increment the 00101. Pardon me for being a bit lost, but would it be possible to specify the font size when setting up, location etc?  I haven't spent any time on the customizing or programming side of the Mach software as you can tell.

Offline jimpinder

*
  •  1,232 1,232
  • Wakefield, West Yorks, UK
    • View Profile
Re: Macro or wizard for incrementing number?
« Reply #5 on: March 14, 2008, 02:45:12 PM »
You Rusty Old Dogs are all the same - give you a penny and you want a pound - you'll be asking for it to draw a self potrait of the author next.

But yes, you can. Certainly the first is no problem, you can enter the day/date and then the machine can put in a serial number and increment it on each pass.

As to the fonts - I think this depends more on what engraving program you are using, and how easy it is to change that.
Not me driving the engine - I'm better looking.
Re: Macro or wizard for incrementing number?
« Reply #6 on: March 14, 2008, 04:09:33 PM »
You Rusty Old Dogs are all the same - give you a penny and you want a pound - you'll be asking for it to draw a self potrait of the author next.

But yes, you can. Certainly the first is no problem, you can enter the day/date and then the machine can put in a serial number and increment it on each pass.

As to the fonts - I think this depends more on what engraving program you are using, and how easy it is to change that.

LOL, well a turn key solution would be a big bonus. Like I said I need to comprehend what ChrisLT posted. If it's simply a matter of creating the individual numeric characters in the CAD software then calling the code for the characters as sub routines, that will work. I don't need to change the font size on the fly. I have two programs at my disposal. OneCNC which I use for everything and the lite version of the 2Linc engraving program. 

Only issue I see at the moment might be the kerning or character spacing, I'll put some thinkage on it and see what I come up with.
Re: Macro or wizard for incrementing number?
« Reply #7 on: March 18, 2008, 09:35:14 PM »
If you needed to, you can easily change the font size and direction of engraving at run-time. Generate the font, digit by digit as I described, all at some nominal size. Say, you made the character height 1 unit.
Then, to print at 5 units height, add G51 X5 Y5 just before each M98, and G50 just after.
This way, you can use one font and engrave at any size. Or even a mix of sizes.
Make sure the font files don't themselves contain any G51 commands. But there's no reason why they should.
Good luck
Chris

vmax549

*
Re: Macro or wizard for incrementing number?
« Reply #8 on: March 27, 2008, 09:10:24 PM »
Chris I have a macroB macro from a fanuc that does about what you say. If you are interrested it has the numbers already gcoded and is laid out similar to your code. If you could convert it into a working MACH Mcode macro it would be very cool to have.

I also have a macro with all the letters coded out, maybe  you could do an engrave Mcode as well.

Let me know if you are interested. It would make a very good addition to the MACH TOOL BOX we need to start. I have several cool probing macro/program I can add??

(;-) TP
« Last Edit: March 27, 2008, 09:12:49 PM by vmax549 »

vmax549

*
Re: Macro or wizard for incrementing number?
« Reply #9 on: April 01, 2008, 12:37:01 PM »
RustyOldDog, do you still need the serial number MCODE??  We have a working protoype now that does sequential serial numbers with a presettable starting number. Each time the mcode runs it increments the number up one. I have done 300 serial number plates this week without flaw.

IE:  It will engrave the following format

S/N: 1000000
S/N: 1000001
S/N: 1000002
ETC,

(;-) TP
« Last Edit: April 01, 2008, 12:38:49 PM by vmax549 »