Control Variable Thru Notes

Control Variable Thru Notes

sevenfive85
Advocate Advocate
1,685 Views
13 Replies
Message 1 of 14

Control Variable Thru Notes

sevenfive85
Advocate
Advocate

I would like to control the "R" value thru notes(see pic).

 

 

example: if i enter #1234 or any number in notes that line would spit out G90G10L12P1R#xxxx anything else it would default back to G90G10L12P1R0.  thank u

0 Likes
Accepted solutions (3)
1,686 Views
13 Replies
Replies (13)
Message 2 of 14

makko74
Collaborator
Collaborator

hi,

 

i would it solve like this:

 

you need a global parameter in your post ( outside of an function ) e.g. var rValue = 0;

 

in the function  onParameter add the code:

case "notes":
    if (value != "") {
      if ( value.indexOf("#") > -1 ) {
        var test = value.split("\n");
        for ( var i=0; i<test.length; i++ ) {
          if ( test[i].indexOf("#") > -1 ) {
            try {
              rValue = getAsInt( test[i].split("#")[1].trim() );
            } catch(e) {
              rValue = 0;
            } finally {
              if ( rValue != 0 ) rValue = "#" + rValue;
            }
            break;
          }
        }
      }
    }
    return;

and the last change the line ( from your pic 😞

writeBlock("G90G10L12P1R0");

in

writeBlock("G90G10L12P1R" + rValue);

rValue = 0;

 

 

/Mario

 

( beware not truly tested )



InfoInventor CAM(Ultimate) user --- Inventor Professional 2021.2 + Inventor CAM Ultimate 8.1.2.21785
0 Likes
Message 3 of 14

makko74
Collaborator
Collaborator
Accepted solution

P.S.

if you think it's too complicated to change here and there.

 

you can also simply substitute your line:

 

writeBlock("G90G10L12P1R0");

 

with

 

    var rValue = 0;
    if ( hasParameter("notes") ) {
      var notes = getParameter("notes");
      if (notes) {
        var test = notes.split("\n");
        for ( var i=0; i<test.length; i++ ) {
          if ( test[i].indexOf("#") > -1 ) {
            try {
              rValue = getAsInt( test[i].split("#")[1].trim() );
            } catch(e) {
              rValue = 0;
            } finally {
              if ( rValue != 0 ) rValue = "#" + rValue;
            }
            break;
          }
        }
      }
    }
    writeBlock("G90G10L12P1R" + rValue);

not tested

 

/Mario



InfoInventor CAM(Ultimate) user --- Inventor Professional 2021.2 + Inventor CAM Ultimate 8.1.2.21785
0 Likes
Message 4 of 14

sevenfive85
Advocate
Advocate

YAY!!!!!! IT WORK... THANK YOU SO MUCH

Message 5 of 14

makko74
Collaborator
Collaborator
My pleasure.

/Mario


InfoInventor CAM(Ultimate) user --- Inventor Professional 2021.2 + Inventor CAM Ultimate 8.1.2.21785
Message 6 of 14

sevenfive85
Advocate
Advocate

hi makk074 How can i limit the value to only positive integer and limit it to only 5 character long only? thx again

0 Likes
Message 7 of 14

makko74
Collaborator
Collaborator
Accepted solution

change the finally block in

 

            } finally {
              if ( rValue < 0 || rValue > 99999 ) error("rValue out of range");
              if ( rValue != 0 ) rValue = "#" + rValue;
            }

/Mario



InfoInventor CAM(Ultimate) user --- Inventor Professional 2021.2 + Inventor CAM Ultimate 8.1.2.21785
0 Likes
Message 8 of 14

sevenfive85
Advocate
Advocate

Hello Makko74 or anyone who can help. what must I change to be able to use decimal points number rather than just integers?

0 Likes
Message 9 of 14

makko74
Collaborator
Collaborator
Accepted solution

substitute getAsInt with getAsFloat should do the job

 

/Mario



InfoInventor CAM(Ultimate) user --- Inventor Professional 2021.2 + Inventor CAM Ultimate 8.1.2.21785
Message 10 of 14

sevenfive85
Advocate
Advocate

