下載app免費(fèi)領(lǐng)取會(huì)員
網(wǎng)友投稿
更多在Revit 里很多操作都會(huì)彈出警告和錯(cuò)誤提示,
比如墻的高度降低,墻頂部的窗出現(xiàn)在墻的外面
這個(gè)會(huì)彈一個(gè)錯(cuò)誤提示框,
比如在同一個(gè)位置創(chuàng)建兩面墻,
會(huì)彈出一個(gè)警告提示框
如果在自己寫(xiě)的程序里出現(xiàn)了這種彈窗,會(huì)影響到用戶(hù)體驗(yàn),
其實(shí)API里提供一些錯(cuò)誤和警告的處理,
下面提供一個(gè)例子解決上面的兩種情況,
關(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;
// 處理錯(cuò)誤
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("無(wú)連接高度");
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)載。
上一篇:二次開(kāi)發(fā)教程:Revit開(kāi)發(fā)創(chuàng)建部件和部件視圖
下一篇:二次開(kāi)發(fā)教程:Revit開(kāi)發(fā)之放棄重做操作
推薦專(zhuān)題