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:

Function arguments


Recommended Posts

I remember reading that MP post now finally supports function arguments (Hooray!), "function" here being the same as "post block", assumedly.

Is there any examples of usage? I want to apply this neat feature to a post block called "replace scandic characters with non scandic ones" that takes a global temporary variable as input.

Does it support return values yet?

Link to comment
Share on other sites
12 minutes ago, SlaveCam said:

I remember reading that MP post now finally supports function arguments (Hooray!), "function" here being the same as "post block", assumedly.

Is there any examples of usage? I want to apply this neat feature to a post block called "replace scandic characters with non scandic ones" that takes a global temporary variable as input.

Does it support return values yet?

 

5 minutes ago, Zaffin_D said:

You are out luck on both counts.

Strings can’t be passed as arguments.

MP post blocks can only operate on arguments; they cannot truly return a value.

Maybe you can input the string into a custom c++/c# application, then output the result into a text file where the post can read it?

There was a similar topic I saw on Mastercam.com post area about custom applications taking string arguments.

Just throwing Ideas around..

Link to comment
Share on other sites
30 minutes ago, Zaffin_D said:

That would work, but in my testing repeatedly using the launch or dll function will make the posting time much longer.

Perhaps using inline functions would help? Was this done in an managed or unmanaged environment? Or both?

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

Perhaps using inline functions would help? Was this done in an managed or unmanaged environment? Or both?

I've tried this both managed and native add-ins. The result is the same; MP takes time to spool up the process.  Also because of the serial nature of MP, nothing is happing until the called app returns.  It's not a big deal if you are doing it a handful of times, but it can get bothersome. 

In this case (parsing a string) MP's regex function would be very useful and much quicker than sending it out to an external app. 

Not to derail this, but I think you should look into what inline-ing does.

Link to comment
Share on other sites
15 minutes ago, Zaffin_D said:

I've tried this both managed and native add-ins. The result is the same; MP takes time to spool up the process.  Also because of the serial nature of MP, nothing is happing until the called app returns.  It's not a big deal if you are doing it a handful of times, but it can get bothersome. 

In this case (parsing a string) MP's regex function would be very useful and much quicker than sending it out to an external app. 

Ah okay, so it's an MP issue, and MP's Native "Regex" functions can do the translation?

15 minutes ago, Zaffin_D said:

Not to derail this, but I think you should look into what inline-ing does.

Hmm okay, I see, so it's a compiler thing and would not apply here..  sometimes I misinterpret things, thanks..

Link to comment
Share on other sites

One thing that you could try is defining two string values, an input variable and an output variable.

Instead of passing it as a variable, you set the value of the input variable immediately before calling the function. The function will then use this variable to modify the value of the output variable.

For example:

sinput : ""
soutput : ""

pfunction
      soutput = regex(sregexExpression, sinput, 2)

potherPostBlock
    sinput = "Whatever"
    pfunction
    result = mprint(soutput)

 

  • Like 1
Link to comment
Share on other sites

I'm not familiar with scandic characters, so I grabbed some random non-ascii ones for this example.

s_return           : ""
s_replacement_char : ""

flktbl 1 4
    "A" "Ä"
    "E" "Ë"
    "I" "Ï"
    "O" "Ö"

s_string           : "STRÏNG ÖF MÏXËD CHÄRÄCTERS"

p_sanitize_s_string
    s_return = regex("([^\x00-\x7F])", s_string, 0)
    while strlen(s_return),
        [
        s_replacement_char = flook(1, s_return)

        s_string = regex(s_return, s_replacement_char, 2)

        s_return = regex("([^\x00-\x7F])", s_string, 0)
        ]

psof$
    "BEFORE: ", s_string, e$
    p_sanitize_s_string
    *e$
    "AFTER:  ", s_string, e$

Sample output

BEFORE:  STRÏNG ÖF MÏXËD CHÄRÄCTERS

AFTER:   STRING OF MIXED CHARACTERS

 

You would have to add all the replacement characters to the look up table, and if the replacements are outside the ascii range the regex would need to be modified; but you get the idea.  

  • Like 1
Link to comment
Share on other sites

Thanks to all. Maybe it sounded too good to be true.

I wasn't aware of regex function. Good to know that at least it is there.

My replacement function works without regex, but works only for Ä and Ö, which are the most common

#region replace_scandics
stmpstr  : ""
stmpstr2 : ""
stmpstr3 : ""
ival     : 0

preplace_scandics #stmpstr is both input and output. input must be in upper case.
    #Replace Ä->A
    ival = strstr("Ä", stmpstr)
    while ival > 0,
    [
        stmpstr2 = brksps(ival, stmpstr)
        stmpstr3 = brksps(2, stmpstr2)
        stmpstr = stmpstr + "A" + stmpstr3
        ival = strstr("Ä", stmpstr)
    ]

    #Replace Ö->O
    ival = strstr("Ö", stmpstr)
    while ival > 0,
    [
        stmpstr2 = brksps(ival, stmpstr)
        stmpstr3 = brksps(2, stmpstr2)
        stmpstr = stmpstr + "O" + stmpstr3
        ival = strstr("Ö", stmpstr)
    ]
#endregion

 

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