BlaskoM

Z depth as macro variable

Recommended Posts

Hello, I am new to mastercam and the post processes but I am taking over some basic mastercam programming responsibilities  from a co worker. 

What I can't figure out is how to make the post create code with the Z depths as macro variables.

In my tool path parameters under linking parameters it has the feed plane at 6 so it puts Z6. in the post code.

What I want is Z[#502+7.00]

Is there a way I can do that? If I try to put [#502+7.00] directly in the box i linking parameters, it crashes mastercam because it does not know the # symbol

 

Thanks

  • Like 1

Share this post


Link to post
Share on other sites

You would have to create a logic process using mi and mr triggers to accomplish this task. Mastercam is not a macro output by nature software. It can be done, but heavy post work IMHO would need to be done to accomplish that task.

Welcome to the Mastercam forum.

  • Like 1

Share this post


Link to post
Share on other sites
On 3/14/2020 at 8:45 AM, BlaskoM said:

Hello, I am new to mastercam and the post processes but I am taking over some basic mastercam programming responsibilities  from a co worker. 

What I can't figure out is how to make the post create code with the Z depths as macro variables.

In my tool path parameters under linking parameters it has the feed plane at 6 so it puts Z6. in the post code.

What I want is Z[#502+7.00]

Is there a way I can do that? If I try to put [#502+7.00] directly in the box i linking parameters, it crashes mastercam because it does not know the # symbol

 

Thanks

Part of the issue is: do you want "all Z Values" coming out of the Post to have that Variable output, or "just the Clearance Value at the Tool Change Event?

You can use the 'new address' function to assign different prefix and suffix values to the numerical output.

I made these edits to MPMaster, to get the output you are looking for. Warning: use this at your own risk! No warranty is expressed or implied, and Selway Machine Tool is not liable for and edits you make to your Post Processor. (Make sure you make a backup copy (at least 2 copies!!!) of your Post before you start!)

First, create some variables:

sav_zabs    : 0     #Saved Z Abs Value
str_z_pvar   : "Z[#502+"
str_z_svar   : "]"
str_z_pstd   : "Z"
str_z_sstd   : ""

 

Inside "ptlchg_com", change this:

      phsm1_on        #must remain before G43
      pbld, n$, "G43", *tlngno$, pfzout, scoolant, next_tool$, e$
      pcan2           #Added so M and G codes in canned text will output before phsm2_on

To This:

      phsm1_on        #must remain before G43
      ### CMG START CHANGES- We must manipulate the formatting for 'zabs' (output in pfzout), but then we must restore it afterwards!
      sav_zabs = zabs # Store current for restore
      result = nwadrs(str_z_pvar, zabs) #Assign new prefix string to zabs
      result = nwsufx(str_z_svar, zabs) #Assign new suffix string to zabs
      zabs = sav_zabs, prv_zabs = c9k #set current to output, force output by setting previous to c9k
      pbld, n$, "G43", *tlngno$, pfzout, scoolant, next_tool$, e$
      #Set Z back to normal output
      result = nwadrs(str_z_pstd, zabs) #Assign original prefix string to zabs
      result = nwsufx(str_z_sstd, zabs) #Assign original suffix string to zabs
      zabs = sav_zabs, !zabs #set current to output, update variable to maintain proper modality
      #CMG END CHANGES
      pcan2           #Added so M and G codes in canned text will output before phsm2_on

 

 

Here is the output I got from a simple rectangle:

%
O0123 (T)
(MCX FILE  - T)
(PROGRAM   - T.NC)
(DATE      - MAR-16-2020)
(TIME      - 9:32 AM)
(T3   - 5/8 FLAT ENDMILL     - H3   - D3   - D0.6250")
G00 G17 G20 G40 G80 G90
G91 G28 Z0.
(COMPENSATION TYPE - COMPUTER)
M08
T3 M06 (5/8 FLAT ENDMILL)
(MAX - Z5.1234)
(MIN - Z0.)
G00 G17 G90 G54 X-2.8265 Y-.7537 S11111 M03
G49
G94
G05.1 Q1
G43 H3 Z[#502+5.1234]
Z.2
G95 G01 Z0. F.0079
X-2.2015 F.02
G03 X-1.5765 Y-.1287 I0. J.625
G01 Y.6999
G02 X-1.264 Y1.0124 I.3125 J0.
G01 X1.2453
G02 X1.5578 Y.6999 I0. J-.3125
G01 Y-.9574
G02 X1.2453 Y-1.2699 I-.3125 J0.

 

  • Like 2

Share this post


Link to post
Share on other sites
On 3/16/2020 at 12:32 PM, Colin Gilchrist said:

ptlchg_com

Colin,

The changes you posted worked great for the G43 Line.

T1 (1/2" ENDMILL 1" LOC)
M06
G54.1 P1 X-1.7483 Y0. S5000 M03
G43 H1 Z[#502+2.] M07
Z1.
Z.1
G01 Z.01 F75.
G41 D1 X-1.6483 F150.

 

Can this be done with ONLY the FINAL Z DEPTH or Z DEPTHS if the toolpath had more than one.

T1 (1/2" ENDMILL 1" LOC)
M06
G54.1 P1 X-1.7483 Y0. S5000 M03
G43 H1 Z2. M07
Z1.
Z.1
G01 Z[#502+.01] F75.
G41 D1 X-1.6483 F150.

Share this post


Link to post
Share on other sites
2 hours ago, Dave228 said:

Colin,

The changes you posted worked great for the G43 Line.

T1 (1/2" ENDMILL 1" LOC)
M06
G54.1 P1 X-1.7483 Y0. S5000 M03
G43 H1 Z[#502+2.] M07
Z1.
Z.1
G01 Z.01 F75.
G41 D1 X-1.6483 F150.

 

Can this be done with ONLY the FINAL Z DEPTH or Z DEPTHS if the toolpath had more than one.

T1 (1/2" ENDMILL 1" LOC)
M06
G54.1 P1 X-1.7483 Y0. S5000 M03
G43 H1 Z2. M07
Z1.
Z.1
G01 Z[#502+.01] F75.
G41 D1 X-1.6483 F150.

"Only the final depth" is a tall order. There are some new tools inside MP to be able to query the Operation structure, but I'm not very well versed in using them.

Traditionally, it is rather difficult to tell "have I finished a given operation or not"? The reason for this is the way the NCI data is structured. Every "depth cut" or "multi-pass" is written to the NCI File as a "Null Toolchange". (NCI Gcode = 1000). So it can be difficult to test and see "am I done with the current operation, or are there "more passes" to go?

Fortunately MPMaster has both "regular retract", and "null retract" sections.

Having done this for a while, my recommendation would be "leave the output as 'variable Z output' until the Operation has completed, and then switch back to regular (non-variable) Z output.

To do that, move the "new address and new sufffix" commands to 'pretract'.

pretract        #End of tool path, toolchange
      phsm_off
      sav_absinc = absinc$
      absinc$ = one
      sav_coolant = coolant$
      coolant$ = zero

#      if nextop$ = 1003, #Uncomment this line to leave coolant on until eof unless
#        [                 #  explicitely turned off through a canned text edit
        if all_cool_off,
          [
          #all coolant off with a single off code here
          if coolant_on, pbld, n$, *sall_cool_off, e$
          coolant_on = zero
          ]
        else,
          [
          local_int = zero
          coolantx = zero
          while local_int < 20,
            [
            coolantx = and(2^local_int, coolant_on)
            local_int = local_int + one
            if coolantx > zero,
              [
              coolantx = local_int
              pbld, n$, scoolantx, e$
              ]
            coolantx = zero
            ]
          coolant_on = zero
          ]
#        ]

      #cc_pos is reset in the toolchange here
      cc_pos$ = zero
      if convert_rpd$ = one,
        [
        gcode$ = one
        feed = maxfeedpm
        ipr_type = zero
        ]
      else, gcode$ = zero
      pbld, n$, sccomp, *sm05, psub_end_mny, e$
      pcancel_rot_coord
      pbld, n$, sgabsinc, sgcode, [if gcode$ = 1, sgfeed], *sg28, "Z0.", [if gcode$ = 1, feed], scoolant, e$
#      if lock_codes = one & rot_on_x, pbld, n$, *sunlock, sunlockcomm, e$
#      pbld, n$, *sg28, "X0.", "Y0.", protretinc, e$
#      if lock_codes = one & rot_on_x & cuttype = 0, pbld, n$, *slock, slockcomm, e$
      if abs(fmtrnd(cabs)) > 360 & nextop$ <> 1003 & not(index),
        [
        if lock_codes = one, pbld, n$, *sunlock, sunlockcomm, e$
        rotretflg = 1
        pbld, n$, `sg28, protretinc, e$
        rotretflg = 0
        if lock_codes = one & cuttype = 0, pbld, n$, *slock, slockcomm, e$
        ]
      absinc$ = sav_absinc
      coolant$ = sav_coolant
      uninhibit_probe$
      #Set Z back to normal output
      result = nwadrs(str_z_pstd, zabs) #Assign original prefix string to zabs
      result = nwsufx(str_z_sstd, zabs) #Assign original suffix string to zabs
      zabs = sav_zabs, !zabs #set current to output, update variable to maintain proper modality

 

 

 

Share this post


Link to post
Share on other sites

Colin,

I guess you probably know by now I am trying to get a variable Z Depth so I can program a family of parts with one toolpath, using a #variable for the depth, where the variable would be the part thickness.

let me ask you this. how would you use mastercam to do a family of parts like that? the guys are "used to" having one program make several parts and I am trying to keep the hand editing as close to zero as possible, hence the odd post edit questions.

I got this code from my local reseller. Its pretty cool because it adds the #xxx behind ALL Z depths, but since it ALSO captures the Clearance and Retract heights, its really only good for "moving" the toolpaths up or down with the variable as opposed to stretching the depth.

szsufx : "+[#100]"

pzparam
      if mi5$,[
        result = nwsufx(szsufx, zabs)
        result = nwsufx(szsufx, zinc)
        result = nwsufx(szsufx, depth_a)
        result = nwsufx(szsufx, depth_i)
      ]
      else,[
        result = nwsufx("", zabs)
        result = nwsufx("", zinc)
        result = nwsufx("", depth_a)
        result = nwsufx("", depth_i)
      ]

Then "pzparam" gets added to the  ptlchg_com section and the ptlchg0$ section

Share this post


Link to post
Share on other sites
4 hours ago, Dave228 said:

Colin,

The changes you posted worked great for the G43 Line.

T1 (1/2" ENDMILL 1" LOC)
M06
G54.1 P1 X-1.7483 Y0. S5000 M03
G43 H1 Z[#502+2.] M07
Z1.
Z.1
G01 Z.01 F75.
G41 D1 X-1.6483 F150.

 

Can this be done with ONLY the FINAL Z DEPTH or Z DEPTHS if the toolpath had more than one.

T1 (1/2" ENDMILL 1" LOC)
M06
G54.1 P1 X-1.7483 Y0. S5000 M03
G43 H1 Z2. M07
Z1.
Z.1
G01 Z[#502+.01] F75.
G41 D1 X-1.6483 F150. 

 

The only way I can see to do a "FINAL Z DEPTH or Z DEPTHS if the toolpath had more than one" is to make a WHILE/DO loop and you will need more than one variable but they won't need to be stored. They should be able to be created inside the loop(s). The final Z shown "G01 Z[#502+.01] F75." looks like its not the final Z. This means at least one more loop would be needed and depending on what control you have you may be limited on how many loops that will be allowed.

 

Share this post


Link to post
Share on other sites

Parameter 19 contains the minimum Z value for an operation. I think you could use this information to check if you're at the lowest Z; below is some pseudo code.

op_min_z : 99999

fmt  "Z" 2  z$        #Z position output
fmt  ""  2  op_min_z  #Min Z position, formated for comparision

ptlchg$
    op_min_z = 99999
    # Get the opertions min Z position
    op_min_z = opinfo(19, 0)

plin$
    # Test to see if we are at the min Z position
    if fmtrnd(op_min_z) = fmtrnd(z$),
        [
        # The min Z has been reached, update the prefix/suffix
        result = nwadrs("Z[#502+", z$)
        result = nwsufx("]", z$)
        ]
    else,
        [
        # We are not at the min Z, restore the orignal prefix/suffix
        result = nwadrs("Z", z$)
        result = nwsufx("", z$)
        ]

  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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