public static SolidEdgePart.Model CreateFiniteExtrudedProtrusion(SolidEdgePart.PartDocument partDocument, SolidEdgePart.RefPlane refPlane, double[][] linesArray, SolidEdgePart.FeaturePropertyConstants profilePlaneSide, double extrusionDistance) { SolidEdgePart.ProfileSets profileSets = null; SolidEdgePart.ProfileSet profileSet = null; SolidEdgePart.Profiles profiles = null; SolidEdgePart.Profile profile = null; SolidEdgeFrameworkSupport.Relations2d relations2d = null; SolidEdgeFrameworkSupport.Relation2d relation2d = null; SolidEdgeFrameworkSupport.Lines2d lines2d = null; SolidEdgeFrameworkSupport.Line2d line2d = null; SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; System.Array aProfiles = null; // Get a reference to the profile sets collection. profileSets = partDocument.ProfileSets; // Add a new profile set. profileSet = profileSets.Add(); // Get a reference to the profiles collection. profiles = profileSet.Profiles; // Add a new profile. profile = profiles.Add(refPlane); // Get a reference to the lines2d collection. lines2d = profile.Lines2d; // Draw the Base Profile. for (int i = 0; i <= linesArray.GetUpperBound(0); i++) { line2d = lines2d.AddBy2Points( x1: linesArray[i][0], y1: linesArray[i][1], x2: linesArray[i][2], y2: linesArray[i][3]); } // Define Relations among the Line objects to make the Profile closed. relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d; // Connect all of the lines. for (int i = 1; i <= lines2d.Count; i++) { int j = i + 1; // When we reach the last line, wrap around and connect it to the first line. if (j > lines2d.Count) { j = 1; } relation2d = relations2d.AddKeypoint( Object1: lines2d.Item(i), Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2: lines2d.Item(j), Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, guaranteed_ok: true); } // Close the profile. profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed); // Hide the profile. profile.Visible = false; // Create a new array of profile objects. aProfiles = Array.CreateInstance(typeof(SolidEdgePart.Profile), 1); aProfiles.SetValue(profile, 0); // Get a reference to the models collection. models = partDocument.Models; // Create the extended protrusion. model = models.AddFiniteExtrudedProtrusion( NumberOfProfiles: aProfiles.Length, ProfileArray: ref aProfiles, ProfilePlaneSide: profilePlaneSide, ExtrusionDistance: extrusionDistance); return(model); }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgePart.PartDocument partDocument = null; SolidEdgePart.RefPlanes refPlanes = null; SolidEdgePart.RefPlane refPlane = null; SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgeGeometry.Body body = null; SolidEdgeGeometry.Faces faces = null; SolidEdgeGeometry.Face face = null; SolidEdgePart.Thickens thickens = null; SolidEdgePart.Thicken thicken = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the documents collection. documents = application.Documents; // Add a new part document. partDocument = documents.AddPartDocument(); // Always a good idea to give SE a chance to breathe. application.DoIdle(); // Get a reference to the RefPlanes collection. refPlanes = partDocument.RefPlanes; // Get a reference to a RefPlane. refPlane = refPlanes.GetFrontPlane(); List <double[]> linesArray = new List <double[]>(); linesArray.Add(new double[] { 0, 0, 0.08, 0 }); linesArray.Add(new double[] { 0.08, 0, 0.08, 0.06 }); linesArray.Add(new double[] { 0.08, 0.06, 0.064, 0.06 }); linesArray.Add(new double[] { 0.064, 0.06, 0.064, 0.02 }); linesArray.Add(new double[] { 0.064, 0.02, 0.048, 0.02 }); linesArray.Add(new double[] { 0.048, 0.02, 0.048, 0.06 }); linesArray.Add(new double[] { 0.048, 0.06, 0.032, 0.06 }); linesArray.Add(new double[] { 0.032, 0.06, 0.032, 0.02 }); linesArray.Add(new double[] { 0.032, 0.02, 0.016, 0.02 }); linesArray.Add(new double[] { 0.016, 0.02, 0.016, 0.06 }); linesArray.Add(new double[] { 0.016, 0.06, 0, 0.06 }); linesArray.Add(new double[] { 0, 0.06, 0, 0 }); // Get a reference to the models collection. models = partDocument.Models; // Call helper method to create the actual geometry. model = PartHelper.CreateFiniteExtrudedProtrusion(partDocument, refPlane, linesArray.ToArray(), SolidEdgePart.FeaturePropertyConstants.igRight, 0.005); body = (SolidEdgeGeometry.Body)model.Body; faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; thickens = model.Thickens; Type type = typeof(SolidEdgePart.FeaturePropertyConstants); var fields = type.GetFields(); for (int i = 1; i <= faces.Count; i++) { model = models.Item(1); body = (SolidEdgeGeometry.Body)model.Body; faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; thickens = model.Thickens; face = faces.Item(i) as SolidEdgeGeometry.Face; Array facesArray = Array.CreateInstance(typeof(SolidEdgeGeometry.Face), 1); facesArray.SetValue(face, 0); foreach (var field in fields) { if (field.IsSpecialName) { continue; } SolidEdgePart.FeaturePropertyConstants side = (SolidEdgePart.FeaturePropertyConstants)field.GetRawConstantValue(); try { thicken = thickens.Add(side, 0.0254, 1, ref facesArray); thicken.Delete(); break; } catch { } } //thicken = thickens.Add(SolidEdgePart.FeaturePropertyConstants.igReverseNormalSideDummy, 0.0254, 1, ref facesArray); //selectSet = application.ActiveSelectSet; //selectSet.RemoveAll(); //selectSet.Add(faces.Item(1)); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }