How to delete family from document ?

Adamchuk_Nicolay
Enthusiast
Enthusiast

How to delete family from document ?

Adamchuk_Nicolay
Enthusiast
Enthusiast

Hi,

 

how to delete family from project (not symbol or instance) ?

Can not to use ActiveDocument.Delete(ElementID) becouse can not find the ID for loaded family.

 

Thank you for advance.

0 Likes
Reply
Accepted solutions (1)
2,398 Views
1 Reply
Reply (1)

Anonymous
Not applicable
Accepted solution

The way you can find the element id of the family is by filtering for families and then finding the desired family by name or some other characteristic:

 

void DeleteFamilyTest() {
            Family famToDelete = null;
            FilteredElementCollector fec = new FilteredElementCollector(uidoc.Document);
            fec.OfClass(typeof(Family));
            foreach (Element e in fec.ToElements()) {
                Family f = e as Family;
                if (null != f && f.Name.Equals("SomeFamilyName")) {
                    famToDelete = f;
                }
            }
            if (null != famToDelete) {
                uidoc.Document.Delete(famToDelete.Id);
            }
        }

 Hope this helps!