Get elements which are part of a selected assembly

Get elements which are part of a selected assembly

Anonymous
Not applicable
2,457 Views
3 Replies
Message 1 of 4

Get elements which are part of a selected assembly

Anonymous
Not applicable

Hi,

 

I am trying to get a list of all elements that are not selected, so that I can hide them in a view, however I am running into a problem with elements that are part of assemblies. I am currently getting a list of all elements inside a view, and excluding those elements which are selected with this:

ICollection<ElementId> selection = data.Application.ActiveUIDocument.Selection.GetElementIds();
ICollection<ElementId> toHide = new List<ElementId>();
FilteredElementCollector collector
    = new FilteredElementCollector(doc, view.Id)
    .WhereElementIsNotElementType()
    .Excluding(selection);

I am then hiding each element in toHide, however the .Selection does not contain elements which are part of a selected assembly, so even if an assembly is selected, the elements inside it get hidden. 

 

I am wondering if there is any way to get either a list of selected assemblies and the elements inside them, or even just a list of all elements which are part of assemblies. If there is no way of knowing that an element is part of a assembly which is selected, then I would be fine excluding all elements which are part of an assembly. In this case, how could I check to see that an element is part of an assembly?

 

Any help would be great, thanks.

0 Likes
Accepted solutions (1)
2,458 Views
3 Replies
Replies (3)
Message 2 of 4

Aaron.Lu
Autodesk
Autodesk
Accepted solution
Dear, I think you can
- get the id and then get element from document,
- and cast the element to AssemblyInstance
- then use AssemblyInstance.GetMemberIds() to get all its parts.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 3 of 4

Anonymous
Not applicable

This worked great, thanks for the help.

0 Likes
Message 4 of 4

Jes_Gonzalez
Advocate
Advocate

Do you guys have an example of the code? I'm trying to achieve the same thing. I'm having issue with my code.

 

 

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());

0 Likes