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:

Help Modifying my Mill Post


Guess_who
 Share

Recommended Posts

I am trying to update some of our posts to utilize all of the custom Fanuc macros we use here. So what I need to be able to do is pull out the individual letters, numbers or Characters from the operation comment so that I can convert it to an integer and use it in our custom macro. I know how do all of the logic needed the only thing I cannot find is a way to put each character from the comment into its own string variable. Similar to how the plcval function works for numbers.

 

For example: If the operation comment is “ 12345-12 REV A” I would need to identify each character and assign it to its own string variable.

 

I do know how to use the brksps function, but that will only take a string and divide it at a location into two strings.

 

I have the last three versions of MasterCam installed on my box up to and including X7 B3, but our Company is still officially using X6 MU3. Unfortunately my post reference manuals are from X5. I am really hoping there is a list of new functions that are available for X6 or even X7

 

Or maybe something like this would be easier using a Nethook? I have never created a Nethook, and I’m not sure I even have all of the licensing or software needed to make one. But I could do some research.

 

Thanks

 

Ray

Link to comment
Share on other sites

The scan function will search a comment for a specific string, and assign the associated value to a variable.

 

Yes, because the scan function can give a placement of the match found, I figure there was another command that could read the variable given a placement to look. But I have not been successful in finding any command that will do this.

 

Thanks for the reply

Link to comment
Share on other sites

Ok, I'll bite.

 

You can break the string up into a string array with a combination of functions. We don't have a 'pcval' function that works on strings the way you are asking for.

 

Take a look at this sample code and see if it gives you what you want. I just mocked this up real quick, so it could need some more modification/testing.

 

sinput_str : "12345-12 REV A"
#Implied String Array for comment while loop
str0   : "***"
str1   : "***"
str2   : "***"
str3   : "***"
str4   : "***"
str5   : "***"
str6   : "***"
str7   : "***"
str8   : "***"
str9   : "***"
str10   : "***"
str11   : "***"
str12   : "***"
str13   : "***"
str14   : "***"
str15   : "***"
str16   : "***"
str17   : "***"
str18   : "***"
str19   : "***"
str20   : "***"
slength_error   : "ERROR - YOUR STRING HAS MORE THAN 20 CHARACTERS."
strtemp : ""
length  : 0  #Holds string length
counter : 1  #Start offset at str1 (offset 1 from str0)
result  : 0
pmacro    #Breaks strings into character array.
  length = strlen(sinput_str) #Get length of input string
  if length > 20,
    [
    result = mprint(slength_error)
    slength_error, e$ #Write error message to NC file
    exitpost$
    ]
  while length > 0, #Loop through the string and break it into array
    [
    strtemp = brksps(2, sinput_str)  #Break input string at first character
    sinput_str = slin(counter, str0) #Load character into array
    counter = counter + 1 #Increment counter
    sinput_str = strtemp #Load remaining string back into sinput_str
    length = length - 1 #Decrement string length for while loop before exiting
    ]
psof$ #Entry into post
  pmacro
  spaces$ = 0
  "STRING 1 >", str1, e$  
  "STRING 2 >", str2, e$  
  "STRING 3 >", str3, e$
  "STRING 4 >", str4, e$
  "STRING 5 >", str5, e$
  "STRING 6 >", str6, e$
  "STRING 7 >", str7, e$
  "STRING 8 >", str8, e$
  "STRING 9 >", str9, e$
  "STRING 10 >", str10, e$
  "STRING 11 >", str11, e$
  "STRING 12 >", str12, e$
  "STRING 13 >", str13, e$
  "STRING 14 >", str14, e$
  "STRING 15 >", str15, e$
  "STRING 16 >", str16, e$
  "STRING 17 >", str17, e$
  "STRING 18 >", str18, e$
  "STRING 19 >", str19, e$
  "STRING 20 >", str20, e$

 

 

When I used that in a post and ran it, here is the output I got:

 

