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:

Array Variables


Recommended Posts

Hi Kevin,

 

What are you trying to do with your Array?

 

The MP Language does not define "Arrays" like a modern Object Oriented language. Especially important to understand is that an "array" in MP is just a static list of numeric variables. There is nothing to indicate to the MP Language that an array exists. All functions that use arrays (Vector or Matrix Math function require either 3 or 9 variables) do so by specifying the start of the array as one of the function parameters.

v1_x : .34546
v1_y : .21546
v1_z : .87548

v2_x : 0
v2_y : 0
v2_Z : 0


panyblock   #User Defined Post Block
      v2_x = vequ(v1_x)

Consider the code above. I've defined two lists of variables, each containing 3 unique variable names. We could use the three variables listed for example to represent the endpoint of a vector. The line of code that I added to the 'panyblock' post block is the "vector equate" function. That function copies three numeric values from an array, into another array of three variables.

 

You'll notice that we only use the first variable name in the array list as the return argument (v2_x). Then the argument passed to the 'vequ' function is the first variable in an array list that we want to copy (v1_x).

 

Also important to note that you cannot "re-define" an array in MP. So once you create the list of variables, that defines the size of the array, and you can't change it dynamically.

 

The same is also true with Buffer Files. These files get defined during the parsing of the post, and you can't "redefine" the size. (Buffer Files are very powerful, and do give you some unique ways of storing, sorting, and retrieving data through.)

Link to comment
Share on other sites
bigprody, on 01 Aug 2014 - 09:35 AM, said:bigprody, on 01 Aug 2014 - 09:35 AM, said:

Thanks EX.

 

Buffers are new to me, would you mind helping a brother out?

 

Take a look at Generic Fadal Format_1 4X Mill.pst that came with Mastercam.  It has 2 buffer files that are used.  You can figure out how they define it, and how it is used.  The MP Documentation is not very detailed in this area, you kind of need to figure a lot out on your own.

 

I can't explain everything involved here, it would take a long time.  But if you get stuck on something, just ask.  Good Luck!  :cheers:

 

PS - Search the above pst file for fbuf and you will find the buffer definitions.

Link to comment
Share on other sites

Thanks for the explination Colin. Here is what I would like to accomplish.

 

We have a very specific work flow from the posted code to our machine. We build stamping dies here. I run a 2 pallet Matsuura and every part thru the machine is one off. To facilitate a quick work flow we have built extensive tool and operation libraries and keep stock on hand of these 800 or so tools. Each tool has an ID number which we use the "Manufactures Tool Code Field" in the tool parameters page to hold the value. I wrote an App for windows that keeps track of the tools in our machine using the ID #. When we load up our code into the app it pulls all of the ID #'s and compares them to what is in the tool carousel. It reorganizes our tools in program to match the machine thus saving us alot of editing.

 

We run lights out every night combining longer running details. I am now starting to combine these programs in Mastercam. The limit that we have with these multiple setups is the size of our toolchanger. So what I would like to do is inside of mastercam pull 3 or 4 details into one file, run the code, have the post count how many different ID#s the now rather large program has and output the result in a comment at the end of the file. I can easly maximize the night run that way by using as much of the tool changer as possible.

 

How I would handle this in VB would be to build an array holding the ID#s checking so none were added twice and then the size of the array is my tool count.

 

Possible in MP Language?

Link to comment
Share on other sites

If I may offer an alternative, you can achieve what you desire by capturing the ID# as a string, searching the tools_used string for that ID#, and concatenating the tools_used string the ID# if not found.  Use a simple counter to count the times the ID# is not found, and report the counter at the end of program.

Link to comment
Share on other sites

Thanks for the explination Colin. Here is what I would like to accomplish.

 

We have a very specific work flow from the posted code to our machine. We build stamping dies here. I run a 2 pallet Matsuura and every part thru the machine is one off. To facilitate a quick work flow we have built extensive tool and operation libraries and keep stock on hand of these 800 or so tools. Each tool has an ID number which we use the "Manufactures Tool Code Field" in the tool parameters page to hold the value. I wrote an App for windows that keeps track of the tools in our machine using the ID #. When we load up our code into the app it pulls all of the ID #'s and compares them to what is in the tool carousel. It reorganizes our tools in program to match the machine thus saving us alot of editing.

 

We run lights out every night combining longer running details. I am now starting to combine these programs in Mastercam. The limit that we have with these multiple setups is the size of our toolchanger. So what I would like to do is inside of mastercam pull 3 or 4 details into one file, run the code, have the post count how many different ID#s the now rather large program has and output the result in a comment at the end of the file. I can easly maximize the night run that way by using as much of the tool changer as possible.

 

How I would handle this in VB would be to build an array holding the ID#s checking so none were added twice and then the size of the array is my tool count.

 

Possible in MP Language?

 

When you say "count how many different ID numbers", what are you referring too? Can we just count the number of unique tools used in the program? Do we have to count based on the MFG Tool Code? Are there cases where you might have 2 different "T11", but they have different MFG Tool Code?

 

If you are taking multiple programs, merging them together, then posting them all as a single program, then we might be able to make this really simple.

 

If all you want to do is check to see if there are above a certain number of tools used, then you can do something like this:

ptlchg1002$
      if ntools$ > 30,
        [
        result = mprint ("The number of tools used is greater than 30.")
        result = mprint ("The number of tools used will be displayed next.")
        result = mprint (ntools$)
        ]

The code above would just check the number of unique tools used (regardless of the tool number assigned) and warn you if there were above 30 tools used. You could modify this number of course.

 

Hope that helps,

 

Colin

Link to comment
Share on other sites

