Tip> alternative to Field877 Activemodal >> exec.Modalcodes

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Tip> alternative to Field877 Activemodal >> exec.Modalcodes

Postby Robertspark » Sat Jan 12, 2019 9:01 pm

Tip> alternative to Field 877 Activemodal >> exec.Modalcodes

Normal way of extracting Field 877 (Active Modal) is

Code: Select all
string Activemodal = AS3.Getfield(877); // Field 877: Activemodal;
string[] WordSeparator = new string[] {"|"};
string[] Modals = Activemodal.Split(WordSeparator, StringSplitOptions.None);


And then

Code: Select all
Modals[0]; // GROUP 1
Modals[1]; // GROUP 2
Modals[2]; // GROUP 7
Modals[3]; // GROUP 8      
Modals[4]; // GROUP 16
Modals[5]; // GROUP 12
Modals[6]; // GROUP 13    
Modals[7]; // GROUP 17
Modals[8]; // GROUP 3    
Modals[9]; // GROUP 5   
Modals[10]; // GROUP 10


you'll see that they are not in order..... and if any other modal groups are added later on the array will extend and change the positions {note this is from the current development version of UCCNC which is 2.108 ..... hence there are 11 fields ....... 2.106 only had 9 (GROUP 8 & 10 were are added .... and they weren't added to the end of the string of field 877 either


alternative.....

exec.Modalcodes which is a double [] (array) and at present contains 18 items
.... the 18 items correspond to the 18 groups within the table of the UCCNC manual.... and they are in order.... group "0" to Group "17"
Arrays start at position 0 in c#

Here is a code snippet that may help you with coding and testing arrays

Code: Select all
string Activemodal = AS3.Getfield(877); // Field 877: Activemodal;
string[] WordSeparator = new string[] {"|"};
string[] Modals = Activemodal.Split(WordSeparator, StringSplitOptions.None);


      string Gcode = "";
// BODY OF FILE

   Gcode = (Gcode +  Modals.Length + " (Modals length)") + Environment.NewLine;
      
      for (var x = 0; x < Modals.Length; x++)
{
    Gcode = (Gcode +  Modals[x] + "( Array position " + x + " )") + Environment.NewLine;
}
      
      
   Gcode = (Gcode +  exec.Modalcodes.Length + " (Modals length)") + Environment.NewLine;
      
      for (var x = 0; x < exec.Modalcodes.Length; x++)
{
    Gcode = (Gcode +  exec.Modalcodes[x] + "( GROUP " + x + " )" ) + Environment.NewLine;
}

      
   // Save file
   
       System.IO.File.WriteAllText(Application.StartupPath + @"/Example_codes/Test.tap" , Gcode );
     
     // Load file

       exec.Loadfile(Application.StartupPath + @"/Example_codes/Test.tap");
   



Happy coding
Rob
Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
...working my way through the 1000+ ways things don't work to find the one that does
UC400eth, UC300eth, UCCNC v1.2110, Neuron Lite
UCCNC v1.2110 Macro Manual
Robertspark
 
Posts: 1366
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Tip> alternative to Field877 Activemodal >> exec.Modalco

Postby cncdrive » Sat Jan 12, 2019 10:17 pm

Thanks Rob. :)
cncdrive
Site Admin
 
Posts: 2805
Joined: Tue Aug 12, 2014 11:17 pm


Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests