How to access a an element in a loaded family

How to access a an element in a loaded family

aclarke
Advocate Advocate
1,238 Views
2 Replies
Message 1 of 3

How to access a an element in a loaded family

aclarke
Advocate
Advocate

Hi all,

 

How can I enter a loaded family and access elements in this loaded family?  Specifically a filled region that is placed in a Title Block, I want to return this filled region's bounding box.

 

I have tried 'GetSubComponentIds()' and 'GetSubelements()' but both return '0'.

ISelectionFilter filter = new myFunctions.mySelectionFilter();
            Reference reference = uidoc.Selection.PickObject(ObjectType.Element, filter);

            FamilyInstance e = (FamilyInstance)doc.GetElement(reference);
            TD(e.GetSubelements().Count.ToString());

what I am doing is returning a count of sub elements, just to see if I can access them, here is the code I used

 

TD() is shortcut function for TaskDialog.Show("task", e.GetSubelements().Count.ToString());

 

When I select my title border with the code, the result is '0' but  this border is full of stuff.

 

Reading this, https://thebuildingcoder.typepad.com/blog/2010/02/nested-family-instance.html

Maybe I need to use 'GetSubComponentIds()' and 'SuperComponent' but I still get '0' when replacing 'GetSubelements' with 'GetSubComponentIds().  I am assuming that SuperComponent is the parent family, the definition is not clear.  But I still return '0' with GetSubComponentIds which I am assuming is the nested family since maybe SuperComponent is a parent family?  But neither definition is clear in the Revit API Doc.

 

Any guidance would be greatly appreciated.

 

Thanks

 

AlanC.

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

jeremytammik
Autodesk
Autodesk
Accepted solution

You have a Document instance representing your currently opened project model.

 

The loaded family is a completely different Document object.

 

You can retrieve the `document instance representing the loaded family via EditFamily:

 

https://www.revitapidocs.com/2020/56e636ee-5008-0ee5-9d6c-5f622dedfbcb.htm

 

It takes a Family argument that can be retrieved from the loaded family, or a family symbol, or a family instance.

 



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

Message 3 of 3

aclarke
Advocate
Advocate

Thank you Jeremy

 

ISelectionFilter filter = new myFunctions.mySelectionFilter();
            Reference reference = uidoc.Selection.PickObject(ObjectType.Element, filter);

            FamilyInstance e = (FamilyInstance)doc.GetElement(reference);

            Document familyDoc = doc.EditFamily(e.Symbol.Family);
            foreach (FilledRegion i in CollectedFilledRegion(familyDoc))
            {
                TD(familyDoc.GetElement(i.GetTypeId()).Name);
            }



public static List<FilledRegion> CollectedFilledRegion(Document doc)
        {
            List<FilledRegion> collector = new FilteredElementCollector(doc)
                .OfClass(typeof(FilledRegion))
                .Cast<FilledRegion>()
                .ToList();
            return collector;
        }
0 Likes