STRING 1 >1
STRING 2 >2
STRING 3 >3
STRING 4 >4
STRING 5 >5
STRING 6 >-
STRING 7 >1
STRING 8 >2
STRING 9 >
STRING 10 >R
STRING 11 >E
STRING 12 >V
STRING 13 >
STRING 14 >A
STRING 15 >***
STRING 16 >***
STRING 17 >***
STRING 18 >***
STRING 19 >***
STRING 20 >***

 

I initialized the strings in the array to "***", so I could tell when a string was actually written too vs. just being blank because it was initialized that way...

 

So that's the first part for you. Now you need to figure out what to do with those strings: what kind of output do you need to generate?

 

Hope that helps,

 

Colin

Link to comment
Share on other sites

Ok, we got a similar question here in the post department, so here is some additional information that should give you everything you need.

 

You can use a lookup table in MP with a string character as "input", and have it return a numeric value (from the first column).

 

flktbl 100 95
 32 " "
 33 "!"
 34 '"'
 35 "#"
 36 "$"
 37 "%"
 38 "&"
 39 "'"
 40 "("
 41 ")"
 42 "*"
 43 "+"
 44 ","
 45 "-"
 46 "."
 47 "/"
 48 "0"
 49 "1"
 50 "2"
 51 "3"
 52 "4"
 53 "5"
 54 "6"
 55 "7"
 56 "8"
 57 "9"
 58 ":"
 59 ";"
 60 "<"
 61 "="
 62 ">"
 63 "?"
 64 "@"
 65 "A"
 66 "B"
 67 "C"
 68 "D"
 69 "E"
 70 "F"
 71 "G"
 72 "H"
 73 "I"
 74 "J"
 75 "K"
 76 "L"
 77 "M"
 78 "N"
 79 "O"
 80 "P"
 81 "Q"
 82 "R"
 83 "S"
 84 "T"
 85 "U"
 86 "V"
 87 "W"
 88 "X"
 89 "Y"
 90 "Z"
 91 "["
 92 "\"
 93 "]"
 94 "^"
 95 "_"
 96 "`"
 97 "a"
 98 "b"
 99 "c"
 100 "d"
 101 "e"
 102 "f"
 103 "g"
 104 "h"
 105 "i"
 106 "j"
 107 "k"
 108 "l"
 109 "m"
 110 "n"
 111 "o"
 112 "p"
 113 "q"
 114 "r"
 115 "s"
 116 "t"
 117 "u"
 118 "v"
 119 "w"
 120 "x"
 121 "y"
 122 "z"
 123 "{"
 124 "|"
 125 "}"
 126 "~"
strtemp : ""
number : 0 #number from lookup table
str1 : "<"
pheader$		 #Call before start of file						
 strtemp = str1
 number = flook(100, strtemp)
 "RESULT: ", *number, e$

 

Just make sure you define your lookup table ahead of the call to 'flook', and you should be all set. Note that you could also build the first column values as "strings" by including them in quotes, and have the function return a string value instead of numeric. Just make sure your return variable is defined as a string variable. Some food for thought.

 

Running the above code in 'pheader$' returned the value of '60' for the output of 'number'. You'll also need to include a Format Assignment for the 'number' return variable if you want to output it...

 

Hope that helps,

 

Colin

Link to comment
Share on other sites

Glad I could help. :)

 

The same thing that is true about Mastercam is also true about MP; there is always a way to get the job done.

 

I'm happy because I also learned something new. I always thought Lookup tables were restricted to numeric values only (they used to be!). They were enhanced sometime a while back to also allow strings as input or output. This, as you can see, was a very useful enhancement.

 

I'd encourage you to look at the help descriptions in Volume 3 of the MP Post Guide for the following functions:

 

slin

slout

vlin

vlout

 

'vlin' and 'vlout' are used to read/write numeric variables to an implied array, and 'slin'/'slout' are used to read/write string variables...

 

Cheers,

 

Colin

Link to comment
Share on other sites

Awesome suggestions, thanks everyone. I think I will go back and redo some of this and try some of everyone's suggestions. Mine works, but I wouldn't mind trying some of the other suggestions to clean it up a bit.

 

Right now I am working on trying to weed out the characters that wont work in a comment on a Fanuc Makino D500. I'll just do a test for specific character and replace them in the comment line but I'll still convert to a integer to preform the engraving.

 

