【发布时间】:2019-06-21 02:22:33
【问题描述】:
我想将墙 ID 放入墙的属性中。
代码会构建,但不会将墙 id 放入所有墙的参数 wall id。
我试过没有交易和有交易。我的印象是必须使用它们来执行,但我没有得到正确的结果(或任何结果)。
public void InsertWallID() {
Document doc = this.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> WallEls = collector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Walls).ToElements();
using (Transaction trans = new Transaction(doc, "Change wall parameters values"))
{
trans.Start();
int WallIDValue;
foreach(Element WallEl in WallEls)
{
ElementId WallId = WallEl.Id;
WallIDValue = WallId.IntegerValue;
if(WallEl.LookupParameter("WallID")==null)
{
Parameter wallparam = WallEl.LookupParameter("WallID") as Parameter;
wallparam.Set(WallIDValue);
}
}
trans.Commit();
}
}
}
}
预期结果: 每个实例的参数中都有自己的 id。这将让我安排墙壁和他们的墙壁 ID
实际结果: 参数 WallID 没有更改,因为它仍然为空。
【问题讨论】: