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:

Variables? Macros?


Recommended Posts

I am not sure if this where this post should be.

Anyway, I am trying to use macro/variable on my T, D offset and H offset.

So, my programs will look like this, and this is without subprograms.

 

#1 = 1

T#1 M6

G.. H#1 .. ..

G01 G41 D#1 ..

 

#2 = 2

..

 

This is so operator will only changes one thing on each Tool instead of going through T, then H and all D of that same Tool.

From what I understand is that I can only use variable 1-33.

 

I've tested a program on the machine and it runs. Dry run. My concern is that will it run on every program and won't crash the machine?

 

Link to comment
Share on other sites

Macro B and Mastercam post processers are two independent programming systems. It might help if we knew exactly what you are trying to achieve. Most people are trying to get there posted files to NOT require editing at the machine as this is the source of many scrap parts. Is it possible to output the code you want by editing the post processer? Yes, but it will be a fair amount of work......

Why not just assign the correct numbers in the source file?

Link to comment
Share on other sites

Will you use the same variable every time?  If so you can just make your post output the #n you want.

I may also suggest not using #1 as this is typically a system variable.  Typically, user variables start at #500 and go up.

If you have a probe, they usually use #100-#199 or so, give or take for the brand.

I usually use #600 and up for my stuff.  I have a system, mostly based off of the key sequence to get to the proper screen such as page down twice and it's the first one on the list or puts it at the bottom right for quick access.

Any way, just a suggestion.  You can get in trouble in a hurry with macros so take the time to develop a system and then stick to it.

Link to comment
Share on other sites
1 hour ago, jlw™ said:

Will you use the same variable every time?

Looks like he wants to assign a different variable for each tool, and then the operator assigns the variable according to whatever tool load he has up, but it is unclear to me what he is trying to achieve. It seems to be fraught with danger. Maybe I'm just missing something. Just seems to me it would be "safer" to reassign the T#s in the source and repost. Interested in what the purpose of the exercise is, perhaps tool management?......just building the toolist which tells the operator what variable goes with what tool would be a major project in itself, but I am by no means an expert at this.

Link to comment
Share on other sites

I really appreciate all your response. I am not sure the best way to explain this. English is my second language so bear with me. So, here is the story.

Our shop is not enforcing to saved mastercam files in our network. Our Programmers, comes and go. Ending up with just NC files in our network.

The way we are setup is, we load an old/new program. We will found out that tools already in the machine but in wrong station. So, Op usually changes T, the H and all Ds for each station.  That's takes time. And if Op missed one D, which happened quite a few time.

So, I, who's acting as a substitute programmer think that this will work. So, yes, I want to assign different variable for each tool that Operator will changes to whatever tool load in their machines. That's all. I hope that this clear all up. 

 

Here is sample of my programs.

 

