-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
109 lines (100 loc) · 6.97 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TopologyTraverseByAPI
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Open part document continue...");
Console.WriteLine("Traversal Started !!");
interop.CimAppAccess.AppAccess CimAppAcc = new interop.CimAppAccess.AppAccess();
interop.CimatronE.IApplication aCimApplication = (interop.CimatronE.IApplication)CimAppAcc.GetActiveApplication();
interop.CimatronE.ICimDocument aDoc = aCimApplication.GetActiveDoc();
interop.CimMdlrAPI.IModelContainer aContainer = (interop.CimMdlrAPI.IModelContainer)aDoc;
interop.CimMdlrAPI.IMdlrModel aMdlrModel = (interop.CimMdlrAPI.IMdlrModel)aContainer.Model;
interop.CimBaseAPI.IEntityQuery aMdlrQuery = (interop.CimBaseAPI.IEntityQuery)aMdlrModel;
interop.CimBaseAPI.IEntityFilter aEntityFilter = aMdlrQuery.CreateFilter(interop.CimBaseAPI.EFilterEnumType.cmFilterEntityType);
//Get All bodies in MdlrModel
interop.CimBaseAPI.FilterType aFilter = (interop.CimBaseAPI.FilterType)aEntityFilter;
aFilter.Add(interop.CimBaseAPI.EntityEnumType.cmBody);
aMdlrQuery.SetFilter((interop.CimBaseAPI.IEntityFilter)aFilter);
interop.CimBaseAPI.ICimEntityList aBodyList = aMdlrQuery.Select();
if (aBodyList.Count > 0)
{
Console.WriteLine("Bodies Count = " + aBodyList.Count);
foreach (interop.CimBaseAPI.ICimEntity aBody in aBodyList)
{
int aBodyId = aBody.ID;
//------------------------------------------------BodyUtility------------------------------------------------
//Use body utility functions
BodyUtility aBodyUtility = new BodyUtility();
//Get All Faces from body
interop.CimBaseAPI.ICimEntityList aFaceListRelatedToBody = aBodyUtility.GetAllFaces(aBody);
int aIsWireBody = aBodyUtility.IsWirebody(aBody);
//------------------------------------------------------------------------------------------------
if (aIsWireBody == 1) //Sketch is also treated as body
continue;
//Get All Faces in aBody
interop.CimBaseAPI.IEntityQuery aBodyQuery = (interop.CimBaseAPI.IEntityQuery)aBody;
interop.CimBaseAPI.IEntityFilter aEntFilter = aBodyQuery.CreateFilter(interop.CimBaseAPI.EFilterEnumType.cmFilterEntityType);
interop.CimBaseAPI.FilterType aFaceFilter = (interop.CimBaseAPI.FilterType)aEntFilter;
aFaceFilter.Add(interop.CimBaseAPI.EntityEnumType.cmFace);
aBodyQuery.SetFilter((interop.CimBaseAPI.IEntityFilter)aFaceFilter);
interop.CimBaseAPI.ICimEntityList aFaces = aBodyQuery.Select();
if (aFaces.Count > 0)
{
Console.WriteLine("Face Count = " + aFaces.Count);
foreach (interop.CimBaseAPI.ICimEntity aFace in aFaces)
{
int aFaceId = aFace.ID;
//--------------------------------------------FaceUtility----------------------------------------------------
//Use face utility functions
FaceUtility aFaceUtility = new FaceUtility();
//Get All Edges in face
interop.CimBaseAPI.ICimEntityList aEdgeListRelatedToFace = aFaceUtility.GetAllEdges(aFace);
//Get All Loops in face
interop.CimBaseAPI.ICimEntityList aLoopListRelatedToFace = aFaceUtility.GetAllLoops(aFace);
//Get parent body of face
interop.CimBaseAPI.ICimEntity aBodyRelatedToFace = aFaceUtility.GetParentBody(aFace);
//Get surface data of face, IGeom3DSurface has all functions which provide surface information
interop.CimServicesAPI.IGeom3DSurface aSurface = aFaceUtility.GetSurfaceData(aFace);
//------------------------------------------------------------------------------------------------
if (aEdgeListRelatedToFace.Count > 0)
{
foreach (interop.CimBaseAPI.ICimEntity aEdge in aEdgeListRelatedToFace)
{
int aEdgeId = aEdge.ID;
//-------------------------------------------EdgeUtility-----------------------------------------------------
//Use edge utility functions
EdgeUtility aEdgeUtility = new EdgeUtility();
interop.CimBaseAPI.ICimEntityList aCoedgeListRelatedToEdge = aEdgeUtility.GetCoedges(aEdge);
interop.CimBaseAPI.ICimEntityList aFaceListRelatedToEdge = aEdgeUtility.GetConnectedFaces(aEdge);
interop.CimBaseAPI.ICimEntityList aVerticesListRelatedToEdge = aEdgeUtility.GetVertices(aEdge);
//Get curve data of edge, IGeom3DCurve has all functions which provide curve information
interop.CimServicesAPI.IGeom3DCurve aCurve = aEdgeUtility.GetCurve(aEdge);
//------------------------------------------------------------------------------------------------
if (aVerticesListRelatedToEdge.Count > 0)
{
foreach (interop.CimBaseAPI.ICimEntity aVertex in aVerticesListRelatedToEdge)
{
//--------------------------------------------VertexUtility----------------------------------------------------
//Use vertex utility functions
VertexUtility aVertexUtility = new VertexUtility();
interop.CimBaseAPI.ICimEntityList aEdgeListRelatedToVertex = aVertexUtility.GetConnectedEdges(aVertex);
double[] aVertexLocation = aVertexUtility.GetVertexLocation(aVertex);
//------------------------------------------------------------------------------------------------
}
}
}
}
}
}
}
}
}
}
}