我正在尝试删除所有系列中所有以特定前缀开头的查找表。
[方法“ sizeTableManager.RemoveSizeTable(tableToRemove)”好像成功返回了true,但是当我去编辑项目中的族并调出Lookup 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();
}
}
提前感谢!
嗯,事实证明,RemoveSizeTable()方法确实有效,但是我必须重新生成文档才能使更改生效:
using (Transaction t = new Transaction(doc, "regenerate document"))
{
t.Start();
doc.Regenerate();
t.Commit();
}
在发现保存文档导致更改生效后发现。