Get list of elements in Assembly

Get list of elements in Assembly

Jes_Gonzalez
Advocate Advocate
3,118 Views
6 Replies
Message 1 of 7

Get list of elements in Assembly

Jes_Gonzalez
Advocate
Advocate

Hello, I'm trying to create a export that will get assembly name then list all elements that are tied to that assembly and export to txt. So the issues I'm running into is that i can return the element and i can return the assembly but i can get them to return together, they come in two separate  list. Any help would be greatly appreciated. 

 

 

 

 

 

List<AssemblyInstance> ListAssemblies_ClassActiveView = sc.GetAssemblies_ActiveView(doc);

List<FabricationPart> ListFabrication_ClassActiveView = sc.GetPipe_ActiveView(doc);

 

TaskDialog.Show("Values", "Brandt Spools \n" + SB(ListAssemblies_ClassActiveView).ToString());

TaskDialog.Show("Values", "Brandt Fabrication \n" + SB(ListFabrication_ClassActiveView).ToString());

 

return Result.Succeeded;

 

}
public StringBuilder SB(List<AssemblyInstance> assemblies)
{

StringBuilder sb = new StringBuilder();


foreach (AssemblyInstance ai in assemblies)
//sb.Append(ai.Name + "" + ai.Id + "\n");
sb.Append(ai.Name + "" + ai.GetMemberIds());


//sb.Append(ai.Name + "" + ai.Id + "\n" + ai.GetMemberIds());

return sb;

}

 

private StringBuilder SB(List<FabricationPart> pipe)
{

StringBuilder sb = new StringBuilder();


foreach (FabricationPart fabpart in pipe)
sb.Append(fabpart.ProductName + "" + fabpart.Id + "\n");


//sb.Append(ai.Name + "" + ai.Id + "\n" + ai.GetMemberIds());

return sb;

}

0 Likes
Accepted solutions (1)
3,119 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

Yes, well, you are obviously calling two separate methods, storing the results in two separate lists, and displaying the lists in two separate task dialogue forms.

 

The behaviour you describe is an obvious consequence of that.

 

Furthermore, the code you share says next to nothing about how the elements are retrieved.

 

So there is little I can say about this.

 

Maybe it would help if you share a minimal sample model with a couple of assemblies and elements tied to them, so we can understand better what you are after.

  

Best regards,

 

Jeremy

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 7

Jes_Gonzalez
Advocate
Advocate

Sorry, here is a sample project along with what I have so far. I wasn't able to upload it due to size but its all in my google drive. 

 

 

https://drive.google.com/open?id=1VXqIUcxRWkLiDqyLM5nmBE7NXKp46IzT

0 Likes
Message 4 of 7

jeremytammik
Autodesk
Autodesk

Thank you, but I would prefer a small project, not a large one.

 

Minimal, as said  🙂

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 7

Jes_Gonzalez
Advocate
Advocate

Here you go, thanks again Jeremy.

0 Likes
Message 6 of 7

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Jes,

 

Thank you for your sample model.

 

Now, I'll step through the process for you, as I have done repeatedly in the past for others.

 

I regularly document these steps in an attempt to teach people how to fish instead of feeding them eternally.

 

Unfortunately, it never seems to end...

 

So, this is what your sample model looks like:

assembly_pipework_sample_model.png

 

  • Open spool_testing.rvt
  • I see one free-floating run of MEP pipework and one MEP pipework assembly
  • Select the assembly
  • Use RevitLookup Snoop Objects on it
  • It is an AssemblyInstance object
  • Click on the GetMemberIds method
  • It returns a list of 11 Element and 11 FabricationPart objects
  • The Element objects have an empty Name property
  • The FabricationPart objects are named 'Default'
  • Therefore, the Name property does not seem very useful in this case
  • If I dig deep enough into their properties, I find useful descriptive strings on each
  • For instance, 'FP Description' seems more useful

 

On one of the Element objects, I discovered the shared parameter 'FP Description' with a GUID value 'ac6ed937-ffb7-4b18-9c69-7541f5c0319d' saying 'Victaulic 741 Vic Flange Adapter'.

assembly_pipework_2_snoop_description.png

 

One of the FabricationPart objects has that parameter as well.

 

Let's grab the description from that on the assembly itself also.

 

Then, we can implement the following to list them:

 

  List<string> ListElementsInAssembly(
    Document doc )
  {
    // 'FP Description' shared parameter GUID

    Guid guid = new Guid(
      "ac6ed937-ffb7-4b18-9c69-7541f5c0319d" );

    FilteredElementCollector assemblies
      = new FilteredElementCollector( doc )
        .OfClass( typeof( AssemblyInstance ) );

    List<string> descriptions = new List<string>();

    int n;
    string s;

    foreach( AssemblyInstance a in assemblies )
    {
      ICollection<ElementId> ids = a.GetMemberIds();

      n = ids.Count;

      s = string.Format(
        "\r\nAssembly {0} has {1} member{2}{3}",
        a.get_Parameter( guid ).AsString(),
        n, Util.PluralSuffix( n ), Util.DotOrColon( n ) );

      descriptions.Add( s );

      n = 0;

      foreach( ElementId id in ids )
      {
        Element e = doc.GetElement( id );

        descriptions.Add( string.Format( "{0}: {1}",
          n++, e.get_Parameter( guid ).AsString() ) );
      }
    }

    Debug.Print( string.Join( "\r\n", descriptions ) );

    return descriptions;
  }

 

Running this method in your small sample model generates the following output in the Visual Studio debug window:

 

  Assembly L6-AHU-31-32-CS-CHWR-17 has 22 members:
  0: Victaulic 90 Elbow No 10
  1: Victaulic 90 Elbow No 10
  2: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  3: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  4: Chicago Area A53 ERW Sch 40 Blk GRV Pipe
  5: Chicago Area A53 ERW Sch 40 Blk GRV Pipe
  6: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  7: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  8: Victaulic 761 10PosHndl AlBzTrim E Seat
  9: Victaulic 761 10PosHndl AlBzTrim E Seat
  10: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  11: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  12: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  13: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  14: Chicago Area A53 ERW Sch 40 Blk GRV Pipe
  15: Chicago Area A53 ERW Sch 40 Blk GRV Pipe
  16: Chicago Area A53 ERW Sch 40 Blk GRV Pipe
  17: Chicago Area A53 ERW Sch 40 Blk GRV Pipe
  18: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  19: VICTAULIC COMPANY 2-QUICKVIC STYLE 107N COUPLING
  20: Victaulic 741 Vic Flange Adapter
  21: Victaulic 741 Vic Flange Adapter

 

Is that what you are after?

 

I added this code to The Building Coder samples:

 

https://github.com/jeremytammik/the_building_coder_samples

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 7

Jes_Gonzalez
Advocate
Advocate

WOW! Thank you Jeremy!

0 Likes