UG Secondary Program - Accessing Bodies, Faces and Edges

本文详细介绍了如何使用NXOpen API在CAD软件中操作体、面和边,包括获取部分、体、面和边的相关属性和方法,以及如何通过这些方法获取相关对象之间的关系。文中提供了C++、.NET、Java等不同语言环境下实现的示例。

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

Bodies, Faces and Edges - Language Specific Details

NX Open for C++

NX Open for .NET

NX Open for Java

NX Open for C++
NX session → list of parts

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);
  }
part → list of solid bodies

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);
   }
}
solid body → list of faces

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]);
	  }
} 
solid body → list of edges

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 → list of associated edges
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 → list of associated faces
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();
}
NX Open for .NET
NX session → list of parts

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
part → list of solid bodies

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
solid body → list of faces

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
solid body → list of edges

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 → list of associated edges
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 → list of associated faces
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
NX Open for Java
NX session → list of parts

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);
   }
part → list of solid bodies

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); 
   } 
}
solid body → list of faces

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]);
    }
}
solid body → list of edges

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 → list of associated edges
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 → list of associated faces
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(); 
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值