THANK YOU makko74 It work but one more thing. How can i limit it to 4 decimal places only or round to 4 decimal places.  Also when i enter #1. in notes G90G10L12P1R1 appears, i would like it to show the decimal point too.    G90G10L12P1R1. (decimal point)

0 Likes
Message 11 of 14

sevenfive85
Advocate
Advocate

HI Makko74,

 

 

how can i modify the codes to do this?

 

example: if i enter #1234  in notes that line would spit out G90G10L12P1R#1234 and          

               if i enter ##1234 it would spit out G90G10L12P1R1234(no # sign). thank you

0 Likes
Message 12 of 14

makko74
Collaborator
Collaborator

its much more easier if you use an other character as "#" for this.

maybe use a "!" ( stands for NOT in javascript )

 

#123  -> G...R#123

!#123 -> G...R123

 

 

    var rValue = 0;
    if ( hasParameter("notes") ) {
      var notes = getParameter("notes");
      if (notes) {
        var test = notes.split("\n");
        for ( var i=0; i<test.length; i++ ) {
          var posExc = -1,
              posNom = test[i].indexOf("#");
          if ( posNom > -1 ) {
            try {
              rValue = getAsFloat( test[i].split("#")[1].trim() );
            } catch(e) {
              rValue = 0;
            } finally {
              if ( rValue < 0 || rValue > 99999 ) error("rValue out of range");
              if ( posNom > 0 ) posExc = test[i].indexOf("!");
              if ( rValue != 0 ) {
                rValue = ( (posExc == ( posNom - 1 )) && ( posExc > -1 ) ) ? rValue : "#" + rValue;
              }
            }
            break;
          }
        }
      }
    }
    writeBlock("G90G10L12P1R" + rValue);

 

NOT TESTED

 

/Mario



InfoInventor CAM(Ultimate) user --- Inventor Professional 2021.2 + Inventor CAM Ultimate 8.1.2.21785
0 Likes
Message 13 of 14

makko74
Collaborator
Collaborator

mapsymap schrieb:

THANK YOU makko74 It work but one more thing. How can i limit it to 4 decimal places only or round to 4 decimal places.  Also when i enter #1. in notes G90G10L12P1R1 appears, i would like it to show the decimal point too.    G90G10L12P1R1. (decimal point)


if i remember me right then has Laurens answered a similar question from you here on this forum.

 

create a new format ( up in the post, if is there nothing similar in your post ) you also can look into the post-help file under createFormat

var rFormat = createFormat({decimals:4, forceDecimal:true});

 

and than change the line:

 

rValue = ( (posExc == ( posNom - 1 )) && ( posExc > -1 ) ) ? rValue : "#" + rValue;

 

to

 

rValue = ( (posExc == ( posNom - 1 )) && ( posExc > -1 ) ) ? rFormat.format( rValue ) : "#" + rFormat.format( rValue );

 

ALSO NOT TESTED

 

/Mario



InfoInventor CAM(Ultimate) user --- Inventor Professional 2021.2 + Inventor CAM Ultimate 8.1.2.21785
0 Likes
Message 14 of 14

sevenfive85
Advocate
Advocate

Hi All,

I am looking to pass some value inside notes between two characters "rotateDeg=xxxx". The '"rotateDeg=' would be the start of my character search and '"' would be my last character, I am looking for the value between these two (xxxx) to pass. I think the slice() method along with idexOf and lastIndexOf would need to be use but I am not sure what the syntax should look like. Using the code from above can someone please help me get the correct codes. thank you.

 

    var rValue = 0;
    if ( hasParameter("notes") ) {
      var notes = getParameter("notes");
      if (notes) {
        var test = notes.split("\n");
        for ( var i=0; i<test.length; i++ ) {
          if ( test[i].indexOf("#") > -1 ) {
            try {
              rValue = getAsInt( test[i].split("#")[1].trim() );
            } catch(e) {
              rValue = 0;
            } finally {
              if ( rValue != 0 ) rValue = "#" + rValue;
            }
            break;
          }
        }
      }
    }
    writeBlock("G90G10L12P1R" + rValue);

 

0 Likes