(MATERIAL - 3.50W X 3.50L X .625H ALUM 6061-T6)
( T#1 | 2"  FACE MILL | FLT:2 | LOC:1.575 | SO:2.100 | H#1 )
( T#2 | 1/2 FLAT EM | FLT:3 | LOC:1.000 | SO:1.500 | H#2 | D#2 | WEAR COMP | DIA - .5 )
( T#3 | 3/16 FLAT EM | FLT:3 | LOC:.438 | SO:1.000 | H#3 | D#3 | WEAR COMP | DIA - .1875 | XY STOCK TO LEAVE - .0073 | Z STOCK TO LEAVE - .01 )
( T#4 | 3/32 FLAT EM | FLT:4 | LOC:.375 | SO:1.000 | H#4 | D#4 | WEAR COMP | DIA - .09375 | XY STOCK TO LEAVE - .011 | Z STOCK TO LEAVE - 0. )
G20
G0 G17 G40 G49 G80 G90
#1 = 1 ( T#1 | 2"  FACE MILL | FLT:4 | LOC:.375 | SO:1.000 | H#1 | D#1 )		------ OP will make this #1 = 8 (IF 2" FM is in Station 8)
N1 ( SHAVING )
T#1 M6 ( T#1 | 2"  FACE MILL | FLT:4 | LOC:.375 | SO:1.000 | H#1 | D#1 )
( MAX -  Z2. )
( MIN -  Z0. )
G0 G90 G54 X-5.45 Y-.5001 S7500 M3
G43 H#1 Z2. T#2
Z.1
G1 Z0. F75.
X1.2
Y-1.25
X-4.45
Y-2.
X1.2
Y-2.7499
X-5.45
G0 Z2.
M5
G91 G28 Z0.
M01
#2 = 2 ( T#2 | 1/2 FLAT EM | FLT:4 | LOC:.375 | SO:1.000 | H#2 | D#2 )			
N2 ( FINISHING AROUND )
T#2 M6 ( T#2 | 1/2 FLAT EM | FLT:4 | LOC:.375 | SO:1.000 | H#2 | D#2 )
( MAX -  Z2. )
( MIN -  Z-.52 )
G0 G90 G54 X-3.625 Y.5 S7500 M3
G43 H#2 Z2. M8 T#3
Z.1

 

 

For each variable will be the station number.

#1 = 5 (station/tool 5)

#2 = 8 (station/tool 8)

#3 = 15 (station/tool 15)

 

 

Link to comment
Share on other sites

OK that's what I thought originally, (and don't worry I'm sure your English is better than my "your first language"!!)

As jlw mentioned you might want to be careful how you assign your variables. There are probably, depending on your machine, other Macro B routines running in the background that you never see (M6 and G28 for example). You might want to get a Macro B variable reference guide that will tell you what variables are actually available to you that will not interfere with other Macro B routines.

However it is just as easy to make a mistake assigning variables (even though they are fewer) at the control as reassigning offsets and tool numbers. Either way it is a dangerous way to fly. And hand editing the existing code is also prone to error, what if you miss a D# call in the middle of a toolpath? Even with editing tools the possibility is always there for mistakes, Mastercam with a "post and go" post processer will always compile your code better than any human, that's why we have this forum.....

I would certainly be looking at reprogramming and saving the source files properly. How big / complex are the files? If they are simple it will probably be quicker and safer to start from scratch....

Best of luck..!!

Link to comment
Share on other sites

It is possible to have Mastercam post output macro variable codes like T#1 T#2 T#3, very easy actually.  But this could cause some issues depending on how your program runs.  For example what if you have more than 21 tools in a program?  What if you use the same tool twice in different locations?

Link to comment
Share on other sites

My recommendation would be to pick up a good book on Macro B Programming, and immerse yourself in that knowledge, before you go ahead with making the changes. This will potentially save you some serious crashes and/or aggravation down the road.

There are two books I would recommend (I own both):

CNC Programming using Fanuc Custom Macro B, by S.K Sinha (Author)

and

Fanuc CNC Custom Macros, by Peter Smid (Author) 

Both of those books contain a world of knowledge about how Macro B programming works, how to write good programs, and how to test to be sure you've got all the features needed.

In this case, I'd only worry about changing the "active tool" number, and use System Variables to account for the "on the fly" changes.

For example:

#1 = 3
#2 = 5
#3 = 8

T#1 M06
G00 G90 G54 X1.0 Y1.0 S4430 M03
G43 H#4120 Z2. M08
Z-3.0
G01 G41 D#4120 X1. Y3.
.
.
M09
G00 G90 G53 G49 Z0.
T#2 M06
G43 H#4120 Z6. M08
Z0.
G01 G41 D#4120 X1. Y3.

What I've done is to make all of the H and D numbers set equal to "the active tool number", by using the System Variable #4120. That variable holds the "Active Tool" in the tool spindle. You must be careful when you do this. For example, it can be dangerous to turn on "staged tools" when using these Macro Variables. You want to be sure #4120 on your system is the variable that holds the "current tool in the spindle", and not the "tool that has been called by pre-stage".

This will make your life much easier, as the Operators on the shop floor only have to worry about setting the Tool Variables, and not have to mess around with H/D offsets.

 

 

Link to comment
Share on other sites
Just now, nickbe10 said:

Great book, the best of the Macro B books in my opinion.....

Hey Colin did you get my e-mail? Send me one.....

Yes, sorry Nick. Just been super slammed with work. I'll be in touch soon. (Can you guys make a credit card payment to PayPal? That's about the easiest way for me to accept a Credit Card payment at the moment...)

Thanks,

Colin

Link to comment
Share on other sites
9 minutes ago, Colin Gilchrist said:

Yes, sorry Nick. Just been super slammed with work. I'll be in touch soon. (Can you guys make a credit card payment to PayPal? That's about the easiest way for me to accept a Credit Card payment at the moment...)

No problem, will check out the above and let you know. We have some time to get our stuff together, just trying to stay in front.....

  • Like 1
Link to comment
Share on other sites
2 hours ago, Colin Gilchrist said:

My recommendation would be to pick up a good book on Macro B Programming, and immerse yourself in that knowledge, before you go ahead with making the changes. This will potentially save you some serious crashes and/or aggravation down the road.

There are two books I would recommend (I own both):

CNC Programming using Fanuc Custom Macro B, by S.K Sinha (Author)

and

Fanuc CNC Custom Macros, by Peter Smid (Author) 

Both of those books contain a world of knowledge about how Macro B programming works, how to write good programs, and how to test to be sure you've got all the features needed.

In this case, I'd only worry about changing the "active tool" number, and use System Variables to account for the "on the fly" changes.

For example:


#1 = 3
#2 = 5
#3 = 8

T#1 M06
G00 G90 G54 X1.0 Y1.0 S4430 M03
G43 H#4120 Z2. M08
Z-3.0
G01 G41 D#4120 X1. Y3.
.
.
M09
G00 G90 G53 G49 Z0.
T#2 M06
G43 H#4120 Z6. M08
Z0.
G01 G41 D#4120 X1. Y3.

What I've done is to make all of the H and D numbers set equal to "the active tool number", by using the System Variable #4120. That variable holds the "Active Tool" in the tool spindle. You must be careful when you do this. For example, it can be dangerous to turn on "staged tools" when using these Macro Variables. You want to be sure #4120 on your system is the variable that holds the "current tool in the spindle", and not the "tool that has been called by pre-stage".

This will make your life much easier, as the Operators on the shop floor only have to worry about setting the Tool Variables, and not have to mess around with H/D offsets.

 

 

Hi, used this method in a machine on my old work place, works quite good, keep in mind the pre set staging as mentioned and make sure your active tool is in spindle, and you have an easy way of just changing one thing and be sure that the offsett follows the active tool, ah, the power of Fanuc... i also liked the way Okuma solves this, i think Colin got me now to look back in some old macros again, even in the summer vacation! Thanks 😉

  • Like 1
Link to comment
Share on other sites

Are you using a Fanuc control? If so I would be careful using local variables (#1 through #33) for what you want to do. Local variables by default will reset themselves to null after leaving any special M, G, or T code. I have not checked as to whether Fanuc standard G codes (G83 R Z Q F) uses the local variables but if it does your variables will be wiped out after your first drilling operation as well as if your machine builder itself uses them. There is a parameter that will make the control save the variables after leaving each macro using them but that in itself is very dangerous. With that stated using the #100 variables by default will reset themselves to null at program end. If you are going to do this I would recommend using the #500 variables. The #500 variables will keep keep their values even when the machine is turned off.

Link to comment
Share on other sites
From a friend who said I'm missing what you want:
 
use the ASCII equivalent of the pound sign (035) for getting output.  The Tool number and H number are easy peasy. 
 
    prv_spaces$=spaces$
    spaces$=0
    pbld, *n$, "T", 035, "M6", ptoolcomm, e$
    spaces$=prv_spaces$
 
 
    prv_spaces$=spaces$
    spaces$=0
    pbld, n$, "G43", " H", 035 , "517 ", pfzout, " ", next_tool$, e$
    spaces$=prv_spaces$
 
The D however takes some doing and is not easily explained. 
 
First modify the pccdia postblock - change the 517 to whatever number you want to use. ; 
pccdia          #Cutter Compensation
      #Force Dxx#   
 
      if prv_cc_pos$ <> cc_pos$ & cc_pos$, prv_tloffno$ = c9k
      sccomp
    tloffno$ = 517
 
     if cc_pos$, tloffno$
 
Next in the following section add the srtl*;
 
# --------------------------------------------------------------------------
#String and string selector definitions for NC output
# --------------------------------------------------------------------------
#Address string definitions
 
strtlm : ""
strtlmd      : "D"
strtlmv : ""
 
Add the following fmt to the section noted. 
# --------------------------------------------------------------------------
# Toolchange / NC output Variable Formats
# --------------------------------------------------------------------------
fmt     4   tlmv    #Tool Length Variable 
 
And finally in pheader BEFORE the tool list gets output; 
 
     strtlmd = strtlmd + no2asc(035) # Variable Output for Cutter Compensation
     result = nwadrs(strtlmd,tloffno$)  # Variable Output for Cutter Compensation
 
 
Have fun. 
  • Like 4
Link to comment
Share on other sites

I would recommend using #100-#199 or #500-#999 for doing what you want as well.

 

Using #1-#33 is bad form in the way you have shown and WILL get you into serious trouble. :cough: service call you can't afford :cough: 

Link to comment
Share on other sites
On 7/19/2017 at 5:46 AM, Colin Gilchrist said:

My recommendation would be to pick up a good book on Macro B Programming, and immerse yourself in that knowledge, before you go ahead with making the changes. This will potentially save you some serious crashes and/or aggravation down the road.

There are two books I would recommend (I own both):

CNC Programming using Fanuc Custom Macro B, by S.K Sinha (Author)

and

Fanuc CNC Custom Macros, by Peter Smid (Author) 

Both of those books contain a world of knowledge about how Macro B programming works, how to write good programs, and how to test to be sure you've got all the features needed.....

 

I don't have the first book but the 2nd... I do. My other reference is no longer in print and no longer available, it's by Michael Hubbard. Most of the I use the FANUC Manual's Custom MACRO B section. 

Link to comment
Share on other sites

Thank you guys. We were able to generate NC code the way we want it. I guess I can start tool number from 500 as most of you suggested, I assigned variable before tool changes and don't use macro on our NC codes. Here is sample.

 

O2961(100088296 REV 0)
(DATE - 24-07-17 TIME - 09:57)
(PROGRAMMER - DARWIN)
(MATERIAL - FULLY WELDED PART)
( T#1 | 3/4 FLAT EM  | FLT:4 | LOC:2.000 | SO:2.750 | H#1 | D#1 | WEAR COMP | DIA - .75 )
( T#2 | 1/2 SPOTDRILL | FLT:2 | LOC:2.000 | SO:2.500 | H#2 )
( T#3 | LTR. Q DRILL  | FLT:2 | LOC:2.000 | SO:4.000 | H#3 )
( T#4 | 3/8-24 TAPRH  | FLT:1 | LOC:2.000 | SO:4.000 | H#4 )
( T#5 | 1/2 FLAT EM  | FLT:4 | LOC:1.000 | SO:3.000 | H#5 | D#5 | WEAR COMP | DIA - .5 )
G20
G0 G17 G40 G49 G80 G90
( G54 XY IS PER PRINT, Z IS TOP OF MATERIAL )
( OFFSET Z 11.237" FROM THE BOTTOM )
N1 ( SHAVING 5.6875 PLANE, -2.312 DEEP )
#1 = 1 ( T#1 | 3/4 FLAT EM | FLT:4 | LOC:2.000 | SO:2.750 | H#1 | D#1 )
T#1 M6 ( T#1 | 3/4 FLAT EM | FLT:4 | LOC:2.000 | SO:2.750 | H#1 | D#1 )
( MAX: Z2. )
( MIN: Z-2.312 )
G0 G90 G54 X-15.75 Y1.1025 S2000 M3
G43 H#1 Z2. M8
Z-2.15
G1 Z-2.312 F15.
G41 D#1 Y.9775
G3 X-15.625 Y.8525 I.125 J0.
G1 X-15.25
X-11.75
X-11.7
G3 X-11.575 Y-1.1875 I0. J.125
G1 G40 Y-1.0625
G0 Z2.
M5
G91 G28 Z0. M9
M01
N2 ( SPOT DRILL )
#2 = 2 ( T#2 | 1/2 SPOTDRILL | FLT:2 | LOC:2.000 | SO:2.500 | H#2 | D#2 )
T#2 M6 ( T#2 | 1/2 SPOTDRILL | FLT:2 | LOC:2.000 | SO:2.500 | H#2 | D#2 )
( MAX -  Z2. )
( MIN -  Z-2.375 )
G0 G90 G54 X-14.181 Y-.4019 S1500 M3
G43 H#2 Z2. M8
G98 G81 Z-2.375 R-2.15 F5.
G80
M5
G91 G28 Z0. M9
M01
N3 ( .332 HOLE FOR 3/8-24 TAP )
#3 = 3 ( T#3 | LTR. Q DRILL | FLT:2 | LOC:2.000 | SO:4.000 | H#3 | D#3 )
T#3 M6 ( T#3 | LTR. Q DRILL | FLT:2 | LOC:2.000 | SO:4.000 | H#3 | D#3 )
( MAX -  Z2. )
( MIN -  Z-3.65 )
G0 G90 G54 X-14.181 Y-.4019 S1000 M3
G43 H#3 Z2. M8
G98 G83 Z-3.65 R-2.15 Q.15 F5.
G80
M5
G91 G28 Z0. M9
M01
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...