/// <summary> /// Runs the Macro at the given location. /// </summary> /// <param name="macroFile">The file path to the macro.</param> public void RunMacro(FileSystem.File macroFile) { PMMacro macro = null; macro = LoadMacro(macroFile); macro.Run(); }
/// <summary> /// Loads a macro from the specified file that can be stepped through or run with progress /// feedback. /// </summary> /// <param name="macroFile">The file path to the macro.</param> /// <returns>The new PMMacro.</returns> public PMMacro LoadMacro(FileSystem.File macroFile) { PMMacro macro = new PMMacro(this, macroFile); return(macro); }
/// <summary> /// Runs the specified Macro. /// </summary> /// <param name="macro">The macro to be run</param> public void RunMacro(PMMacro macro) { macro.Run(); }
/// <summary> /// Executes the next line in the macro and increments the index marker. /// </summary> /// <param name="hideDialogs">If true, hides all dialogs.</param> public override void RunStep(bool hideDialogs = true) { List <string> commands = ReplaceTokens(_lines[_localIndex]); string trimLine = ""; var results = new List <string>(); foreach (string item in commands) { var command = item; // Handle the case where the line is trying to open a file if (hideDialogs && command.ToUpper().Contains("FILEOPEN")) { //Macro could have filename on same line or next line. trimLine = command.ToUpper().Trim(); // remove spaces string[] works = trimLine.Split(' '); //check last word if (works[works.Length - 1] == "FILEOPEN") { // Instead of launching a dialog box, concatonate the two lines removing the FILEOPEN command command = command.Substring(0, command.ToUpper().IndexOf("FILEOPEN")) + ReplaceTokens(_lines[_localIndex + 1])[0]; _localIndex += 2; _totalIndex += 2; //single line } else { //do nothing as already on line _localIndex += 1; _totalIndex += 1; } //_powerMILL.DoCommand(command) } else if (hideDialogs && command.ToUpper().Contains("FILESAVE")) { trimLine = command.ToUpper().Trim(); // remove spaces string[] works = trimLine.Split(' '); //check last word if (works[works.Length - 1] == "FILESAVE") { // Instead of launching a dialog box, concatonate the two lines removing the FILESAVE command command = command.Substring(0, command.ToUpper().IndexOf("FILESAVE")) + ReplaceTokens(_lines[_localIndex + 1])[0]; _localIndex += 2; _totalIndex += 2; //single line } else { //do nothing as already on line _localIndex += 1; _totalIndex += 1; } } else if (hideDialogs && command.ToUpper().Contains("TMPLTSELECTORGUI")) { trimLine = command.ToUpper().Trim(); // remove spaces string[] works = trimLine.Split(' '); //check last word if (works[works.Length - 1] == "TMPLTSELECTORGUI") { // Instead of launching a dialog box, concatonate the two lines removing the TMPLTSELECTORGUI command command = command.Substring(0, command.ToUpper().IndexOf("TMPLTSELECTORGUI")) + ReplaceTokens(_lines[_localIndex + 1])[0]; _localIndex += 2; _totalIndex += 2; //single line } else { //do nothing as already on line _localIndex += 1; _totalIndex += 1; } } else if (hideDialogs && command.ToUpper().StartsWith("FORM")) { // Ignore first two words if (command.IndexOf(" ", 5) != -1) { command = command.Substring(command.IndexOf(" ", 5) + 1); //_powerMILL.DoCommand(command) } else { command = "$$$NothingToDo$$$"; } _localIndex += 1; _totalIndex += 1; } else if (hideDialogs && command.ToUpper().Contains(" FORM ")) { // Ignore the bit from the form command onward command = command.Substring(0, command.ToUpper().IndexOf(" FORM ")); //_powerMILL.DoCommand(command) _localIndex += 1; _totalIndex += 1; } else if (command.ToUpper().StartsWith("MACRO")) { //In some cases sub macros should be run as a single line. E.g they contain loops if (RunSubMacrosOption == SubMacroRunOptions.RunAllLines) { _childMacro = new PMMacro(_powerMILL, new FileSystem.File(command.Substring(command.IndexOf("\"") + 1, command.LastIndexOf("\"") - command.IndexOf("\"") - 1))); _childMacro.Run(); command = "$$ " + command; _totalIndex += 1 + _childMacro.TotalCount; } else { _totalIndex += 1; } _localIndex += 1; } else if (command.ToUpper().StartsWith("RUNMACRO")) { // Remove the "RUN" from the start and just run as a macro command = command.Substring(3); _localIndex += 1; _totalIndex += 1; } else { // Otherwise just run the command _localIndex += 1; _totalIndex += 1; } bool bIgnoreCmdLine = false; if (DoNotExecuteCommentsOrBlankLines) { string strCmd = command.Trim(); // remove whitespace if (string.IsNullOrEmpty(strCmd) || strCmd.StartsWith("$$") || strCmd.StartsWith("//")) { //must use start with because have to account for case where comment is on right of a command.i.e // PRINT ENTITY 'fred' $$ a comment bIgnoreCmdLine = true; } } if (command != "$$$NothingToDo$$$" && bIgnoreCmdLine == false) { _executedCommands.Add(command); if (UseExecuteEx == false) { _powerMILL.DoCommand(command); } else { // capture the result of the command for potential debugging purposes string result = _powerMILL.DoCommandEx(command).ToString(); if (!string.IsNullOrEmpty(result.Trim())) { _executedCommands.Add("$$ MESSAGE INVOKED:"); //EchoCommand("$$ MESSAGE INVOKED:") foreach ( string ritem in result.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { _executedCommands.Add("$$ " + ritem); //EchoCommand("$$ " + ritem) } } } } } // Rejig the counters for where extra lines were inserted because of the ReplaceTokens command if (commands.Count > 1) { _localIndex -= commands.Count - 1; _totalIndex -= commands.Count - 1; } }