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:

Line number change based on tool change for lathe


Recommended Posts

The reason for the code below is hard to explain over the web, but what it does is if the next tool number is the same as the previous it adds on to the N#, but if the next tool is different then the one just used it changes the N# to the next highest 100 based number.

IE,

N100(1st Tool)

Tool does it's thing

Tool goes home

If Tool was sent home because you selected "Force Tool Change" or you used "Tool Inspection Point" the next Line would be

N101(1st Tool)

Tool does the next thing

If the next tool number is different (Like calling up a drill after facing a part), instead of N101 you would get

N200(2nd Tool)

Tool does its thing

I think I read somewhere that IHS has something similar in their standard Fanuc post, and maybe everybody uses IHS posts, but this should work in any of the supplied Mastercam posts.

I have it working in the generic Fanuc 2X post, but don't see why it wouldn't work in any other post. My 1st line number is always 100 hence adding 100 at a different tool.

Paste/type code below in red in ptoolcomment section of post (I have it just above the "if tool_op$ = 64" line in my post

ptoolcomment    #Comment for tool
      if tool_info = 1 | tool_info = 3,
        [
        tnote = abs(t$)
        toffnote = tloffno$
        strtool$ = ucase(strtool$)
        stinsert2 = ucase(stinsert2)
        !spaces$
        spaces$ = zero
        #"(", *tnote, *toffnote, ")", e$
        
        if posttype$ = two, #Lathe toolpath operation
        
        if sav_pretool = t$, #If previous tool is same as current tool continue to "if tool_op ...." below
        
        else,
        
    n$ = sav_seqno + 100, e$ #Line number equals saved sequence number (which should always be 100 based) + 100
        sav_seqno = n$ #Save new 100 base sequence number

                
        if tool_op$ = 64, *n$, "(", *strtool$, ")", e$ #Drill operation
          else, *n$, "(", *strtool$, ")", e$

        #spaces$ = prv_spaces$
        ]

Now type/paste line in red in pheader$ section of post

pheader$         #Start of file
      rd_tlpathgrp$
      if miscopsflg = 0,
      [
      "%", e$
      sav_spc = spaces$
      spaces$ = 0
      *progno$,"(", sprogname$, sextnc$, ")", e$
      "(", "OP#", ")", e$
      "(", "DOCUMENT REV. ", month$, "/", day$, "/", year$, ")", e$ #Date and time output Ex. 12/02/05
      spaces$ = sav_spc
      miscopsflg = 1
      ]
      sav_seqno = n$ #Save 1st sequence number which should be 100

Last is to add the 2 line below in General User Variable section of post

sav_seqno    : 1     #Current 100 based sequence number saved
sav_pretool  : 1     #Save current tool

Maybe someone will find this useful and this post wouldn't have been a waste of my time, but if nobody found it useful oh well. Just figured I'd help someone.

  • Like 1
Link to comment
Share on other sites
34 minutes ago, Günther Massimo - GMCCS said:

Why not...


pcalc_n
	if t$<>prv_t$, n$ = int(n$/100) * 100 + 100

psof$
	pcalc_n
	n$,...
	...
	
ptlchg$
	pcalc_n 
	n$,...
	...

Probably could, would have to add the pcalc_n and such to my post. My way just happened to be what I came up with 1st. I'm not super fluent in posts so sometimes I end up going the long way around the bush.

 

Thanks.

Link to comment
Share on other sites
10 hours ago, lowcountrycamo said:

What of tool number showed up again 3 tools later?  That I would really like.

My code ignores tool numbers themselves per say. It's set up so every time the next tool number is different then the one just used it changes the N number to the next 100 based number. The program I used to verify my code does exactly that. Tool number 2 is recalled after tool number 3 and i changed the N number to the next 100 based number used on tool 3.

Link to comment
Share on other sites

Want to be really cool have all of that out in the header(Tool Table) for the tool number as it changes. I worked on that for months and could never get the buffer structure correct. I could get close, but never could get the numbers to come out correct they were always off by one even when I did all the math your supposed to do with buffers the tool number would never come out correct in the Tool Table when I was trying to have them come out. On tool changes no problem, but in the Tool Table I could never get it to work correctly.

Here is the best I could get it using MPLMASTER as the base:

# --------------------------------------------------------------------------
# NCI file pre-read look ahead routines
# Build the toolchange buffer, sets cycle and turret flags
# --------------------------------------------------------------------------
pwrttparam$      #Information from parameters
      #"pwrttparam", ~prmcode$, ~sparameter$, e$
      if prmcode$ = 15145, metvals   = rpar(sparameter$,1)
      if opcode$ = 104, result = fprm (opcode$)
      if prmcode$ = 15346, comp_type = rpar(sparameter$, 1)
      if prmcode$ = 20103, stinsert2 = sparameter$
      if prmcode$ = 20110, stholder2 = sparameter$

pwrtt$           #Buffer toolchange information, tooltable = 3 calls on 1003
      if gcode$ = 1001, psetup
      pcut_cctyp
      if opcode$=104 | opcode$=105 | opcode$=three | opcode$=16, cc_pos$ = zero
      if gcode$ <> 1001, plast_recd
      pcur_recd
      if gcode$ <> 1003, cc_pos$ = zero
      !opcode$, !tool_op$
      if gcode$ = 1003,
        [
        size1 = rbuf (one, zero)
        rc1 = one
        if rc1 < size1, preadcur_nxt
        if cc_1013$ = zero, cc_pos$ = zero
        ]
      #if you want repetitive tool output, keep the abs( ) in ptooltable and remove the >= t$ from the pwrtt call to this block        
      #if (tool_info = 2 | tool_info = 3) & gcode$ <> 1003 & op_id$ <> last_op_id & last_tloffno <> tloffno$ & t$ >= 0, ptooltable
      if (tool_info = 2 | tool_info = 3) & gcode$ <> 1003 & op_id$ <> last_op_id & last_tloffno <> tloffno$, ptooltable #This allows us to see the same tool with different offset
      last_tloffno = tloffno$ #This controls the different offset tracking not to duplicate it when they are used in the operations
      last_op_id = op_id$
      last_t = t$ #Trying to save the tool to keep subtraction from happening in the tool list when the same tool is called

ptooltable # Write tool table, scans entire file, null tools are negative
           #if you want repetitive tool output, keep the abs( ) in ptooltable and remove the >= t$ from the pwrtt call to this block
           toolno = t$ * 100 + tloffno$
           tnote = abs(toolno) #use to be this abs(t$), but we want it to look different so we changed
           tldianote = abs(tldia$) #Oct-20-08 AEH
           [if spindle_no$ = 0, ntooltrack = t$],[if spindle_no$ = 1, ntooltrack = t$ + 1000]
           ntooltrack = abs(ntooltrack) #See it used else where Figure why not
           if opcode$ = 3 | opcode$ = 16, toffnote = tlngno$
           else, toffnote = tloffno$
           stinsert2 = ucase(stinsert2)
           !spaces$
           spaces$ = zero
           if posttype$ = 2,    #lathe tools
             [
             scomm_str, *tnote, " - ", *ntooltrack, " - ", plistcomm, " - ", *toffnote, pdspace, " - ", *stinsert, *stinsert2, " - ", *stholder, *stholder2, scomm_end, e$
             #scomm_str, *tnote, ptspace, " - ", *toffnote, pdspace, " - ", *stinsert, *stinsert2, " - ", *stholder, *stholder2, scomm_end, e$
             ]
           else,                  #mill tools
             [
             if opcode$ = 3 | opcode$ = 16,
               [
               if tcr$ = 0, scomm_str, *tnote, " - ", *ntooltrack, " - ", plistcomm, " - ", *tldianote, punit, pdiamspc, scomm_end, e$
               ]
             else,
               [
               if tcr$ > 0, scomm_str, *tnote, " - ", *ntooltrack, " - ", plistcomm, " - ", *toffnote, pdspace, " - ", *tldianote, punit, pdiamspc, " - ", *tcr$,  punit, scomm_end, e$
               if tcr$ = 0, scomm_str, *tnote, " - ", *ntooltrack, " - ", plistcomm, " - ", *toffnote, pdspace, " - ", *tldianote, punit, pdiamspc,  scomm_end, e$
               ]
             ]
           spaces$ = prv_spaces$

Here is an example of an issue I was running into posting code. I got rid of the redundant tool posting, but could never get the numbers to adjust correctly.

O1589 (XXXXXXXX_REV_G_UPPER 2017)
(DATE - 03-01-17 TIME - 09:46)
(MCX FILE - C:\CUSTOMERS\XXXXXXXXXXXXX)
(NC FILE - C:\CUSTOMERS\XXXXXXX)
(POST DEV - XXXXXXX MACHINE TOOLS)
(T0101 - N1 - OD 55 ROUGH          - OFFSET - 1   - INSERT - DNMG-432 - HOLDER - MDJNL-164C)
(T0909 - N9 - OD 55 FINISH         - OFFSET - 9   - INSERT - DNMG-431 - HOLDER - MDJNL-164C)
(T1010 - N10 - CENTER DRILL- .25 DIA. - OFFSET - 10  - INSERT - NONE - HOLDER - NONE)
(T0404 - N4 - 1/4 SPOTDRILL        - DIA. - .25")
(T0505 - N5 - 1/8 FLAT EM          - OFFSET - 5   - DIA. - .125")
(T0486 - N5 - 1/8 FLAT EM          - OFFSET - 14  - DIA. - .125")
(T0485 - N5 - 1/8 FLAT EM          - OFFSET - 15  - DIA. - .125")
(T0484 - N5 - 1/8 FLAT EM          - OFFSET - 16  - DIA. - .125")
(T0475 - N5 - 1/8 FLAT EM          - OFFSET - 25  - DIA. - .125")
(T1212 - N12 - 3/32 FLAT ENDMILL    - OFFSET - 12  - DIA. - .09375")
(T0600 - N6 - M4-0.7 STI TAP RH    - DIA. - .191")
(T0808 - N8 - 1/4 CHAMFER MILL     - OFFSET - 8   - DIA. - .25")
(T0099 - N1 - OD 55 ROUGH          - OFFSET - 1   - INSERT - DNMG-432 - HOLDER - MDJNL-164C)
(T0891 - N9 - OD 55 FINISH         - OFFSET - 9   - INSERT - DNMG-431 - HOLDER - MDJNL-164C)
(T1100 - N11 -  1/4 FLAT ENDMILL    - DIA. - .25")
(T1089 - N11 -  1/4 FLAT ENDMILL    - OFFSET - 11  - DIA. - .25")
(T1100 - N11 -  1/4 FLAT ENDMILL    - DIA. - .25")
(T1089 - N11 -  1/4 FLAT ENDMILL    - OFFSET - 11  - DIA. - .25")
(T1100 - N11 -  1/4 FLAT ENDMILL    - DIA. - .25")
(T1089 - N11 -  1/4 FLAT ENDMILL    - OFFSET - 11  - DIA. - .25")
(T1100 - N11 -  1/4 FLAT ENDMILL    - DIA. - .25")
(T1089 - N11 -  1/4 FLAT ENDMILL    - OFFSET - 11  - DIA. - .25")
(T1100 - N11 -  1/4 FLAT ENDMILL    - DIA. - .25")
(T1089 - N11 -  1/4 FLAT ENDMILL    - OFFSET - 11  - DIA. - .25")
(T1100 - N11 -  1/4 FLAT ENDMILL    - DIA. - .25")
(T1089 - N11 -  1/4 FLAT ENDMILL    - OFFSET - 11  - DIA. - .25")
(T0202 - N2 - 1/4 CHAMFERMILL      - OFFSET - 2   - DIA. - .0001")

 

Link to comment
Share on other sites
On 6/29/2018 at 11:50 AM, jeff.D said:

C^Millman,

If you move to the enhanced tool table your dependence on buffers will go down.  Could even use a stack.

 

Thanks,

Jeff 

All ears and would love to see an example. Please point me to a Mastercam MP post that has been updated to use this?

Link to comment
Share on other sites
1 hour ago, C^Millman said:

All ears and would love to see an example. Please point me to a Mastercam MP post that has been updated to use this?

I think this would work with some minor tweaks (depending on what you wanted the line numbers to be).  In this example we'll make them the offset.

#region Tooltable

s1013            : ""
stoolString      : ""

fprmtbl 1 2
        1013   s1013
        10094  stoolString

fmt "DIAMETER - "    3 toolDiameter
fmt "MAX Z DEPTH: "  3 toolZMin
fmt "TOOL NUMBER - " 4 tt_tool$
fmt "N"              4 tt_tlngno$

#Start Array
stackTool : 0
stackLine : 0
#End Array

pushResult : 0

fstack 1 2

ptooltable$
      if (tt_count$ = TOOL_NOT_OUTPUT@),
      [
        return = fprm(ONE@, OP_PARAMETERS@)
        toolDiameter = rparsngl(s1013, TWO@)
        stoolString = ucase(stoolString)
        n$, scommentStart, *tt_tool$, "|", *tt_tlngno$, "|", stoolString, "|", *toolDiameter, "|", pGetToolsMinimumZ(tt_tool$), no_spc$, scommentEnd e$
        stackTool = tt_tool$
        stackLine = tt_tlngno$
        stackTool = push(1, pushResult, 0)
      ]

opZMin       : 0
tool         : 0
toolIndex    : 0
opToolNumber : 0

pGetToolsMinimumZ(tool)
      toolIndex = ZERO@
      toolZMin = ZERO@
      opToolNumber = opinfo(10002, toolIndex)
      while (opToolNumber <> QUERY_INVALID@),
      [
        if (opToolNumber = tool),
        [
          opZMin= opinfo(19, toolIndex)
          if (opZMin < toolZMin),
          [
            toolZMin = opZMin
          ]
        ]
        toolIndex = toolIndex + ONE@
        opToolNumber = opinfo(10002, toolIndex)
      ]
      *toolZMin

#endregion End Tooltable

 

Once you have the tool numbers and the line numbers in the stack, you could use something like the below post block to write them out.

#Start Array
stackSize  : 0
popResult  : 0
#End Array

#Start Array
toolNumber : 0
lineNumber : 0
#End Array

fmt "N"    4 lineNumber

matchFound : no$

pGetLineNumber
      matchFound = no$
      stackSize = pop(1, popResult, 0)
      while (stackSize > 0),
      [
        toolNumber = pop(1, stackSize, 5)
        if (t$ = toolNumber), matchFound = yes$
        if (matchFound),
        [
          stackSize = 0
          *lineNumber, e$
        ]
        else, stackSize = stackSize - 1
      ]

This would need to be refined a bit to meet your goals.  I'd be happy to talk more about solving this problem, send me an email if you'd like.

 

  • Like 1
Link to comment
Share on other sites
3 minutes ago, jeff.D said:

I think this would work with some minor tweaks (depending on what you wanted the line numbers to be).  In this example we'll make them the offset.


#region Tooltable

s1013            : ""
stoolString      : ""

fprmtbl 1 2
        1013   s1013
        10094  stoolString

fmt "DIAMETER - "    3 toolDiameter
fmt "MAX Z DEPTH: "  3 toolZMin
fmt "TOOL NUMBER - " 4 tt_tool$
fmt "N"              4 tt_tlngno$

#Start Array
stackTool : 0
stackLine : 0
#End Array

pushResult : 0

fstack 1 2

ptooltable$
      if (tt_count$ = TOOL_NOT_OUTPUT@),
      [
        return = fprm(ONE@, OP_PARAMETERS@)
        toolDiameter = rparsngl(s1013, TWO@)
        stoolString = ucase(stoolString)
        n$, scommentStart, *tt_tool$, "|", *tt_tlngno$, "|", stoolString, "|", *toolDiameter, "|", pGetToolsMinimumZ(tt_tool$), no_spc$, scommentEnd e$
        stackTool = tt_tool$
        stackLine = tt_tlngno$
        stackTool = push(1, pushResult, 0)
      ]

opZMin       : 0
tool         : 0
toolIndex    : 0
opToolNumber : 0

pGetToolsMinimumZ(tool)
      toolIndex = ZERO@
      toolZMin = ZERO@
      opToolNumber = opinfo(10002, toolIndex)
      while (opToolNumber <> QUERY_INVALID@),
      [
        if (opToolNumber = tool),
        [
          opZMin= opinfo(19, toolIndex)
          if (opZMin < toolZMin),
          [
            toolZMin = opZMin
          ]
        ]
        toolIndex = toolIndex + ONE@
        opToolNumber = opinfo(10002, toolIndex)
      ]
      *toolZMin

#endregion End Tooltable

 

Once you have the tool numbers and the line numbers in the stack, you could use something like the below post block to write them out.


#Start Array
stackSize  : 0
popResult  : 0
#End Array

#Start Array
toolNumber : 0
lineNumber : 0
#End Array

fmt "N"    4 lineNumber

matchFound : no$

pGetLineNumber
      matchFound = no$
      stackSize = pop(1, popResult, 0)
      while (stackSize > 0),
      [
        toolNumber = pop(1, stackSize, 5)
        if (t$ = toolNumber), matchFound = yes$
        if (matchFound),
        [
          stackSize = 0
          *lineNumber, e$
        ]
        else, stackSize = stackSize - 1
      ]

This would need to be refined a bit to meet your goals.  I'd be happy to talk more about solving this problem, send me an email if you'd like.

 

Awesome thank you for teaching me this new way to go about it. I will be emailing you since I have to do what PCRobotic has been working for some posts. Customer wants a novel for each program for the Tool List and then for each tool change.

Link to comment
Share on other sites

In hindsight, a better way would be to use the tt_op_id$ value as the 'key' for the line number in the stack.


#Start Array
stackOpID : 0
stackLine : 0
#End Array

pushResult : 0

fstack 1 2

ptooltable$
      if (tt_count$ = TOOL_NOT_OUTPUT@),
      [
        return = fprm(ONE@, OP_PARAMETERS@)
        toolDiameter = rparsngl(s1013, TWO@)
        stoolString = ucase(stoolString)
        n$, scommentStart, *tt_tool$, "|", *tt_tlngno$, "|", stoolString, "|", *toolDiameter, "|", pGetToolsMinimumZ(tt_tool$), no_spc$, scommentEnd e$
        stackOpID = tt_op_id$
        stackLine = tt_tlngno$  # This could be any value you'd like, it is now 'keyed' to the op_id$ value in the stack
        stackOPID = push(1, pushResult, 0)
      ]

We'd also have to make a slight change to our pGetLineNumber post block

#Start Array
stackSize  : 0
popResult  : 0
#End Array

#Start Array
opID       : 0
lineNumber : 0
#End Array

currentOpID : 0

fmt "N"    4 lineNumber

pGetLineNumber(currentOpID)  # Pass the current op_id$ value to pGetLineNumber as an argument; pGetLineNumber(op_id$) 
      stackSize = pop(1, popResult, 0)
      while (stackSize > 0),
      [
        opID = pop(1, stackSize, 5)
        if (currentOpID = opID),
        [
          stackSize = 0
          *lineNumber, e$
        ]
        else, stackSize = stackSize - 1
      ] 
  • Like 1
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...