0

I want to change code manually by giving data from windows form. For that, I created a text file where i can change values/words. But, how to use those lines as C# code or how to read them from .txt file?

powerMill.Execute("ACTIVATE TOOLPATH TOOLPATH_2");
powerMill.Execute("EDIT TOOLAXIS ORIENTATION ON EDIT PAR 'PolarMilling.Active' '0'");
powerMill.Execute("EDIT PAR 'OrientationVector.Type' 'direction_of_travel'");
powerMill.Execute("EDIT PAR 'OrientationVector.OffsetAngle'  90");

Here i have to change "TOOLPATH_2" and "90" value in the code itself every time i run the program.

Can any help me.

Abdul Arif
  • 45
  • 1
  • 10
  • These 4 lines are C# code in between main code. I want to read line by line and also consider these lines as code. – Abdul Arif Mar 15 '16 at 06:18
  • Base on my search `https://www.google.com.ph/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=read%20text%20file%20c%23` – Chris Mar 15 '16 at 06:18

1 Answers1

2

There are 2 ways I can imagine.

First one:
Instead of trying to execute code powerMill.Execute("..."); just read the strings itself and execute them:

Textfile:

ACTIVATE TOOLPATH TOOLPATH_2
EDIT TOOLAXIS ORIENTATION ON EDIT PAR
...

Code:

string[] input = File.ReadAllLines(@"C:\pathToYourTextfile.txt");

foreach(string entry in input)
{
    powerMill.Execute(entry);
}

The second way (if you really want to execute input):

You could compile the input and execute it. Check this link. In case your input isnt much complicated I wouldnt recommend going this way. Depends on your goals in detail.

Community
  • 1
  • 1
C4d
  • 3,183
  • 4
  • 29
  • 50