完善主体资料,免费赠送VIP会员!
* 主体类型
* 企业名称
* 信用代码
* 所在行业
* 企业规模
* 所在职位
* 姓名
* 所在行业
* 学历
* 工作性质
请先选择行业
您还可以选择以下福利:
行业福利,领完即止!

下载app免费领取会员

NULL

5cdd2dc095060.jpg

二次开发教程:Revit开发之警告和错误处理

发布于:2019-08-26 16:40:58

网友投稿

更多

在Revit 里很多操作都会弹出警告和错误提示,


比如墙的高度降低,墙顶部的窗出现在墙的外面


这个会弹一个错误提示框,


比如在同一个位置创建两面墙,


会弹出一个警告提示框




如果在自己写的程序里出现了这种弹窗,会影响到用户体验,




其实API里提供一些错误和警告的处理,


下面提供一个例子解决上面的两种情况,


关键代码如下:



    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;

本文版权归腿腿教学网及原创作者所有,未经授权,谢绝转载。

未标题-1.jpg

上一篇:二次开发教程:Revit开发创建部件和部件视图

下一篇:二次开发教程:Revit开发之放弃重做操作

60acb4e0ef112.png