1 Reply Latest reply on Aug 17, 2017 6:49 PM by Nilesh Patel

    Get the two components constrained by a mate

    Omar Kermad

      I can get all the components in an assembly and add them to a list:


      var assembly = (AssemblyDoc)swModel;
      var components = (object[])assembly.GetComponents(false);
      var componentList = new List<Component2>();
      foreach (var component in components)


      But I am unable to find most of the components constrained by the mates in the list:


      foreach (var component in components)
          var swcomponent = (Component2)component ;
          var mates = (object[])swcomponent.GetMates();
          foreach (var mate in mates)
              var swmate = (IMate2)mate;
              var entity1 = swmate.MateEntity(0);
              var entity2 = swmate.MateEntity(1);
              var component1 = entity1.ReferenceComponent;
              var component2 = entity2.ReferenceComponent;
               var found1 = componentList.Contains(component1);
               var found2 = componentList.Contains(component2);


      My model (attached) is quite basic: the assembly contains two subassemblies (which are in fact instances of the same assembly) mated together, with each subassembly containing two parts mated together.


      How can I uniquely determine which parts in the assembly each mate constrains. I need to be able to distinguish between parts that are used in different assemblies (e.g. TwoBarHinge<1>/Bar<1> should be distinguishable from TwoBarHinge<2>/Bar<1>).


      I have tried comparing names, but the names that I get out of the two components for the mate don't contain the assembly when the mate is between two parts in the same subassembly. So, for example, whilst I read full names like TwoBarHinge<1>/Bar<1> when iterating through the list of components, I only read Bar<1> from the components constrained by the mate.


      Thank you.