Here is what I have right now.

 

pengraving_macro

 

engrave_counter = 1

IJK_counter = 1

engrave_length = strlen(sengrave_comment)

IF engrave_length > 30,

[

"( *** TOO LONG - MUST BE UNDER 30 *** IS= ", *engrave_length, "***)"

engrave_length = 0

]

while engrave_counter < engrave_length + 1,

[

sengrave_letter = brksps(2, sengrave_comment)

pengraving_macro2

 

IF IJK_counter = 1, *P9970_I

IF IJK_counter = 2, *P9970_J

IF IJK_counter = 3, *P9970_K

 

sengrave_comment = sengrave_letter

engrave_counter = engrave_counter + 1

IJK_counter = IJK_counter + 1

IF IJK_counter > 3, IJK_counter = 1

]

 

 

 

pengraving_macro2

IJK_ascii_holder = 999.

if sengrave_comment = "0", IJK_ascii_holder = 0

if sengrave_comment = "1", IJK_ascii_holder = 1

if sengrave_comment = "2", IJK_ascii_holder = 2

if sengrave_comment = "3", IJK_ascii_holder = 3

if sengrave_comment = "4", IJK_ascii_holder = 4

if sengrave_comment = "5", IJK_ascii_holder = 5

if sengrave_comment = "6", IJK_ascii_holder = 6

if sengrave_comment = "7", IJK_ascii_holder = 7

if sengrave_comment = "8", IJK_ascii_holder = 8

if sengrave_comment = "9", IJK_ascii_holder = 9

if sengrave_comment = "A", IJK_ascii_holder = 101

if sengrave_comment = "B", IJK_ascii_holder = 102

if sengrave_comment = "C", IJK_ascii_holder = 103

if sengrave_comment = "D", IJK_ascii_holder = 104

if sengrave_comment = "E", IJK_ascii_holder = 105

if sengrave_comment = "F", IJK_ascii_holder = 106

if sengrave_comment = "G", IJK_ascii_holder = 107

if sengrave_comment = "H", IJK_ascii_holder = 108

if sengrave_comment = "I", IJK_ascii_holder = 109

if sengrave_comment = "J", IJK_ascii_holder = 110

if sengrave_comment = "K", IJK_ascii_holder = 111

if sengrave_comment = "L", IJK_ascii_holder = 112

if sengrave_comment = "M", IJK_ascii_holder = 113

if sengrave_comment = "N", IJK_ascii_holder = 114

if sengrave_comment = "O", IJK_ascii_holder = 115

if sengrave_comment = "P", IJK_ascii_holder = 116

if sengrave_comment = "Q", IJK_ascii_holder = 117

if sengrave_comment = "R", IJK_ascii_holder = 118

if sengrave_comment = "S", IJK_ascii_holder = 119

if sengrave_comment = "T", IJK_ascii_holder = 120

if sengrave_comment = "U", IJK_ascii_holder = 121

if sengrave_comment = "V", IJK_ascii_holder = 122

if sengrave_comment = "W", IJK_ascii_holder = 123

if sengrave_comment = "X", IJK_ascii_holder = 124

if sengrave_comment = "Y", IJK_ascii_holder = 125

if sengrave_comment = "Z", IJK_ascii_holder = 126

if sengrave_comment = " ", IJK_ascii_holder = 127

if sengrave_comment = ".", IJK_ascii_holder = 128

if sengrave_comment = "-", IJK_ascii_holder = 129

if sengrave_comment = "*", IJK_ascii_holder = 130

if sengrave_comment = "/", IJK_ascii_holder = 131

if sengrave_comment = "=", IJK_ascii_holder = 132

if sengrave_comment = "#", IJK_ascii_holder = 133

if sengrave_comment = "(", IJK_ascii_holder = 134

if sengrave_comment = ")", IJK_ascii_holder = 135

if sengrave_comment = "@", IJK_ascii_holder = 150

if sengrave_comment = "$", IJK_ascii_holder = 98

if sengrave_comment = "%", IJK_ascii_holder = 99

if sengrave_comment = "?", IJK_ascii_holder = 100

 

