Begtostudy(白途思)'s Professional Technology Blog

欢迎访问begtostudy的专业知识博客!主要是专业技术和算法为主。
  首页  :: 联系 :: 订阅 订阅  :: 管理

UG Secondary Program - Accessing Bodies, Faces and Edges

Posted on 2010-11-19 17:11  白途思  阅读(614)  评论(0编辑  收藏  举报

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(); 
}
原文:http://blog.csdn.net/begtostudy/archive/2008/08/19/2797815.aspx
前往Begtostudy的编程知识博客(CSDN)