private void button3_Click(object sender, EventArgs e) { // Connect to or start Solid Edge. YCC_solidedge.getEdgeApplication(ref SEApp, true); SolidEdgeAssembly.AssemblyDocument asydoc = (SolidEdgeAssembly.AssemblyDocument)SEApp.ActiveDocument; SolidEdgeAssembly.Occurrences occs = (SolidEdgeAssembly.Occurrences)asydoc.Occurrences; SolidEdgeAssembly.Occurrence occ = (SolidEdgeAssembly.Occurrence)occs.Item(2); Array MinRangePoint = Array.CreateInstance(typeof(double), 0); Array MaxRangePoint = Array.CreateInstance(typeof(double), 0); //object[] w = new object[3]; occ.GetRangeBox(ref MinRangePoint, ref MaxRangePoint); SolidEdgePart.PartDocument ps = (SolidEdgePart.PartDocument)occ.OccurrenceDocument; //SolidEdgePart.Models ms = (SolidEdgePart.Models)ps.Models.Item[1]; SolidEdgePart.Model m = (SolidEdgePart.Model)ps.Models.Item(1); SolidEdgeGeometry.Body b = (SolidEdgeGeometry.Body)m.Body; SolidEdgeGeometry.Edges ees = (SolidEdgeGeometry.Edges)b.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; SolidEdgeGeometry.Edge ee = (SolidEdgeGeometry.Edge)ees.Item(1); //ee.GetRange(ref MinRangePoint, ref MaxRangePoint); b.GetRange(ref MinRangePoint, ref MaxRangePoint); }
static void CreateFaceRotateByGeometry(SolidEdgePart.PartDocument partDocument) { SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgeGeometry.Body body = null; SolidEdgePart.FaceRotates faceRotates = null; SolidEdgePart.FaceRotate faceRotate = null; SolidEdgeGeometry.Faces faces = null; SolidEdgeGeometry.Face face = null; SolidEdgeGeometry.Edges edges = null; SolidEdgeGeometry.Edge edge = null; double angle = 0.5; // Get a reference to the models collection. models = partDocument.Models; model = models.Item(1); body = (SolidEdgeGeometry.Body)model.Body; faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; face = (SolidEdgeGeometry.Face)faces.Item(2); edges = (SolidEdgeGeometry.Edges)body.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; edge = (SolidEdgeGeometry.Edge)edges.Item(5); faceRotates = model.FaceRotates; // Add face rotate. faceRotate = faceRotates.Add( face, SolidEdgePart.FaceRotateConstants.igFaceRotateByGeometry, SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends, null, null, edge, SolidEdgePart.FaceRotateConstants.igFaceRotateAxisEnd, angle); }
// In a real world scenario, you would want logic (or user input) to pick the desired // face, edge & *vertex. Here, we just grab the 1st we can find. *Vertex can be null. static void GetFaceEdgeVertexForModel( SolidEdgePart.Model model, out SolidEdgeGeometry.Face face, out SolidEdgeGeometry.Edge edge, out SolidEdgeGeometry.Vertex vertex) { SolidEdgeGeometry.Body body = null; SolidEdgeGeometry.Faces faces; SolidEdgeGeometry.Edges edges = null; // Get a reference to the model's body. body = (SolidEdgeGeometry.Body)model.Body; // Query for all faces in the body. faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; // Get a reference to the first face. face = (SolidEdgeGeometry.Face)faces.Item(1); // Get a reference to the face's Edges collection, edges = (SolidEdgeGeometry.Edges)face.Edges; // Get a reference to the first edge. edge = (SolidEdgeGeometry.Edge)edges.Item(1); // Not using vertex in this example. vertex = null; }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgePart.PartDocument partDocument = null; SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgeGeometry.Body body = 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); // Bring Solid Edge to the foreground. application.Activate(); // Get a reference to the active part document. partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false); if (partDocument != null) { models = partDocument.Models; if (models.Count == 0) { throw new System.Exception("No geometry defined."); } model = models.Item(1); body = (SolidEdgeGeometry.Body)model.Body; Array MinRangePoint = Array.CreateInstance(typeof(double), 0); Array MaxRangePoint = Array.CreateInstance(typeof(double), 0); body.GetRange(ref MinRangePoint, ref MaxRangePoint); } else { throw new System.Exception("No active document."); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void CreateFaceRotateByPoints(SolidEdgePart.PartDocument partDocument) { SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgeGeometry.Body body = null; SolidEdgePart.FaceRotates faceRotates = null; SolidEdgePart.FaceRotate faceRotate = null; SolidEdgeGeometry.Faces faces = null; SolidEdgeGeometry.Face face = null; SolidEdgeGeometry.Vertices vertices = null; SolidEdgeGeometry.Vertex point1 = null; SolidEdgeGeometry.Vertex point2 = null; double angle = 0.0872664625997165; // Get a reference to the models collection. models = partDocument.Models; model = models.Item(1); body = (SolidEdgeGeometry.Body)model.Body; faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; face = (SolidEdgeGeometry.Face)faces.Item(1); vertices = (SolidEdgeGeometry.Vertices)face.Vertices; point1 = (SolidEdgeGeometry.Vertex)vertices.Item(1); point2 = (SolidEdgeGeometry.Vertex)vertices.Item(2); faceRotates = model.FaceRotates; // Add face rotate. faceRotate = faceRotates.Add( face, SolidEdgePart.FaceRotateConstants.igFaceRotateByPoints, SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends, point1, point2, null, SolidEdgePart.FaceRotateConstants.igFaceRotateNone, angle); }
private void button4_Click(object sender, EventArgs e) { YCC_solidedge.getEdgeApplication(ref SEApp, true); partDoc = (SolidEdgePart.PartDocument)SEApp.ActiveDocument; SolidEdgePart.Model md = partDoc.Models.Item(1); SolidEdgeGeometry.Body by = (SolidEdgeGeometry.Body)md.Body; SolidEdgeGeometry.Edges ed = (SolidEdgeGeometry.Edges)by.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryStraight]; List <SolidEdgeGeometry.Edge> ListExceptionEdge = new List <SolidEdgeGeometry.Edge>(); int Count = 0; foreach (SolidEdgeGeometry.Edge _e in ed) { if (ListExceptionEdge.Contains(_e)) { continue; } SEEdge newpoint = new SEEdge(_e); if (newpoint.Len == 23.09 || newpoint.Len == 11.55) { POP newPOP = new POP(newpoint); Count = Count + 1; if (newPOP.ListHexagonEdge.Count == 6) { foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListHexagonEdge) { ListExceptionEdge.Add(_edge); } foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListHoleEdge) { ListExceptionEdge.Add(_edge); } foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListOtherHexagonEdge) { ListExceptionEdge.Add(_edge); } } } } //bool done = true; //int count = 0; //while (done) //{ // foreach (SEEdge _p in point23) // { // if (www(ref point23, _p)) // { // count++; // break; // } // if (_p == point23[point23.Count() - 1]) done = false; // } // if (point23.Count == 0) done = false; //} }
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; SolidEdgePart.FaceRotates faceRotates = null; SolidEdgePart.FaceRotate faceRotate = null; SolidEdgeGeometry.Faces faces = null; SolidEdgeGeometry.Face face = null; SolidEdgeGeometry.Vertices vertices = null; SolidEdgeGeometry.Vertex point1 = null; SolidEdgeGeometry.Vertex point2 = null; SolidEdgeFramework.SelectSet selectSet = null; double angle = 0.0872664625997165; 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; // Create a new part document. partDocument = documents.AddPartDocument(); // Get a reference to the RefPlanes collection. refPlanes = partDocument.RefPlanes; // Get a reference to a RefPlane. refPlane = refPlanes.GetFrontPlane(); // Always a good idea to give SE a chance to breathe. application.DoIdle(); 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 }); // Call helper method to create the actual geometry. PartHelper.CreateFiniteExtrudedProtrusion(partDocument, refPlane, linesArray.ToArray(), SolidEdgePart.FeaturePropertyConstants.igRight, 0.005); // Get a reference to the models collection. models = partDocument.Models; model = models.Item(1); body = (SolidEdgeGeometry.Body)model.Body; faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; face = (SolidEdgeGeometry.Face)faces.Item(1); vertices = (SolidEdgeGeometry.Vertices)face.Vertices; point1 = (SolidEdgeGeometry.Vertex)vertices.Item(1); point2 = (SolidEdgeGeometry.Vertex)vertices.Item(2); faceRotates = model.FaceRotates; // Add face rotate. faceRotate = faceRotates.Add( face, SolidEdgePart.FaceRotateConstants.igFaceRotateByPoints, SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends, point1, point2, null, SolidEdgePart.FaceRotateConstants.igFaceRotateNone, angle); // Get a reference to the ActiveSelectSet. selectSet = application.ActiveSelectSet; // Empty ActiveSelectSet. selectSet.RemoveAll(); // Add new FaceRotate to ActiveSelectSet. selectSet.Add(faceRotate); // Switch to ISO view. application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgePart.PartDocument partDocument = null; SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgeGeometry.Body body = 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); // Bring Solid Edge to the foreground. application.Activate(); // Get a reference to the active part document. partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false); if (partDocument != null) { models = partDocument.Models; if (models.Count == 0) { throw new System.Exception("No geometry defined."); } model = models.Item(1); body = (SolidEdgeGeometry.Body)model.Body; int facetCount = 0; Array points = Array.CreateInstance(typeof(double), 0); object normals = Array.CreateInstance(typeof(double), 0); object textureCoords = Array.CreateInstance(typeof(double), 0); object styleIds = Array.CreateInstance(typeof(int), 0); object faceIds = Array.CreateInstance(typeof(int), 0); //Returns the number of facets and the number of points on the facets for the referenced object. // If Tolerance <= 0, then data is returned from the geometry cache, and not from Parasolid. body.GetFacetData( Tolerance: 0.1, FacetCount: out facetCount, Points: ref points, Normals: out normals, TextureCoords: out textureCoords, StyleIDs: out styleIds, FaceIDs: out faceIds, bHonourPrefs: false); // We really need an explpanation from development on how to process the out variables. } else { throw new System.Exception("No active document."); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
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(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgePart.PartDocument partDocument = null; SolidEdgePart.Models models = null; SolidEdgeGeometry.Body body = null; SolidEdgeGeometry.Shells shells = null; SolidEdgeGeometry.Shell shell = null; SolidEdgePart.Constructions constructions = null; SolidEdgePart.ConstructionModel constructionModel = null; int bodyCount = 0; 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); // Bring Solid Edge to the foreground. application.Activate(); // Get a reference to the active part document. partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false); if (partDocument != null) { models = partDocument.Models; // Check for solid design bodies. foreach (var model in models.OfType <SolidEdgePart.Model>()) { body = (SolidEdgeGeometry.Body)model.Body; if (body.IsSolid) { shells = (SolidEdgeGeometry.Shells)body.Shells; for (int i = 1; i <= shells.Count; i++) { shell = (SolidEdgeGeometry.Shell)shells.Item(i); if (shell != null) { if ((shell.IsClosed) && (shell.IsVoid == false)) { bodyCount++; } } } } } // Check for solid construction bodies. constructions = partDocument.Constructions; for (int i = 1; i <= constructions.Count; i++) { constructionModel = constructions.Item(i) as SolidEdgePart.ConstructionModel; if (constructionModel != null) { body = (SolidEdgeGeometry.Body)constructionModel.Body; if (body.IsSolid) { bodyCount++; } } } Console.WriteLine("Active part document contains ({0}) solid bodies.", bodyCount); } else { throw new System.Exception("No active document."); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgePart.SheetMetalDocument sheetMetalDocument = null; SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgePart.FlatPatternModels flatPatternModels = null; SolidEdgePart.FlatPatternModel flatPatternModel = null; SolidEdgeGeometry.Body body = null; SolidEdgeGeometry.Faces faces; SolidEdgeGeometry.Face face = null; SolidEdgeGeometry.Edges edges = null; SolidEdgeGeometry.Edge edge = null; SolidEdgeGeometry.Vertex vertex = null; bool useFlatPattern = true; bool flatPatternIsUpToDate = false; string outFile = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to Solid Edge, application = SolidEdgeCommunity.SolidEdgeUtils.Connect(false); // Get a reference to the Documents collection. documents = application.Documents; // Get a refernce to the active sheetmetal document. sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false); if (sheetMetalDocument == null) { throw new System.Exception("No active document."); } // Get a reference to the Models collection, models = sheetMetalDocument.Models; // Check for geometry. if (models.Count == 0) { throw new System.Exception("No geometry defined."); } // Get a reference to the one and only model. model = models.Item(1); // Get a reference to the FlatPatternModels collection, flatPatternModels = sheetMetalDocument.FlatPatternModels; // Observation: SaveAsFlatDXFEx() will fail if useFlatPattern is specified and // flatPatternModels.Count = 0. // The following code will turn off the useFlatPattern switch if flatPatternModels.Count = 0. if (useFlatPattern) { if (flatPatternModels.Count > 0) { for (int i = 1; i <= flatPatternModels.Count; i++) { flatPatternModel = flatPatternModels.Item(i); flatPatternIsUpToDate = flatPatternModel.IsUpToDate; // If we find one that is up to date, call it good and bail. if (flatPatternIsUpToDate) { break; } } if (flatPatternIsUpToDate == false) { // Flat patterns exist but are out of date. useFlatPattern = false; } } else { // Can't use flat pattern if none exist. useFlatPattern = false; } } // In a real world scenario, you would want logic (or user input) to pick the desired // face, edge & *vertex. Here, we just grab the 1st we can find. *Vertex can be null. // Get a reference to the model's body. body = (SolidEdgeGeometry.Body)model.Body; // Query for all faces in the body. faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll]; // Get a reference to the first face. face = (SolidEdgeGeometry.Face)faces.Item(1); // Get a reference to the face's Edges collection, edges = (SolidEdgeGeometry.Edges)face.Edges; // Get a reference to the first edge. edge = (SolidEdgeGeometry.Edge)edges.Item(1); // Not using vertex in this example. vertex = null; outFile = System.IO.Path.ChangeExtension(sheetMetalDocument.FullName, ".dxf"); // Observation: If .par or .psm is specified in outFile, SE will open the file. // Even if useFlatPattern = true, it's a good idea to specify defaults for face, edge & vertex. // I've seen where outFile of .dxf would work but .psm would fail if the defaults were null; models.SaveAsFlatDXFEx(outFile, face, edge, vertex, useFlatPattern); if (useFlatPattern) { Console.WriteLine("Saved '{0}' using Flat Pattern.", outFile); } else { Console.WriteLine("Saved '{0}' without using Flat Pattern.", outFile); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }