Each part may contain any number of solid bodies. Each solid body is defined by a set of faces and edges. Each face contains a reference to the body it belongs to and a list of edges that define the face. Each edge will also contain a reference to the owning body and a list of faces that are defined by the edge. NX Open makes it very easy to find the bodies in a part and then to find the relationships between the faces and edges that are used to define the solid body. This section shows examples of how the methods and properties of the body, face and edge objects are used to access the related objects.
Typically a body will have multiple faces and an edge will be used by two faces. However, there are exceptions. For instance, a sphere will only have a single face and no edges. Another example a cone, which will have two faces and a single edge.
The examples show how to access the following relationships:
-
NX session → list of parts
-
part → list of solid bodies
-
solid body → list of faces
solid body → list of edges
-
face → list of associated edges
face → solid body
-
edge → list of associated faces
edge → solid body
To access all parts in an NX session, use the Parts property to access the Part Collection. Then use the collection's iterator to access each part.
Session *NXSession = Session::GetSession();
PartCollection *partList = NXSession->Parts();
PartCollection::iterator itr;
for ( itr = partList->begin(); itr != partList->end(); ++itr )
{
processPart(*itr);
}
To access all solid bodies in a part, use the Bodies property to access the Body Collection. Then use the collection's iterator to access each body.
void processPart(Part *partObject)
{
BodyCollection *bodyList = partObject->Bodies();
BodyCollection::iterator itr;
for (itr = bodyList->begin(); itr != bodyList->end(); ++itr)
{
processBodyFaces(*itr);
processBodyEdges(*itr);
}
}
To access the faces of a body use the GetFaces() method to return an array of faces.
void processBodyEdges(Body *bodyObject)
{
std::vector <Edge *> edgeArray = bodyObject->GetEdges();
for (int inx = 0; inx < (int)edgeArray.size(); ++inx)
{
processEdge(edgeArray[inx]);
}
}
To access the edges in a body use the GetEdges() method to return an array of edges.
void processBodyEdges(Body *bodyObject)
{
std::vector <Edge *> edgeArray = bodyObject->GetEdges();
for (int inx = 0; inx < (int)edgeArray.size(); ++inx)
{
processEdge(edgeArray[inx]);
}
}
face → solid body
To access the edges for a face use the GetEdges() method to return an array of edges. To access the face's body use the GetBody() method.
void processFace(Face *faceObject)
{
std::vector<Edge *> edgeArray = faceObject->GetEdges();
for (int inx = 0; inx < (int)edgeArray.size(); ++inx)
{
processEdge(edgeArray[inx]);
}
Body *bodyOfFace = faceObject->GetBody();
}
edge → solid body
To access the faces associated with and edge use the GetFaces() method to return an array of faces. To access the edge's body use the GetBody() method.
void processEdge(Edge *edgeObject)
{
std::vector<Face *> faceArray = edgeObject->GetFaces();
for (int inx = 0; inx < (int)faceArray.size(); ++inx)
{
processEdgeFace(faceArray[inx]);
}
Body *bodyOfEdge = edgeObject->GetBody();
}
To access all parts in an NX session, use the Parts property to access the Part Collection. Then use a standard iterator method to access each part.
Dim NXSession As Session = Session.GetSession
For Each partObject As Part In NXSession.Parts()
processPart(partObject)
Next partObject
To access all solid bodies in a part, use the Bodies property to access the Body Collection. Then cast the object to the generic Object class to access the face and edge methods.
Sub processPart(ByVal partObject As Part)
For Each bodyObject As DisplayableObject In partObject.Bodies
processBodyFaces(CType(bodyObject, Object))
processBodyEdges(CType(bodyObject, Object))
Next bodyObject
End Sub
To access the faces of a body use the GetFaces() method to return an array of faces.
Sub processBodyFaces(ByVal bodyObject As Object)
For Each faceObject As Face In bodyObject.GetFaces()
processFace(faceObject)
Next faceObject
End Sub
To access a the edges in a body use the GetEdges() method to return an array of edges.
Sub processBodyEdges(ByVal bodyObject As Object)
For Each edgeObject As Edge In bodyObject.GetEdges()
processEdge(edgeObject)
Next edgeObject
End Sub
face → solid body
To access the edges for a face use the GetEdges() method to return an array of edges. To access the face's body use the GetBody() method.
Sub processFace(ByVal faceObject As Face)
For Each edgeObject As Edge In faceObject.GetEdges()
processEdge(edgeObject)
Next edgeObject
Dim bodyOfFace As Body = faceObject.GetBody()
End Sub
edge -→ solid body
To access the edges for a face use the GetEdges() method to return an array of edges. To access the face's body use the GetBody() method.
Sub processEdge(ByVal edgeObject As Edge)
For Each faceObject As Face In edgeObject.GetFaces()
processEdgeFace(faceObject)
Next faceObject
Dim bodyOfEdge As Body = edgeObject.GetBody()
End Sub
To access all parts in an NX session, use the "parts" property to access the Part Collection. Then use the collection's iterator to access each part.
NXSession = (Session) SessionFactory.get("Session");
Part partObject;
PartCollection partList = NXSession.parts();
PartCollection.Iterator itr;
for (itr = partList.iterator(); itr.hasNext();)
{
partObject = (Part) itr.next();
processPart(partObject);
}
To access all solid bodies in a part, use the "bodies" property to access the Body Collection. Then use the collection's iterator to access each body.
public static void processPart(Part partObject)
{
BodyCollection bodyList = partObject.bodies();
BodyCollection.Iterator itr;
for (itr = bodyList.iterator(); itr.hasNext();)
{
Body bodyObject = (Body) itr.next();
processBodyFaces(bodyObject);
processBodyEdges(bodyObject);
}
}
To access the faces of a body use the getFaces() method to return an array of faces.
public static void processBodyFaces(Body bodyObject)
{
Face faceArray[] = bodyObject.getFaces();
for (int inx=0; inx <(int)faceArray.size(); ++inx)
{
processFace(faceArray[inx]);
}
}
To access a the edges in a body use the getEdges() method to return an array of edges.
public static void processBodyEdges(Body bodyObject)
{
Edge edgeArray[] = bodyObject.getEdges();
for (int inx = 0; inx < edgeArray.length; ++inx)
{
processEdge(edgeArray[inx]);
}
}
face → solid body
To access the edges for a face use the getEdges() method to return an array of edges. To access the face's body use the getBody() method.
public static void processFace(Face faceObject)
{
Edge edgeArray[] = faceObject.getEdges();
for (int inx=0; inx < edgeArray.length; ++inx)
{
processEdge(edgeArray[inx]);
}
Body bodyOfFace = faceObject.getBody();
}
edge → solid body
To access the faces associated with and edge use the getFaces() method to return an array of faces. To access the edge's body use the getBody() method.
public static void processEdge(Edge edgeObject)
{
Face faceArray[] = edgeObject.getFaces();
for (int inx=0; inx <faceArray.length; ++inx)
{
processEdgeFace(faceArray[inx]);
}
Body bodyOfEdge = edgeObject.getBody();
}
本文详细介绍了如何使用NXOpen API在CAD软件中操作体、面和边,包括获取部分、体、面和边的相关属性和方法,以及如何通过这些方法获取相关对象之间的关系。文中提供了C++、.NET、Java等不同语言环境下实现的示例。
3431

被折叠的 条评论
为什么被折叠?



