完善主體資料,免費贈送VIP會員!
* 主體類型
* 企業(yè)名稱
* 信用代碼
* 所在行業(yè)
* 企業(yè)規(guī)模
* 所在職位
* 姓名
* 所在行業(yè)
* 學(xué)歷
* 工作性質(zhì)
請先選擇行業(yè)
您還可以選擇以下福利:
行業(yè)福利,領(lǐng)完即止!

下載app免費領(lǐng)取會員

NULL

ad.jpg

二次開發(fā)教程:Revit開發(fā)之警告和錯誤處理

發(fā)布于:2019-08-26 16:40:58

網(wǎ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)載。

未標(biāo)題-1.jpg

上一篇:二次開發(fā)教程:Revit開發(fā)創(chuàng)建部件和部件視圖

下一篇:二次開發(fā)教程:Revit開發(fā)之放棄重做操作