public void RunMacro(IXApplication app, string macroPath, MacroEntryPoint entryPoint, MacroRunOptions_e opts, string args, IXDocument doc) { try { if (entryPoint == null) { var macro = app.OpenMacro(macroPath); entryPoint = macro.EntryPoints.First(); } if (!string.IsNullOrEmpty(args) || doc != null) { if (m_Runner != null) { var param = new MacroParameter(); if (doc != null) { param.Set("Model", GetDocumentDispatch(doc)); } if (!string.IsNullOrEmpty(args)) { param.Set("Args", ParseCommandLine(args)); } var res = m_Runner.Run(GetAppDispatch(app), macroPath, entryPoint.ModuleName, entryPoint.ProcedureName, (int)opts, param, true); if (!res.Result) { throw new MacroRunnerResultError(res.Message); } } else { throw new UserException("Macro runner is not installed. Cannot run the macro with arguments"); } } else { var macro = app.OpenMacro(macroPath); macro.Run(entryPoint, opts); } } catch (MacroUserInterruptException) //do not consider this as an error { } catch (MacroRunnerResultError resEx) { throw new MacroRunFailedException(macroPath, -1, resEx.Message); } }
/// <summary> /// Runs macro and returns its value /// </summary> public string RunMacro(IConfigSectionNode node, string inputValue, string macroName, IConfigSectionNode macroParams, IMacroRunner runner = null, object context = null) { if (context == null) { context = m_MacroRunnerContext; } if (runner != null) { return(runner.Run(node, inputValue, macroName, macroParams, context)); } if (m_MacroRunner != null) { return(m_MacroRunner.Run(node, inputValue, macroName, macroParams, context)); } return(DefaultMacroRunner.Instance.Run(node, inputValue, macroName, macroParams, context)); }
public void RunMacro(IXApplication app, string macroPath, MacroEntryPoint entryPoint, MacroRunOptions_e opts, string args, IXDocument doc) { try { var argsArr = !string.IsNullOrEmpty(args) ? CommandLineUtils.ParseCommandLine(args) : null; var xCadMacro = GetXCadMacroIfExists(macroPath); if (xCadMacro == null) { if (entryPoint == null) { var macro = app.OpenMacro(macroPath); if (macro.EntryPoints != null) { entryPoint = macro.EntryPoints.First(); } else { throw new MacroRunFailedException(macro.Path, -1, "Failed to extract entry point"); } } if (!string.IsNullOrEmpty(args) || doc != null) { if (m_Runner != null) { var param = new MacroParameter(); if (doc != null) { param.Set("Model", GetDocumentDispatch(doc)); } if (!string.IsNullOrEmpty(args)) { param.Set("Args", argsArr); } var res = m_Runner.Run(GetAppDispatch(app), macroPath, entryPoint.ModuleName, entryPoint.ProcedureName, (int)opts, param, true); if (!res.Result) { throw new MacroRunnerResultError(res.Message); } } else { throw new UserException("Macro runner is not installed. Cannot run the macro with arguments"); } } else { var macro = app.OpenMacro(macroPath); macro.Run(entryPoint, opts); } } else { var macroDoc = doc ?? app.Documents.Active; if (macroDoc is IXUnknownDocument) { macroDoc = ((IXUnknownDocument)macroDoc).GetSpecific(); } xCadMacro.Run(app, macroDoc, m_Logger, argsArr); } } catch (MacroUserInterruptException) //do not consider this as an error { } catch (MacroRunnerResultError resEx) { throw new MacroRunFailedException(macroPath, -1, resEx.Message); } }