P9970_I = IJK_ascii_holder

P9970_J = IJK_ascii_holder

P9970_K = IJK_ascii_holder

 

 

 

Here is a sample posted out.

 

N1 T22013070 M6

( T22013070 = .125 DIA. BULL MILL -R.01 )

(*** TEST 12345-0 ( ) )

S8500 M3

G00 G53 G90 Z26.

G0 G90 G54

G65 P9999 A1. B0.

X-3.3186 Y1.4861

G43 H1 D2 Z10. M8

(** ENGRAVE = ) TEST 12345-0 ( )

X-3.3186 Y1.4861

R.1

G01 Z.093 F8.

G65 P9970 A5. B.125 C10. I120. J105. K119. I120. J127. K1. I2. J3. K4. I5. J129. K0. I127. J134. K127. I135.

Z10.

G0 G80 M9

M98 P8888

M01

M30

Link to comment
Share on other sites

I'm glad it worked for you Ray. :)

 

I learned something new as well.

 

You could probably take any characters in the Lookup table that aren't allowed, and change the return value from the ASCII number (which is what I used for the return values) to '999'. Then add some logic to check the value, and report an error if a character was used that is not allowed.

 

By the way, you can use the Command Variable 'ex$' to exit a post block loop. So in your 'while' loop, you could add a line of code to do a Boolean 'If' statement, and exit the 'while' loop if that condition is true with the 'ex$' command.

 

Here is some pseudo-code:

 

pmyblock
 while (condition is false),
 [
 code
 code
 code
 if return = 999, ex$
 ]

Link to comment
Share on other sites

Awesome advice. Thanks again.

 

Since we're on the topic, I am trying to use the scan function to search for a "(" or a ")" within the comment so that I can flag it as not allowed because the Fanuc might bomb out on it. But it seems like I am not using it right. Here is some simple code example

 

sengrave_comment = the operational comment

sbad_ascii1 = ")"

 

if scan(sengrave_comment,sbad_ascii1)<>-9999, "(found bad character)", e

 

No matter what I put in the operational comment it always equals -9999 which as my post book says mean "No match found "

 

 

And thanks again for all the help. I happen to have a few days until I'll be assigned another project and I'd figure I'd play a little and learn something in the process. First break in years.

 

Ray

Link to comment
Share on other sites

Hello Ray,

 

Could you post your sample code again, but use the "code" button in the reply options? I'd like to see where you are getting the operation comment. (You need to use the 'comment$' command variable, and process the comments through the pcomment$/pcomment2 post blocks, and catch gcode$ = 1008 for the operation comment. For all comments, the string will be held in 'scomm$'.)

 

Try creating a string variable in the post, initialized to a string you type in. Then run the scan function with that string.

 

Also, try creating a numeric return variable, and using the scan function without the boolean. "result = scan(string1, string2)"

Then output the 'result' variable and see if you are getting the expected results. (I'll check the function tomorrow and see what isn't working)

 

Hi Ron,

 

I'll suggest that the sample code get added to our documentation, and more importantly, that the function description is revised to note the new functionality that is built into the lookup table now.

 

Thanks,

 

Colin

Link to comment
Share on other sites

Hello Colin. Here is my comment section where I am performing the scan and the outputted code.

 

Right now "scheck_error1" is defined as a ")"

 

pcomment$	 #Comment from manual entry (must call pcomment2 if booleans)
 if (modheader = 0), pcomment3
 else, pcomment2
pcomment2	 #Comment from manual entry

 scomm$ = ucase(scomm$)
 pcomment4

 if gcode$ = 1007, "(", scomm$, ")"
 else, "(", scomm$, ")", e$
pcomment3
 scomm$ = ucase(scomm$)	
 if gcode$ = 1006, scomm$, e$
 if gcode$ = 1005, "(", scomm$, ")", e$
 if gcode$ = 1007, "(", scomm$, ")"
 if gcode$ = 1008,
		 [
		 pcomment4
		 string1008 = scomm$
		 ]
pcomment4
 sengrave_comment = scomm$
 comment_error = scan(sengrave_comment,scheck_error1)
 e$
 "(*** SCAN RESULTS =", *comment_error, e$
 e$

 

 

 

 

