/// <summary> /// Moves the model by the specified vector. /// </summary> /// <param name="moveVector">The vector of how to move the model in X, Y, Z.</param> public void Move(Vector moveVector) { PowerMill.DoCommand("TRANSFORM TYPE MOVE TRANSFORM MOVEX \"" + moveVector.I + "\"", "TRANSFORM TYPE MOVE TRANSFORM MOVEY \"" + moveVector.J + "\"", "TRANSFORM TYPE MOVE TRANSFORM MOVEZ \"" + moveVector.K + "\"", "TRANSFORM MODEL \"" + Name + "\""); }
/// <summary> /// Checks if there are any collisions. /// If it returns true the three status indicators can then be inspected to determine the cause /// </summary> public bool DetectHolderCollisions() { // See if collisions have already been detected if (GetParameterBooleanValue("Verification.CollisionChecked") == false) { // Not yet detected so determine if there are any PowerMill.DoCommand("ACTIVATE TOOLPATH '" + Name + "'", "EDIT COLLISION TYPE Collision", "EDIT COLLISION SCOPE ALL", "EDIT COLLISION SPLIT_TOOLPATH N", "EDIT COLLISION STOCKMODEL_CHECK N", "EDIT COLLISION DEPTH N", "EDIT COLLISION USE_TOOL \" \"", "EDIT COLLISION APPLY"); } // Now check the tool safety parameters var cuttingStatus = GetParameter("Safety.Holder.Cutting.Status"); _holderCuttingMovesSafety = SafetyFromString(cuttingStatus); var linksStatus = GetParameter("Safety.Holder.Links.Status"); _holderLinksSafety = SafetyFromString(linksStatus); var leadsStatus = GetParameter("Safety.Holder.Leads.Status"); _holderLeadsSafety = SafetyFromString(leadsStatus); if (_holderCuttingMovesSafety == ToolpathSafety.Collides || _holderLinksSafety == ToolpathSafety.Collides || _holderLeadsSafety == ToolpathSafety.Collides) { return(true); } // No collisions detected return(false); }
/// <summary> /// Detects if there are any gouges. /// If it returns true the three status indicators can then be inspected to determine the cause. /// </summary> public bool DetectToolGouges() { // See if gouges have already been detected if (GetParameterBooleanValue("Verification.GougeChecked") == false) { // Not yet detected so determine if there are any PowerMill.DoCommand("ACTIVATE TOOLPATH '" + Name + "'", "EDIT COLLISION TYPE Gouge", "EDIT COLLISION SCOPE ALL", "EDIT COLLISION SPLIT_TOOLPATH N", "EDIT COLLISION STOCKMODEL_CHECK N", "EDIT COLLISION APPLY"); } // Now check the tool safety parameters var cuttingStatus = GetParameter("Safety.Tool.Cutting.Status"); _toolCuttingMovesSafety = SafetyFromString(cuttingStatus); var linksStatus = GetParameter("Safety.Tool.Links.Status"); _toolLinksSafety = SafetyFromString(linksStatus); var leadsStatus = GetParameter("Safety.Tool.Leads.Status"); _toolLeadsSafety = SafetyFromString(leadsStatus); if (_toolCuttingMovesSafety == ToolpathSafety.Collides || _toolLinksSafety == ToolpathSafety.Collides || _toolLeadsSafety == ToolpathSafety.Collides) { return(true); } // No gouges detected return(false); }
/// <summary> /// Selects the model, optionally removing everything else from the selection first. /// </summary> /// <param name="clearSelectionFirst">If true unselects everything else before selecting this model.</param> public void AddToSelection(bool clearSelectionFirst = false) { if (clearSelectionFirst) { PowerMill.DoCommand("EDIT MODEL ALL DESELECT ALL"); } PowerMill.DoCommand("EDIT MODEL \"" + Name + "\" SELECT ALL"); }
/// <summary> /// Inserts the specified Boundary into this Boundary. /// </summary> /// <param name="boundary">The boundary to insert into this Boundary.</param> public void InsertBoundary(PMBoundary boundary) { if (boundary == null || !boundary.Exists) { throw new ArgumentNullException("boundary", "Boundary not found"); } PowerMill.DoCommand("EDIT BOUNDARY '" + Name + "' INSERT BOUNDARY '" + boundary.Name + "'"); }
/// <summary> /// Reimports a file into PowerMill. /// </summary> /// <param name="file">The file to import.</param> public void Reimport(FileSystem.File file) { var arrayToCheck = new[] { "dmt", "dgk", "ddx", "ddz", "psmodel", "doc", "det", "pic" }; if (!arrayToCheck.Contains(file.Extension)) { throw new Exception("File extension must be dgk, ddx, ddz, psmodel, doc, det or pic"); } PowerMill.DoCommand(string.Format("EDIT MODEL '{0}' REIMPORT '{1}'", Name, file.Path)); }
/// <summary> /// Exports the model to the specified file. /// </summary> /// <param name="file">The file to which the model will be exported.</param> public void ExportModel(FileSystem.File file, bool exportInActiveWorkplane = true) { // Delete the file if it already exists file.Delete(); if (exportInActiveWorkplane == false) { PowerMill.DoCommand("DEACTIVATE WORKPLANE"); } PowerMill.DoCommand("EXPORT MODEL '" + Name + "' '" + file.Path + "'"); }
/// <summary> /// Inserts the specified Boundary into this Boundary. /// </summary> /// <param name="boundaryName">The name of the boundary to insert into this Boundary.</param> public void InsertBoundaryByName(string boundaryName) { PMBoundary boundary = PowerMill.ActiveProject.Boundaries.GetByName(boundaryName); if (boundary == null || !boundary.Exists) { throw new ArgumentNullException("boundary", "Boundary not found"); } PowerMill.DoCommand("EDIT BOUNDARY '" + Name + "' INSERT BOUNDARY '" + boundary.Name + "'"); }
/// <summary> /// Mirrors the model in the plane. /// </summary> /// <param name="plane">The plane used to mirror the model.</param> public void MirrorInPlane(Planes plane) { switch (plane) { case Planes.XY: PowerMill.DoCommand("TRANSFORM TYPE SCALEZ TRANSFORM SCALEVALUE -1 TRANSFORM MODEL '" + Name + "'"); break; case Planes.ZX: PowerMill.DoCommand("TRANSFORM TYPE SCALEY TRANSFORM SCALEVALUE -1 TRANSFORM MODEL '" + Name + "'"); break; case Planes.YZ: PowerMill.DoCommand("TRANSFORM TYPE SCALEX TRANSFORM SCALEVALUE -1 TRANSFORM MODEL '" + Name + "'"); break; } }
/// <summary> /// Rotate the model by the specified axis and angle. /// </summary> /// <param name="rotateAxis">The rotation axis</param> /// <param name="rotateAngle">The rotation angle</param> public void Rotate(Axes rotateAxis, double rotateAngle) { switch (rotateAxis) { case Axes.X: PowerMill.DoCommand("TRANSFORM ANGLE \"" + rotateAngle + "\" TRANSFORM TYPE ROTATEX TRANSFORM MODEL \"" + Name + "\""); break; case Axes.Y: PowerMill.DoCommand("TRANSFORM ANGLE \"" + rotateAngle + "\" TRANSFORM TYPE ROTATEY TRANSFORM MODEL \"" + Name + "\""); break; case Axes.Z: PowerMill.DoCommand("TRANSFORM ANGLE \"" + rotateAngle + "\" TRANSFORM TYPE ROTATEZ TRANSFORM MODEL \"" + Name + "\""); break; } }
/// <summary> /// Splits the selected sections of the Pattern. /// </summary> public void SplitSelected() { PowerMill.DoCommand("EDIT PATTERN '" + Name + "' SPLIT"); }
/// <summary> /// Invalidates the toolpath. /// </summary> public void MakeInvalid() { PowerMill.DoCommand("INVALIDATE TOOLPATH \"" + Name + "\""); }
/// <summary> /// Calculates the toolpath. /// </summary> public void Calculate() { // Activate it then calculate it IsActive = true; PowerMill.DoCommand("EDIT TOOLPATH \"" + Name + "\" CALCULATE"); }
/// <summary> /// Fits an arc to the selected sections of the Pattern. /// </summary> /// <param name="tolerance">The Arc fitting tolerance.</param> public void ArcFitSelected(double tolerance) { PowerMill.DoCommand("EDIT PATTERN '" + Name + "' ARCFIT " + tolerance); }
/// <summary> /// Reverses the selected sections of the Pattern in PowerMill. /// </summary> public void ReverseSelected() { PowerMill.DoCommand("EDIT PATTERN '" + Name + "' REVERSE"); }
/// <summary> /// Merges the selected sections of the Pattern. /// </summary> public void MergeSelected() { PowerMill.DoCommand("EDIT PATTERN '" + Name + "' MERGE"); }
/// <summary> /// Polygonise a boundary to a specified tolerance. /// </summary> /// <param name="smashTolerance">The tolerance used to polygonise boundary.</param> public void Smash(double smashTolerance) { PowerMill.DoCommand(string.Format("EDIT BOUNDARY \"{0}\" SMASH {1}", Name, smashTolerance)); }
/// <summary> /// Inserts the specified file into this Boundary. /// </summary> /// <param name="file">The file to insert into this Boundary.</param> public void InsertFile(File file) { PowerMill.DoCommand("EDIT BOUNDARY '" + Name + "' INSERT FILE \"" + file.Path + "\""); }
/// <summary> /// Splines all the sections of the Pattern. /// </summary> /// <param name="dblTolerance">The Spline fitting tolerance.</param> public void SplineAll(double dblTolerance) { MergeAll(); PowerMill.DoCommand("EDIT PATTERN '" + Name + "' SPLINE " + dblTolerance); }
/// <summary> /// Fits an Arc to all the sections of the Pattern. /// </summary> /// <param name="dblTolerance">The Arc fitting tolerance.</param> public void ArcFitAll(double dblTolerance) { MergeAll(); PowerMill.DoCommand("EDIT PATTERN '" + Name + "' ARCFIT " + dblTolerance); }
/// <summary> /// Reverses all the sections of the Pattern. /// </summary> public void ReverseAll() { MergeAll(); PowerMill.DoCommand("EDIT PATTERN '" + Name + "' REVERSE"); }
/// <summary> /// Selects all sections of the Pattern. /// </summary> public void SelectAll() { PowerMill.DoCommand("EDIT PATTERN '" + Name + "' SELECT ALL"); }
/// <summary> /// Fatten the boundary onto the XY Plane at Z = 0. /// </summary> public void Flat() { PowerMill.DoCommand(string.Format("EDIT BOUNDARY \"{0}\" CURVEEDITOR START", Name)); PowerMill.DoCommand("CURVEEDITOR FLATTEN SELECTED"); PowerMill.DoCommand("CURVEEDITOR FINISH ACCEPT"); }
/// <summary> /// Merges all the sections of the Pattern. /// </summary> public void MergeAll() { SelectAll(); PowerMill.DoCommand("EDIT PATTERN '" + Name + "' MERGE"); }
/// <summary> /// Polygonises all the sections of the Pattern. /// </summary> /// <param name="dblTolerance">The Polygonisation tolerance.</param> public void PolygoniseAll(double dblTolerance) { MergeAll(); PowerMill.DoCommand("EDIT PATTERN '" + Name + "' SMASH " + dblTolerance); }
/// <summary> /// Closes the selected sections of the Pattern. /// </summary> public void CloseSelected() { PowerMill.DoCommand("EDIT PATTERN '" + Name + "' CLOSE"); }
/// <summary> /// Inserts the specified toolpath into this Boundary. /// </summary> /// <param name="toolpath">The toolpath to insert into this Boundary.</param> public void InsertToolpath(PMToolpath toolpath) { PowerMill.DoCommand("EDIT BOUNDARY '" + Name + "' INSERT TOOLPATH \"" + toolpath.Name + "\""); }
/// <summary> /// Splits all the sections of the Pattern. /// </summary> public void SplitAll() { MergeAll(); PowerMill.DoCommand("EDIT PATTERN '" + Name + "' SPLIT"); }
/// <summary> /// Write the Boundary to the specified file. Supported file types are: dgk, ddz, ddx, dxf, pic /// </summary> /// <param name="file">The file to write to.</param> public void WriteToFile(File file) { PowerMill.DoCommand("KEEP BOUNDARY '" + Name + "' FILESAVE \"" + file.Path + "\""); }
/// <summary> /// Closes all the sections of the Pattern. /// </summary> public void CloseAll() { MergeAll(); PowerMill.DoCommand("EDIT PATTERN '" + Name + "' CLOSE"); }