简体   繁体   中英

Revit API SizeTableManager.RemoveSizeTable() not working?

I'm trying to remove all Lookup Tables that start with a specific prefix inside all families.

The method "sizeTableManager.RemoveSizeTable(tableToRemove)" returns true as if it succeeded but when I go edit the families in the project and bring up the Lookup Tables list they are still there.

The transaction seems to be committing with no errors too, which is even more puzzling...

Any ideas as to what I'm doing wrong?

This is my code so far:

string existingPrefix = "ExistingPrefix_";
Document doc = this.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> elements = collector.OfClass(typeof(Family)).ToElements();

foreach (var element in elements)
{
    using (Transaction t = new Transaction(doc, "flush old lookup tables"))
    {
        t.Start();
        FamilySizeTableManager sizeTableManager = FamilySizeTableManager.GetFamilySizeTableManager(doc, element.Id);
        if(sizeTableManager != null)
        {
            foreach (var tableToRemove in sizeTableManager.GetAllSizeTableNames())
            {
                if(tableToRemove.StartsWith(existingPrefix))
                {       
                    bool result = sizeTableManager.RemoveSizeTable(tableToRemove);
                    if(result)
                    {
                        // TaskDialog.Show("Success", "Removed " + tableToRemove + " from " + element.Name);
                        var test = "test";
                    }
                    else
                    {
                        TaskDialog.Show("Warning", "Unable to remove " + tableToRemove + " from " + element.Name);
                    }           
                }
            }
        }
        var commitResult = t.Commit();
    }
}

Thanks in advance!

Well, turns out that the RemoveSizeTable() method was indeed working, but that I had to regenerate the document for the changes to take effect:

using (Transaction t = new Transaction(doc, "regenerate document"))
{
    t.Start();
    doc.Regenerate();
    t.Commit();
}

Discovered this after noticing that saving the document caused the changes to take effect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM