我希望通过提供来自windows窗体的数据来手动更改代码。为此,我创建了一个文本文件,可以在其中更改值/单词。但是,如何使用这些行作为C#代码,或者如何从.txt文件中读取它们呢?
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");在这里,每次运行程序时,我都必须更改代码本身中的"TOOLPATH_2“和"90”值。
有谁能帮我吗。
发布于 2016-03-15 06:20:44
有两种方法我可以想象。
第一个:
与其尝试执行代码,powerMill.Execute("...");只需读取字符串本身并执行它们:
Textfile:
ACTIVATE TOOLPATH TOOLPATH_2
EDIT TOOLAXIS ORIENTATION ON EDIT PAR
...代码:
string[] input = File.ReadAllLines(@"C:\pathToYourTextfile.txt");
foreach(string entry in input)
{
    powerMill.Execute(entry);
}第二种方法(如果您真的想执行输入)::
您可以编译输入并执行它。检查this链接。如果你的输入不是很复杂的话,我建议你不要这样做。具体取决于你的目标。
https://stackoverflow.com/questions/36003837
复制相似问题