Outputted Code:

 

 

%
O0000
(*** SCAN RESULTS =-9999.
( LAST SAVED )
( B2 PROGRAM NUMBER = 0000 .NC )
G20 G0 G17 G40 G80
G90 G10 L2 P1 X0 Y0 Z0 B0
G11
T22013070
M98 P8888
M01
N1 T22013070 M6
( T22013070 = .125 DIA. BULL MILL -R.01 )
( () )
S8500 M3
G00 G53 G90 Z26.
G0 G90 G54
G65 P9999 A1. B0.
X-3.3186 Y1.4861
G43 H1 D2 Z10. M8
X-3.3186 Y1.4861
R.1
G01 Z.093 F8.
( ENGRAVE = () )
G65 P9970 A5. B.125 C10. I999. J999.
(** CHARACTER(S) NOT FOUND SEE 999'S)
Z10.
(*** SCAN RESULTS =-9999.
( () )
X-3.3186 Y1.4861
R.1
G01 Z.093 F8.
( ENGRAVE = () )
G65 P9970 A5. B.125 C10. I999. J999.
(** CHARACTER(S) NOT FOUND SEE 999'S)
Z10.
G0 G80 M9
M98 P8888
M01
M30

%

 

The "CHARACTER(S) NOT FOUND SEE 999'S" is a separate check I do that will put a 999 in the macro if it finds a character that is not in the defined table. The 999 will kick out an operator message and leave a space for a special character to be programmed manually

Link to comment
Share on other sites

My work-around for this was to use the brackets "[" and "]" in order to engrave the parentheses "(" and ")".

 

The control can hand having the brackets in the comments, so it's a non issue. I would still be interested in learning why the scan function wasn't working for me.

 

So as it stands right now everything is working great. In order to use our in-house custom engraving macros on of Makinos, I only have to type what I want engraved in the operation comment field. That information gets translated and put into our macro.

 

Our macro line looks something like this

 

G65 P9970 A0. B.125 I134. J127. K123. I115. J118. K111. I119. J127. K107. I118. J105. K101. I120. J127. K135.

 

That will engrave "( WORKS GREAT )"

 

I want to thank Colin for all the help.

Link to comment
Share on other sites

Hi Ray,

 

Thanks for the compliments, I'm glad you got your macro working.

 

I figured out the problem with your use of the 'scan' function. Scan only looks for numeric values in String! So that's why you are always getting -9999, because you are looking for a string character, not a numeric value.

 

I'll see if we can update the 'Scan' documentation to make clear that it searches for numeric values in a string...

 

Try using the function 'strstr', which searches a string (2nd argument), to see if the 1st string argument is a sub-string.

 

You must use a numeric return variable, and that variable gives you the index position of where that character was found.

 

Here is some test code:

str1 : "***"
strtemp : ""
result : 0
psof$ #Entry into post
 strtemp = "abcde(fghijklmnop"
 str1 = "("
 result = strstr(str1, strtemp)
 *e$
 "*** SCAN RESULTS =", no_spc$, *result, e$
 "*** st_str_ix value=", no_spc$, st_str_ix$, e$
 "*** end_str_ix value=", no_spc$, end_str_ix$, e$


 

That code gave me this output:

 

*** SCAN RESULTS =result 6.
*** st_str_ix value=st_str_ix$ 6.
*** end_str_ix value=end_str_ix$ 7.

 

As you can see, the 'result' variable value of '6.' was identical to the value held in the helper variable 'st_str_ix$', and the value of 'end_str_ix$' was '7.', which is the index position after the sub-string. (in this case, the sub-string is a single character, so that makes perfect sense)

 

Also, if the sub-string is not found in the string being searched, the return value would be '0.', so I'd use that as the condition to search for in my boolean statement.

 

(if strstr(str1, str2) = zero, pdosomething)

or

(if strstr(str1, str2) <> zero, pdosomething)

 

So, that is the reason 'Scan' wasn't working, because the description in the help file needs to be corrected.

 

Hope that helps,

 

Colin

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...