下載app免費領(lǐng)取會員
在Revit 里很多操作都會彈出警告和錯誤提示,
比如墻的高度降低,墻頂部的窗出現(xiàn)在墻的外面
這個會彈一個錯誤提示框,
比如在同一個位置創(chuàng)建兩面墻,
會彈出一個警告提示框
如果在自己寫的程序里出現(xiàn)了這種彈窗,會影響到用戶體驗,
其實API里提供一些錯誤和警告的處理,
下面提供一個例子解決上面的兩種情況,
關(guān)鍵代碼如下:
public class FailuresPreprocessor : IFailuresPreprocessor
{
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> listFma =failuresAccessor.GetFailureMessages();
if (listFma.Count == 0)
return FailureProcessingResult.Continue;
foreach (FailureMessageAccessor fma in listFma)
{
if (fma.GetSeverity() == FailureSeverity.Error)
{
if (fma.HasResolutions())
failuresAccessor.ResolveFailure(fma);
}
if (fma.GetSeverity() == FailureSeverity.Warning)
{
failuresAccessor.DeleteWarning(fma);
}
}
return FailureProcessingResult.ProceedWithCommit;
}
}
bool testError = true;
// 處理錯誤
if (testError)
{
Wall wall = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as Wall;
Transaction trans = new Transaction(doc, "test");
trans.Start();
FailureHandlingOptions fho = trans.GetFailureHandlingOptions();
fho.SetFailuresPreprocessor(new FailuresPreprocessor());
trans.SetFailureHandlingOptions(fho);
Parameter p = wall.LookupParameter("無連接高度");
double h = p.AsDouble();
p.Set(h / 2);
trans.Commit();
}
// 處理警告
else
{
FilteredElementCollector lvlFilter = new FilteredElementCollector(doc);
lvlFilter.OfClass(typeof(Level));
Level lvl = lvlFilter.First() as Level;
Transaction trans1 = new Transaction(doc, "wall");
FailureHandlingOptions fho1 = trans1.GetFailureHandlingOptions();
fho1.SetFailuresPreprocessor(new FailuresPreprocessor());
trans1.SetFailureHandlingOptions(fho1);
trans1.Start();
Line line = Line.CreateBound(new XYZ(), new XYZ(10, 0, 0));
Wall.Create(doc, line, lvl.Id, false);
Wall.Create(doc, line, lvl.Id, false);
trans1.Commit();
}
return Result.Succeeded;
本文版權(quán)歸腿腿教學(xué)網(wǎng)及原創(chuàng)作者所有,未經(jīng)授權(quán),謝絕轉(zhuǎn)載。
上一篇:二次開發(fā)教程:Revit開發(fā)創(chuàng)建部件和部件視圖
下一篇:二次開發(fā)教程:Revit開發(fā)之放棄重做操作
推薦專題