/// <summary> /// Creates an extruded surface from wireframe. /// </summary> /// <param name="wireframe">The wireframe from which an extruded surface will be created.</param> /// <param name="length">The length of the extruded surface.</param> /// <param name="negLength">The negative length of the extruded surface.</param> /// <returns>The new surface.</returns> public PSSurface CreateExtrudedSurface(PSWireframe wireframe, Geometry.MM length, Geometry.MM negLength) { // Add wireframe to selection _powerSHAPE.ActiveModel.ClearCreatedItems(); wireframe.AddToSelection(true); // Extrude to make solid _powerSHAPE.DoCommand("CREATE SURFACE EXTRUSION"); // Get created surface PSSurface createdSurface = null; try { createdSurface = (PSSurface)_powerSHAPE.ActiveModel.CreatedItems[0]; } catch (Exception ex) { throw new ApplicationException("Failed to create surface extrusion"); } // Edit length/negative length to be as required. Set NEGLENGTH initially in case the desired LENGTH is 0, as can't have // two lengths of 0 within the form _powerSHAPE.DoCommand("MODIFY", "NEGLENGTH " + negLength.ToString(), "LENGTH " + length.ToString(), "ACCEPT"); // Return created solid Add(createdSurface); return(createdSurface); }
/// <summary> /// Creates a new surface sphere at the specified origin and radius. /// </summary> /// <param name="origin">Origin at which to create the sphere.</param> /// <param name="radius">Radius of the sphere.</param> /// <returns>The created sphere.</returns> public PSSurfaceSphere CreateSphere(Geometry.Point origin, Geometry.MM radius) { PSSurfaceSphere sphere = new PSSurfaceSphere(_powerSHAPE, origin); sphere.Radius = radius; Add(sphere); return(sphere); }
/// <summary> /// Creates a new surface cylinder at the specified origin, radius and length. /// </summary> /// <param name="origin">The origin at which to create the cylinder.</param> /// <param name="radius">The radius of the cylinder.</param> /// <param name="length">The length of the cylinder.</param> /// <returns>The created cylinder.</returns> public PSSurfaceCylinder CreateCylinder(Geometry.Point origin, Geometry.MM radius, Geometry.MM length) { PSSurfaceCylinder cylinder = new PSSurfaceCylinder(_powerSHAPE, origin); cylinder.Radius = radius; cylinder.Length = length; Add(cylinder); return(cylinder); }
/// <summary> /// Offsets a single entity by a specified distance. /// </summary> /// <param name="entityToOffset">The single entity that is to be offset.</param> /// <param name="offsetDistance">The offset value to be applied.</param> /// <param name="copiesToCreate">The number of copies to create of the original entity.</param> /// <returns>A list of entities created by the operation. If numberOfCopies is 0, an empty list is returned.</returns> /// <remarks></remarks> public static List <PSEntity> OffsetEntity(IPSOffsetable entityToOffset, Geometry.MM offsetDistance, int copiesToCreate) { // Create a list of the single entity List <IPSOffsetable> entityToOffsetList = new List <IPSOffsetable>(); entityToOffsetList.Add(entityToOffset); // Carry out move operation return(OffsetEntities(entityToOffsetList, offsetDistance, copiesToCreate)); }
/// <summary> /// Creates a plane at a specified origin and sets its length and width. /// </summary> /// <param name="origin">The origin at which to create the plane.</param> /// <param name="principalPlane">Sets the principal plane. Defines which plane is the principal plane of the workspace.</param> /// <param name="length">The desired length of the plane.</param> /// <param name="width">The desired width of the plane.</param> /// <returns>The created plane.</returns> /// <remarks></remarks> public PSSurfacePlane CreatePlaneWithDimensions( Geometry.Point origin, Planes principalPlane, Geometry.MM length, Geometry.MM width) { PSSurfacePlane newPlane = new PSSurfacePlane(_powerSHAPE, origin, principalPlane, length, width); _powerSHAPE.ActiveModel.Surfaces.Add(newPlane); return(newPlane); }
/// <summary> /// Creates a new surface block at the specified origin, with the specified height, width, length /// and draft angle for all walls. /// </summary> /// <param name="origin">The origin at which to create the block.</param> /// <param name="width">The width of the block.</param> /// <param name="length">The length of the block.</param> /// <param name="height">The height of the block.</param> /// <param name="draftAngle">The draft angle to use for all walls.</param> /// <returns>The created block.</returns> public PSSurfaceBlock CreateBlock( Geometry.Point origin, Geometry.MM width, Geometry.MM length, Geometry.MM height, Geometry.Degree draftAngle) { PSSurfaceBlock block = new PSSurfaceBlock(_powerSHAPE, origin); block.Width = width; block.Length = length; block.Height = height; block.DraftAngle1 = draftAngle; block.DraftAngle2 = draftAngle; block.DraftAngle3 = draftAngle; block.DraftAngle4 = draftAngle; Add(block); return(block); }
/// <summary> /// Creates extruded surfaces from a list of wireframes. /// </summary> /// <param name="wireframes">The list of wireframes from which an extruded surface will be created.</param> /// <param name="length">The length of the extruded surface.</param> /// <param name="negLength">The negative length of the extruded surface.</param> /// <returns>The new surface.</returns> public List <PSSurface> CreateExtrudedSurfaces( IEnumerable <PSWireframe> wireframes, Geometry.MM length, Geometry.MM negLength) { // Add wireframes to selection _powerSHAPE.ActiveModel.ClearCreatedItems(); _powerSHAPE.ActiveModel.ClearSelectedItems(); foreach (PSWireframe wireframe in wireframes) { wireframe.AddToSelection(); } // Extrude to make solid _powerSHAPE.DoCommand("CREATE SURFACE EXTRUSION", "LENGTH " + length.ToString(), "NEGLENGTH " + negLength.ToString(), "ACCEPT"); // Get created solid List <PSSurface> createdSurfaces = new List <PSSurface>(); try { foreach (PSSurface createdSurface in _powerSHAPE.ActiveModel.CreatedItems) { createdSurfaces.Add(createdSurface); } } catch (Exception ex) { throw new ApplicationException("Failed to create surface extrusion"); } // Return created surfaces foreach (PSSurface createdSurface in createdSurfaces) { Add(createdSurface); } return(createdSurfaces); }
/// <summary> /// Offsets a group of entities by a specified distance. /// </summary> /// <param name="entitiesToOffset">The group of entities that are to be offset.</param> /// <param name="offsetDistance">The distance the entities are to be offset by.</param> /// <param name="copiesToCreate">The number of copies to create of the origina.l entities.</param> /// <returns>A list of entities created by the operation. If numberOfCopies is 0, an empty list is returned.</returns> public static List <PSEntity> OffsetEntities( List <IPSOffsetable> entitiesToOffset, Geometry.MM offsetDistance, int copiesToCreate) { // Get PowerSHAPE instance _powerSHAPE = ((PSEntity)entitiesToOffset[0]).PowerSHAPE; // Add all IPSOffsetables ((PSEntity)entitiesToOffset[0]).AddToSelection(true); int numberOfEntities = entitiesToOffset.Count(); for (int i = 1; i <= numberOfEntities - 1; i++) { ((PSEntity)entitiesToOffset[i]).AddToSelection(false); } // Carry out operation _powerSHAPE.DoCommand("EDIT OFFSET"); // Determine whether a copy is to be created if (copiesToCreate == 0) { _powerSHAPE.DoCommand("NOKEEP"); } else { _powerSHAPE.DoCommand("KEEP"); _powerSHAPE.DoCommand("COPIES " + copiesToCreate); } // Enter offset distance _powerSHAPE.DoCommand("DISTANCE " + offsetDistance.ToString()); _powerSHAPE.DoCommand("CANCEL"); // If no copies were made, return an empty list if (copiesToCreate == 0) { // If any of the entities were meshes, curve, compcurve or arcs then we need to reassign the Ids var resultEntities = _powerSHAPE.ActiveModel.SelectedItems; foreach (PSEntity entity in entitiesToOffset) { if (entity is PSMesh) { foreach (PSEntity newEntity in resultEntities) { if (newEntity is PSMesh && newEntity.Name == entity.Name) { entity.Id = newEntity.Id; break; // TODO: might not be correct. Was : Exit For } } } if (entity is PSArc) { foreach (PSEntity newEntity in resultEntities) { if (newEntity is PSArc && newEntity.Name == entity.Name) { entity.Id = newEntity.Id; break; // TODO: might not be correct. Was : Exit For } } } if (entity is PSCompCurve) { foreach (PSEntity newEntity in resultEntities) { if (newEntity is PSCompCurve && newEntity.Name == entity.Name) { entity.Id = newEntity.Id; break; // TODO: might not be correct. Was : Exit For } } } if (entity is PSCurve) { foreach (PSEntity newEntity in resultEntities) { if (newEntity is PSCurve && newEntity.Name == entity.Name) { entity.Id = newEntity.Id; break; // TODO: might not be correct. Was : Exit For } } } } return(new List <PSEntity>()); } // If copies were made, add them to their appropriate collections and return new entities List <PSEntity> copiedEntities = new List <PSEntity>(); foreach (PSEntity copiedEntity in _powerSHAPE.ActiveModel.CreatedItems) { _powerSHAPE.ActiveModel.Add(copiedEntity); copiedEntities.Add(copiedEntity); } return(copiedEntities); }
/// <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> /// Offsets a single curve by a specified distance /// </summary> /// <param name="offsetDistance">Distance by which to offset the curve</param> /// <param name="copiesToCreate">Number of copies to be created from the operation</param> /// <returns>List of offset curves</returns> public List <PSEntity> Offset(Geometry.MM offsetDistance, int copiesToCreate) { return(PSEntityOffseter.OffsetEntity(this, offsetDistance, copiesToCreate)); }