SizeTableManager.RemoveSizeTable() not working?

SizeTableManager.RemoveSizeTable() not working?

vincent
Contributor Contributor
723 Views
2 Replies
Message 1 of 3

SizeTableManager.RemoveSizeTable() not working?

vincent
Contributor
Contributor

Hello,

 

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

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.

 

Any ideas as to what I'm doing wrong? 

 

This is my code so far:

 

// remove old tables
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!

 

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

vincent
Contributor
Contributor
Accepted solution

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.

0 Likes
Message 3 of 3

Remy_MAURCOT
Advisor
Advisor

Hi @vincent , it's possible for you to share your dynamo file ?


Rémy MAURCOT
BIM Manager

Mon C.V.
Profil LinkedIn
0 Likes