It took a few reads, but I think I see what he is saying. He wants mastercam to combine three or four programs for three or four different parts (details) and then build a tool list. If the programs use the same tool, he wants mastercam to only count the tool once. So if the tool is used on four different parts, it doesn't come up in the tool list four different times. Then he takes this list, loads up his carousel, and has his app change the tool numbers in the programs to match how he loaded the carousel.

 

...so basically all he is looking for is a tool list across several programs. Seem right?

Link to comment
Share on other sites

That is it Cathedral, I think I have enough to get started on this I will post once I have it figured out or if I need some more help, which will be more likely. I have not used these forums much but when I have everyone, on here has allways been very helpful, it is nice to have such a large community of knowledge to tap.

Link to comment
Share on other sites

In the documentation that I have there are 4 parameters for defining buffers.

 

 

# --------------------------------------------------------------------------

#Buffer 5, testing to store misc real values

wc5 : 1                     #Initial count for write buffer 5

rc5 : 1                        #Initial count for read buffer 5

size5 : 0                    #Buffer 5 size

g10z : 1                     #Saved mr9$ value

g10x : 1                     #Saved mr10$ value

gten_tool : 1               #Tool number capture

fbuf 5 0 3 0 0

# --------------------------------------------------------------------------

 

 

The examples that I see here seem to have 5 Parameters as per the above.

Link to comment
Share on other sites

In the documentation that I have there are 4 parameters for defining buffers.

 

 

# --------------------------------------------------------------------------

#Buffer 5, testing to store misc real values

wc5 : 1                     #Initial count for write buffer 5

rc5 : 1                        #Initial count for read buffer 5

size5 : 0                    #Buffer 5 size

g10z : 1                     #Saved mr9$ value

g10x : 1                     #Saved mr10$ value

gten_tool : 1               #Tool number capture

fbuf 5 0 3 0 0

# --------------------------------------------------------------------------

 

 

The examples that I see here seem to have 5 Parameters as per the above.

 

Technically, the only parameters that "define" the buffer are rcx, wcx, sizex, and fbuf x x x x x

 

the "5" after rc, wc, size, and fbuf is what defines the buffer number; so if you only have one buffer, it would be rc1. If it's the fifth buffer table you've made, it would be rc5.

 

The "g...." variables are the variables that are going to be stored inside the buffer, and those can be whatever variables you want as long as you have properly defined them.

 

For example, I have a buffer table that I use to write out macros:

 

#--------------------------------------------------------------------------

#BUFFER DEFINITION FOR HOLE MACRO

#--------------------------------------------------------------------------

 

wc1    :1

rc1    :1

size1    :0

 

#Hole information

tool    :0

chip    :0

dpth    :0

hole    :0

strt    :0

fdmacro    :0

 

fbuf 1 0 6 0 0

 

 

Notice how in both examples following "fbuf" the first number is the buffer number, and the third number is how many variables you are going to define inside that buffer. Honestly I'm not sure what the other zeroes are for; I only have a limited knowledge of buffers. I can get them to work but I'm far from being an expert.

 

But I'm wondering if you even need to write a buffer. I mean, your post should already be able to output a tool table as long as you turn it on in your control definition. You might save yourself a headache by just flipping a switch.

Link to comment
Share on other sites

I agree with Cathedral, a buffer is probably more work than is needed for what you want.

 

If you do decide to use a buffer, you need to create variables to hold the data contained in the buffer.  I normally incorporate the buffer ID into the variable names used in that buffer to help me keep the buffers straight.  For example, I use gcode_buf1 to hold the value of gcode$ in buffer 1.  You can define and use as many variables as you like, but you must define them in the structure of the buffer initialization.

 

After you define the buffer, you need code to populate values into it, like this:

 

 

 

pbufwrt       #Write to Buffer
      [
       b1_gc = gcode$
       b1_x = xnci$
       b1_y = ynci$
       b1_z = znci$
       b1_nxt_tl = next_tool$
      ]
      size1 = rbuf(1, 0)

 

Then when you are ready to retrieve the data, read it like this:

 

 

pbufrd       #Read From Buffer
      while rc1 <= size1,
      [
       b1_gc = rbuf(1, rc1)
       gcode$ = b1_gc
       xabs = b1_x
       yabs = b1_y
       zabs = b1_z
       next_tool$ = b1_nxt_tl
      ]

 

Hopefully this helps.  :cheers: 
 

 

  • Like 1
Link to comment
Share on other sites

The easier alternative would be like this:

 

sToolsUsed  : ""

sManufacturersID  : ""

ToolsUsed  : 0

ManufacturersIDchk  : 0

 


(In the pparameter$ section)

 

    if prmcode$ = 20002, sManufacturersID = sparameter$     #This is the Manufacturers ID


 

(In psof$ and ptlchg$ sections)

 

ManufacturersIDchk = strstr (sManufacturersID, sToolsUsed)

if ManufacturersIDchk <= 0,

   [

     sToolsUsed = sToolsUsed + ", " + sManufacturersID

     ToolsUsed = ToolsUsed + 1

   ]


(In peof$ section)

 

"(TOOLS USED =", *ToolsUsed, ")", e$

"(COMPLETE LIST OF MANUFACTURERS ID NUMBERS:)", e$

*sToolsUsed, e$


 

Done.

 

***Edited to allow output of complete list of ID #'s.  This string may be very long, and if wrapping is not an option on your machine, it will alarm.  Additional logic could be added to limit the length of the string, and create sToolsUsed2, sToolsUsed3, etc if needed.

Link to comment
Share on other sites

Thanks again guys. I tried the tool table it is a good option but I am looking for something more certain. I will spare you the details but our work flow is quite specific and I am looking  for a solid number and counting the different ID#’s is the best way. Also it will give me a chance to figure out buffers, I can see they will be of some help in some other areas.

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