/// <summary> /// Get a parameter value /// </summary> /// <param name="paramter">Parameter qualified name</param> /// <returns>String raw output of the application</returns> internal string GetParameter(string paramter) { var result = PowerMill.DoCommandEx(string.Format(Resources.GetParameterValue, Identifier, Name, paramter)).ToString(); ValidateOutput(result, paramter); return(result); }
/// <summary> /// Get the next name that will be generated /// </summary> /// <param name="basePrefix">Optionnal prefix</param> /// <returns>Next entity name as a string</returns> public string GetNewEntityName(string basePrefix = null) { if (basePrefix != null) { if (Count > 0) { if (GetByName(basePrefix) != null) { return(_powerMILL .DoCommandEx("PRINT PAR TERSE \"new_entity_name('" + this[0].Identifier + "','" + basePrefix + "')\"") .ToString()); } return(basePrefix); } return(basePrefix); } if (Count > 0) { return(_powerMILL.DoCommandEx("PRINT PAR TERSE \"new_entity_name('" + this[0].Identifier + "')\"").ToString()); } return("1"); }
/// <summary> /// Creates a new boundary based on its type. /// </summary> /// <param name="powerMILL">The base instance to interact with PowerMILL.</param> /// <param name="name">The name for the boundary entity.</param> /// <returns>The created boundary.</returns> /// <remarks></remarks> internal static PMBoundary CreateEntity(PMAutomation powerMILL, string name) { switch ( powerMILL.DoCommandEx("PRINT PAR TERSE \"entity('boundary', '" + name + "').type\"").ToString().Trim()) { case "block": return(new PMBoundaryBlock(powerMILL, name)); case "rest": return(new PMBoundaryRest(powerMILL, name)); case "selected": return(new PMBoundarySelectedSurface(powerMILL, name)); case "shallow": return(new PMBoundaryShallow(powerMILL, name)); case "silhouette": return(new PMBoundarySilhouette(powerMILL, name)); case "collision": return(new PMBoundaryCollisionSafe(powerMILL, name)); case "stockmodel_rest": return(new PMBoundaryStockModelRest(powerMILL, name)); case "contact_point": return(new PMBoundaryContactPoint(powerMILL, name)); case "contact_conv": return(new PMBoundaryContactConversion(powerMILL, name)); case "boolean_operation": return(new PMBoundaryBooleanOperation(powerMILL, name)); case "user": return(new PMBoundaryUserDefined(powerMILL, name)); default: throw new Exception("Failed to determine boundary type"); } }
/// <summary> /// Returns the block limits /// </summary> public BoundingBox GetBlockLimits() { var tpBlockXmin = _powerMILL.DoCommandEx("PRINT PAR TERSE $Block.Limits.XMin"); var tpBlockXmax = _powerMILL.DoCommandEx("PRINT PAR TERSE $Block.Limits.XMax"); var tpBlockYmin = _powerMILL.DoCommandEx("PRINT PAR TERSE $Block.Limits.YMin"); var tpBlockYmax = _powerMILL.DoCommandEx("PRINT PAR TERSE $Block.Limits.YMax"); var tpBlockZmin = _powerMILL.DoCommandEx("PRINT PAR TERSE $Block.Limits.ZMin"); var tpBlockZmax = _powerMILL.DoCommandEx("PRINT PAR TERSE $Block.Limits.ZMax"); BoundingBox boundingBox = new BoundingBox(Convert.ToDouble(tpBlockXmin), Convert.ToDouble(tpBlockXmax), Convert.ToDouble(tpBlockYmin), Convert.ToDouble(tpBlockYmax), Convert.ToDouble(tpBlockZmin), Convert.ToDouble(tpBlockZmax)); return(boundingBox); }
/// <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; } }
/// <summary> /// Creates a new toolpath based on its strategy. /// </summary> /// <param name="powerMILL">The base instance to interact with PowerMILL.</param> /// <param name="name">The new instance name.</param> /// <returns>The new tool instance</returns> internal static PMToolpath CreateEntity(PMAutomation powerMILL, string name) { switch ( powerMILL.DoCommandEx("PRINT PAR TERSE \"entity('toolpath', '" + name + "').strategy\"") .ToString() .Trim()) { case "raster": return(new PMToolpathRasterFinishing(powerMILL, name)); case "radial": return(new PMToolpathRadialFinishing(powerMILL, name)); case "spiral": return(new PMToolpathSpiralFinishing(powerMILL, name)); case "pattern": return(new PMToolpathPatternFinishing(powerMILL, name)); case "com_pattern": throw new Exception("Committed pattern toolpaths not supported"); case "com_boundary": throw new Exception("Committed boundary toolpaths not supported"); case "constantz": return(new PMToolpathConstantZFinishing(powerMILL, name)); case "offset_3d": return(new PMToolpath3DOffsetFinishing(powerMILL, name)); case "pencil_corner": return(new PMToolpathPencilCornerFinishing(powerMILL, name)); case "stitch_corner": return(new PMToolpathStitchCornerFinishing(powerMILL, name)); case "automatic_corner": return(new PMToolpathCornerFinishing(powerMILL, name)); case "along_corner": return(new PMToolpathAlongCornerFinishing(powerMILL, name)); case "multi_pencil_corner": return(new PMToolpathMultiPencilCornerFinishing(powerMILL, name)); case "rotary": return(new PMToolpathRotaryFinishing(powerMILL, name)); case "point_projection": return(new PMToolpathPointProjectionFinishing(powerMILL, name)); case "line_projection": return(new PMToolpathLineProjectionFinishing(powerMILL, name)); case "plane_projection": return(new PMToolpathPlaneProjectionFinishing(powerMILL, name)); case "curve_projection": return(new PMToolpathCurveProjectionFinishing(powerMILL, name)); case "profile": return(new PMToolpathProfileFinishing(powerMILL, name)); case "opti_constz": return(new PMToolpathOptimisedConstantZFinishing(powerMILL, name)); case "inter_constz": return(new PMToolpathSteepAndShallowFinishing(powerMILL, name)); case "swarf": return(new PMToolpathSwarfMachining(powerMILL, name)); case "surface_proj": return(new PMToolpathSurfaceProjectionFinishing(powerMILL, name)); case "embedded": return(new PMToolpathEmbeddedPatternFinishing(powerMILL, name)); case "raster_area_clear": return(new PMToolpathRasterAreaClearance(powerMILL, name)); case "offset_area_clear": return(new PMToolpathOffsetAreaClearance(powerMILL, name)); case "profile_area_clear": return(new PMToolpathProfileAreaClearance(powerMILL, name)); case "drill": return(new PMToolpathDrilling(powerMILL, name)); case "wireframe_swarf": return(new PMToolpathWireframeSwarfMachining(powerMILL, name)); case "raster_flat": return(new PMToolpathRasterFlatFinishing(powerMILL, name)); case "offset_flat": return(new PMToolpathOffsetFlatFinishing(powerMILL, name)); case "plunge": return(new PMToolpathPlungeMilling(powerMILL, name)); case "parametric_offset": return(new PMToolpathParametricOffsetFinishing(powerMILL, name)); case "surface_machine": return(new PMToolpathSurfaceFinishing(powerMILL, name)); case "port_area_clear": return(new PMToolpathPortAreaClearance(powerMILL, name)); case "port_plunge": return(new PMToolpathPortPlungeFinishing(powerMILL, name)); case "port_spiral": return(new PMToolpathPortSpiralFinishing(powerMILL, name)); case "method": return(new PMToolpathMethod(powerMILL, name)); case "blisk": return(new PMToolpathBliskAreaClearance(powerMILL, name)); case "blisk_hub": return(new PMToolpathHubFinishing(powerMILL, name)); case "blisk_blade": return(new PMToolpathBladeFinishing(powerMILL, name)); case "disc_profile": return(new PMToolpathDiscProfileFinishing(powerMILL, name)); case "curve_profile": return(new PMToolpathCurveProfile(powerMILL, name)); case "curve_area_clear": return(new PMToolpathCurveAreaClearance(powerMILL, name)); case "face": return(new PMToolpathFaceMilling(powerMILL, name)); case "chamfer": return(new PMToolpathChamferMilling(powerMILL, name)); case "wireframe_profile": return(new PMToolpathWireframeProfileMachining(powerMILL, name)); case "corner_clear": return(new PMToolpathCornerClearance(powerMILL, name)); case "edge_break": throw new Exception("Edge break toolpaths not supported"); case "flowline": return(new PMToolpathFlowlineFinishing(powerMILL, name)); case "parametric_spiral": return(new PMToolpathParametricSpiralFinishing(powerMILL, name)); case "adaptive_area_clear": return(new PMToolpathAdaptiveAreaClearance(powerMILL, name)); case "rib": return(new PMToolpathRibMachining(powerMILL, name)); case "blade": return(new PMToolpathBladeMachining(powerMILL, name)); case "feature_face": throw new Exception("Feature face machining toolpaths not supported"); case "feature_chamfer": throw new Exception("Feature chamfer machining toolpaths not supported"); default: return(new PMToolpath(powerMILL, name)); } }