/// <summary> /// Creates an Oblique curve against either a mesh, solid or surface. /// </summary> /// <param name="entityToOblique">The entity to be cut by the oblique curve.</param> /// <param name="UsePlane">Sets the principal plane.</param> /// <param name="position">Distance along plane to drop curve on.</param> /// <exception cref="ApplicationException">No curves were created from intersection operation.</exception> /// <exception cref="ApplicationException">Entity must be Mesh, Surface or Solid.</exception> /// <returns>List of CompCurves.</returns> public List <PSCompCurve> CreateObliqueCurve(PSEntity entityToOblique, Planes UsePlane, Geometry.MM position) { List <PSCompCurve> createdCurves = new List <PSCompCurve>(); if (entityToOblique is PSMesh || entityToOblique is PSSolid || entityToOblique is PSSurface) { // Set the principal plane _powerSHAPE.SetActivePlane(UsePlane); entityToOblique.AddToSelection(true); _powerSHAPE.DoCommand("create curve Oblique", "DISTANCE " + position.Value, "ACCEPT"); // Add created curves to collection if (_powerSHAPE.ActiveModel.CreatedItems.Count == 0) { throw new ApplicationException("No curves were created from intersection operation"); } foreach (PSCompCurve createdCurve in _powerSHAPE.ActiveModel.CreatedItems) { createdCurves.Add(createdCurve); _powerSHAPE.ActiveModel.CompCurves.Add(createdCurve); } } else { throw new ApplicationException("Entity must be Mesh, Surface or Solid"); } // Return created curves return(createdCurves); }
/// <summary> /// Copies and pastes the Entity. /// NB:Any dependencies are also copied and cause an exception to be thrown. /// </summary> /// <exception cref="NotImplementedException">Doesn't yet support multiple pasted objects</exception> /// <exception cref="Exception">Item in clipboard is not a PowerSHAPE, or the expected object</exception> public virtual PSEntity Duplicate() { Copy(); _powerSHAPE.ActiveModel.ClearSelectedItems(); _powerSHAPE.DoCommand("PASTE"); int nSelectedItemsCount = _powerSHAPE.ActiveModel.SelectedItems.Count; //only need count once // No object has been pasted within PowerSHAPE if (nSelectedItemsCount == 0) { throw new Exception("Item in clipboard is not a PowerSHAPE object"); // One object has been pasted in PowerSHAPE } if (nSelectedItemsCount == 1) { PSEntity newEntity = _powerSHAPE.ActiveModel.SelectedItems[0]; if (newEntity.Identifier != Identifier) { // The pasted object is not of the required type // Delete the incorrect object newEntity.AddToSelection(true); _powerSHAPE.DoCommand("DELETE"); throw new Exception("Item in clipboard is not a " + Identifier); } _powerSHAPE.ActiveModel.Add(newEntity); return(newEntity); // More than one item was pasted in PowerSHAPE } throw new NotImplementedException("Doesn't yet support multiple pasted objects!"); }
/// <summary> /// Limits an arc by a specified list of entities /// </summary> /// <param name="limitingEntity">The entity with which to perform the limiting operation</param> /// <param name="limitingMode">The mode in which to carry out the operation</param> /// <param name="keepOption">Whether to keep one or both sides of the limit</param> /// <param name="trimOption">Whether to trim one or all of the entities</param> /// <param name="finishOperation">If true, turns edit selection off.</param> /// <returns>A list of limited entities</returns> public List <PSEntity> LimitToEntity( PSEntity limitingEntity, LimitingModes limitingMode = LimitingModes.LimitMode, LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne, LimitingTrimOptions trimOption = LimitingTrimOptions.LimitOne, bool finishOperation = true) { return(PSEntityLimiter.LimitEntity(this, limitingEntity, limitingMode, keepOption, trimOption, finishOperation)); }
/// <summary> /// Does not work as created.number is not updated. /// </summary> /// <param name="entityToLimit">The entity to limit.</param> /// <param name="keepOption">Keep option, by default KeepOne.</param> /// <returns>The limited entity.</returns> /// <remarks></remarks> internal static PSEntity LimitEntityUsingDynamicCutter( IPSLimitable entityToLimit, LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne) { // Get PowerSHAPE instance _powerSHAPE = ((PSEntity)entityToLimit).PowerSHAPE; // Create a list of the single entity PSEntity entity = (PSEntity)entityToLimit; _powerSHAPE.ActiveModel.ClearCreatedItems(); entity.AddToSelection(true); _powerSHAPE.DoCommand("EDIT SELECTION"); _powerSHAPE.DoCommand(keepOption.ToString()); _powerSHAPE.DoCommand("Cutter_Dynamic On"); bool limitingHappened = false; PSModel model = _powerSHAPE.ActiveModel; var interval = 1000; // Keep looping and picking points while (limitingHappened == false) { // Wait for a second to see if a limit has happened yet. The item will no longer be selected when it has System.Threading.Thread.Sleep(interval); // See if the user finished creating the curve yet int selectedCount = 1; try { selectedCount = _powerSHAPE.ReadIntValue("SELECTION.NUMBER"); } catch { selectedCount = 1; } if (selectedCount == 0) { foreach (PSEntity newEntity in _powerSHAPE.ActiveModel.CreatedItems) { newEntity.Id = _powerSHAPE.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID"); _powerSHAPE.ActiveModel.Add(newEntity); } limitingHappened = true; } } // When the limit happens we get a new entity with a new id but it has the same name as the original // So change the id of the entity we wanted to limit so things work as normal entity.Id = _powerSHAPE.ReadIntValue(entity.Identifier + "['" + entity.Name + "'].ID"); return(entity); }
/// <summary> /// Gets the distance between this entity and another /// </summary> /// <param name="otherEntity">The function returns the distance between this entity and the otherEntity</param> /// <exception cref="Exception">Failed to determine distance between objects</exception> public MM DistanceTo(PSEntity otherEntity) { if (otherEntity is PSSurface) { return(((PSSurface)otherEntity).DistanceTo(this)); } if (otherEntity is PSPoint) { return((ToPoint() - ((PSPoint)otherEntity).ToPoint()).Magnitude); } return(base.DistanceTo(otherEntity)); }
internal PSSolidBlock(PSAutomation powershape, Point origin) : base(powershape) { // Clear CreatedItems _powerSHAPE.ActiveModel.ClearCreatedItems(); // Create a plane at the point specified _powerSHAPE.DoCommand("CREATE SOLID BLOCK"); _powerSHAPE.DoCommand(origin.ToString()); // Get created plane id PSEntity newBlock = _powerSHAPE.ActiveModel.CreatedItems[0]; _id = newBlock.Id; }
/// <summary> /// Removes all entities in the list. /// </summary> public override void Clear() { // Get initial number of items in collection int initialCollectionCount = Count; // Loop through items, deleting and removing each from the collection for (int i = 0; i <= initialCollectionCount - 1; i++) { // Get last entity PSEntity currentEntity = this[Count - 1]; // Remove entity from collection Remove((T)currentEntity); } }
/// <summary> /// Limits a single entity using a list of entities. /// </summary> /// <param name="entityToLimit">The entity on which to perform the limiting operation.</param> /// <param name="limitingEntity">The entity with which to perform the limiting operation.</param> /// <param name="limitingMode">The mode in which to carry out the operation.</param> /// <param name="keepOption">Whether to keep one or both sides of the limit.</param> /// <param name="trimOption">Whether to trim one or all of the entities.</param> internal static List <PSEntity> LimitEntity( IPSLimitable entityToLimit, PSEntity limitingEntity, LimitingModes limitingMode = LimitingModes.LimitMode, LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne, LimitingTrimOptions trimOption = LimitingTrimOptions.LimitOne, bool finishOperation = true) { // Create a list of the single entity List <PSEntity> limitingEntities = new List <PSEntity>(); limitingEntities.Add(limitingEntity); // Carry out limit operation return(LimitEntity(entityToLimit, limitingEntities, limitingMode, keepOption, trimOption, finishOperation)); }
/// <summary> /// Gets the distance between this entity and another /// </summary> /// <param name="otherEntity">The function returns the distance between this entity and the otherEntity</param> /// <exception cref="Exception">Failed to determine distance between objects</exception> public MM DistanceTo(PSEntity otherEntity) { object[] values; try { values = _powerSHAPE.ActiveDocument.MinDist(CompositeID, otherEntity.CompositeID); } catch (Exception ex) { throw new Exception("Failed to determine distance between objects", ex); } if (values.Length != 2 || int.Parse(values[0].ToString()) == -1) { throw new Exception("Failed to determine distance between objects"); } return(double.Parse(values[1].ToString())); }
/// <summary> /// Shifts the entity from being relative to one workplane to being relative to another /// </summary> /// <param name="toWorkplane">The workplane to rebase to</param> /// <param name="fromWorkplane">Optional parameter. The workplane to rebase from. Default of Nothing is world.</param> /// <exception cref="NotImplementedException">Doesn't yet support multiple pasted objects</exception> /// <exception cref="Exception">Item in clipboard is not a PowerSHAPE, or the expected object</exception> public virtual void RebaseToWorkplane(PSWorkplane toWorkplane, PSWorkplane fromWorkplane = null) { // Activate the from workplane (default is world) _powerSHAPE.ActiveModel.ActiveWorkplane = fromWorkplane; Copy(); _powerSHAPE.ActiveModel.ClearSelectedItems(); // Activate the to workplane _powerSHAPE.ActiveModel.ActiveWorkplane = toWorkplane; _powerSHAPE.DoCommand("PASTE"); // No object has been pasted within PowerSHAPE if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0) { throw new Exception("Item in clipboard is not a PowerSHAPE object"); // One object has been pasted in PowerSHAPE } if (_powerSHAPE.ActiveModel.SelectedItems.Count == 1) { PSEntity newEntity = _powerSHAPE.ActiveModel.SelectedItems[0]; if (newEntity.Identifier != Identifier) { // The pasted object is not of the required type // Delete the incorrect object newEntity.AddToSelection(true); _powerSHAPE.DoCommand("DELETE"); throw new Exception("Item in clipboard is not a " + Identifier); } // Delete the original item and link this entity to the new one AddToSelection(true); _powerSHAPE.DoCommand("DELETE"); _id = newEntity.Id; _name = newEntity.Name; // More than one item was pasted in PowerSHAPE } else { throw new NotImplementedException("Doesn't yet support multiple pasted objects!"); } }
/// <summary> /// Projects a Curve onto a surface. /// </summary> /// <param name="surface">The surface to wrap onto.</param> /// <param name="projectionType">The type of projection to be carried out.</param> /// <param name="keepOriginal">If true, it deletes the original entity.</param> /// <remarks>The old CompCurve is removed, and this object's ID set to be the new ID.</remarks> /// <returns>List of entities created by the operation.</returns> public virtual List <PSCompCurve> ProjectOntoSurface(PSEntity surface, ProjectionType projectionType, bool keepOriginal) { // Add necessary components to the selection AddToSelection(true); surface.AddToSelection(false); _powerSHAPE.ActiveModel.ClearCreatedItems(); _powerSHAPE.DoCommand("CREATE CURVE PROJECT"); // Select correct projection type switch (projectionType) { case ProjectionType.AlongPrincipalAxis: _powerSHAPE.DoCommand("PRINCIPAL"); break; case ProjectionType.AlongSurfaceNormal: _powerSHAPE.DoCommand("NORMAL"); break; case ProjectionType.ThroughSurface: _powerSHAPE.DoCommand("THRU"); break; } _powerSHAPE.DoCommand("ACCEPT"); List <PSCompCurve> newEntities = new List <PSCompCurve>(); foreach (PSCompCurve newEntity in _powerSHAPE.ActiveModel.CreatedItems) { _powerSHAPE.ActiveModel.Add(newEntity); newEntities.Add(newEntity); } if (keepOriginal == false) { AddToSelection(true); _powerSHAPE.DoCommand("DELETE"); } return(newEntities); }
/// <summary> /// Creates a workplane aligned to an entity /// </summary> internal PSWorkplane(PSAutomation powerSHAPE, PSEntity entity, Geometry.Point origin) : base(powerSHAPE) { // Select the entity entity.AddToSelection(true); // Create the workplane _powerSHAPE.DoCommand("CREATE WORKPLANE NORMALSINGLE"); _powerSHAPE.DoCommand(origin.ToString()); // Try to get workplane details try { PSWorkplane newWorkplane = (PSWorkplane)_powerSHAPE.ActiveModel.CreatedItems[0]; _name = newWorkplane.Name; _id = newWorkplane.Id; } catch { throw new ApplicationException("Failed to create Workplane"); } }
/// <summary> /// Creates CompCurves from an intersection between two sets of surfaces /// </summary> /// <param name="firstSurfaces">The first set of surfaces to intersect</param> /// <param name="secondSurfaces">The second set of surfaces to intersect</param> /// <returns>A list of the created CompCurves</returns> public List <PSCompCurve> CreateCompCurvesFromIntersectionOfTwoSetsOfSurfaces( List <PSSurface> firstSurfaces, List <PSSurface> secondSurfaces) { // Create lists of entites List <PSEntity> firstEntities = new List <PSEntity>(); List <PSEntity> secondEntities = new List <PSEntity>(); foreach (PSSurface firstSurface in firstSurfaces) { PSEntity firstEntity = firstSurface; firstEntities.Add(firstEntity); } foreach (PSSurface secondSurface in secondSurfaces) { PSEntity secondEntity = secondSurface; secondEntities.Add(secondEntity); } // Carry out operation return(CreateCompCurvesFromIntersectionOfTwoSetsOfEntities(firstEntities, secondEntities)); }
/// <summary> /// Creates a workplane that doesn't need an origin /// </summary> internal PSWorkplane( PSAutomation powerSHAPE, PSEntity entity, NewWorkplaneInEntityPositions workplanePosition) : base(powerSHAPE) { // Select the entity entity.AddToSelection(true); // Create the workplane string position = ""; switch (workplanePosition) { case NewWorkplaneInEntityPositions.Centre: position = "SELECTIONCENTRE"; break; case NewWorkplaneInEntityPositions.Bottom: position = "SELECTIONBOTTOM"; break; case NewWorkplaneInEntityPositions.Top: position = "SELECTIONTOP"; break; } _powerSHAPE.DoCommand("CREATE WORKPLANE " + position); // Try to get workplane details try { PSWorkplane newWorkplane = (PSWorkplane)_powerSHAPE.ActiveModel.CreatedItems[0]; _name = newWorkplane.Name; _id = newWorkplane.Id; } catch { throw new ApplicationException("Failed to create Workplane"); } }
/// <summary> /// Intersects an entity with another entity /// </summary> /// <param name="entityToIntersect">Entity to intersect</param> /// <param name="copeWithCoincidentFaces">Optional boolean defaults to False</param> /// <returns>Entity created from the intersection</returns> public PSEntity IntersectEntityWithEntity(IPSIntersectable entityToIntersect, bool copeWithCoincidentFaces = false) { // In order to force the dialog to appear, the command is sent before doing the selection of the entity _powerSHAPE.ActiveModel.ClearSelectedItems(); _powerSHAPE.DoCommand("CREATE FEATURE INTERSECTION"); // Select this item _powerSHAPE.DoCommand("PRIMARY ON"); AddToSelection(false); // Add addition solid to selection PSEntity entity = (PSEntity)entityToIntersect; entity.AddToSelection(false); if (copeWithCoincidentFaces) { _powerSHAPE.DoCommand("TOLERANCE ON"); } else { _powerSHAPE.DoCommand("TOLERANCE OFF"); } // Fill in options on the dialog and accept it to complete the operation. The YES at the end is to handle the question about deleting the solid tree _powerSHAPE.DoCommand("KEEP OFF", "ACCEPT", "YES"); if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0) { return(null); } // Remove the lost solids entity.Delete(); // Return this Mesh return(this); }
/// <summary> /// Cuts a single entity at a defined point. /// </summary> /// <param name="entityToCut">The entity to cut.</param> /// <param name="pointAtWhichToCut">The point at which to cut the entity, which must lie on the entity.</param> /// <returns>A piece of the original entity.</returns> public static PSEntity CutEntity(PSEntity entityToCut, Geometry.Point pointAtWhichToCut) { // Get PowerSHAPE instance _powerSHAPE = entityToCut.PowerSHAPE; // Cut entity entityToCut.AddToSelection(true); _powerSHAPE.DoCommand("EDIT LIMIT CUTS"); _powerSHAPE.DoCommand(pointAtWhichToCut.ToString()); _powerSHAPE.DoCommand("EDIT LIMIT CUTS OFF"); // Check that operation worked if (_powerSHAPE.ActiveModel.CreatedItems.Count == 0) { throw new ApplicationException("Cut operation did not function correctly"); } // Get created entity PSEntity newEntity = _powerSHAPE.ActiveModel.CreatedItems[0]; newEntity.Id = _powerSHAPE.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID"); _powerSHAPE.ActiveModel.Add(newEntity); return(newEntity); }