admin 发表于 2018-7-27 10:56:17

NX二次开放源码分享: 获取装配下所有的实体


NX二次开放源码分享: 获取装配下所有的实体



public class report_all_bodies_in_assembly_level
{
public static void Main(string[] args)
{
    Session theSession = Session.GetSession();
    UFSession theUFSession = UFSession.GetUFSession();
    ListingWindow theLW = theSession.ListingWindow;


    Part theDispPart = theSession.Parts.Display;
    List<Body> theBodies = new List<Body>();
    Tag aTag = Tag.Null;
    int type = 0, subtype = 0;


    theLW.Open();
    do
    {
      theUFSession.Obj.CycleObjsInPart(theDispPart.Tag, UFConstants.UF_solid_type, ref aTag);
      if (aTag == Tag.Null) break;
      theUFSession.Obj.AskTypeAndSubtype(aTag, out type, out subtype);


      if (subtype == UFConstants.UF_solid_body_subtype)
      {
      Body obj = (Body)theSession.GetObjectManager().GetTaggedObject(aTag);
      if (obj is Body) theBodies.Add(obj);
      }
    } while (true);


    theLW.WriteLine("Bodies in the list: " + theBodies.Count.ToString());
    foreach( Body theBody in theBodies )
    {
      if (theBody.IsOccurrence)
      theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Component: {3}",
          theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningComponent.DisplayName));
      else
      theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Part: {3}",
          theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningPart.Leaf));
    }
}
}

页: [1]
查看完整版本: NX二次开放源码分享: 获取装配下所有的实体