Revit二次开发 - 算量模块 - 构件预览

下图为一知名算量软件的构件预览的效果,我们自己开发算量软件应该绕不过它,不管是开发还是测试,该功能提供了直观查看和校核结果的途径,话不多说,看实现。

它的参考文档可以查看SDK的中AnalysisVisualizationFramework文件夹下的内容;

也可以直接百度搜Revit二次开发 AVF,能找到和下面相似的代码;

我感觉用AVF能直接解决显示构件的效率问题;

目前未考虑曲面,仅做参考。

接口中参数value可以给1

    static class AVFSolidUtils
    {
        public static void PaintFace(Document doc, Face face, double value, bool bClear = true)
        {
            var sfm = InitAnalysisDisplayStyle(doc.ActiveView);

            if (bClear) sfm.Clear();

            int schemaId = -1;

            var regList = sfm.GetRegisteredResults();
            if (regList.Count == 0)
            {
                var resultSchema1 = new AnalysisResultSchema("visual_Paint", "Description");
                schemaId = sfm.RegisterResult(resultSchema1);
            }
            else schemaId = regList.First();

            //
            var valList = new List<ValueAtPoint>() { new ValueAtPoint(new List<double>() { value }) };
            //
            var vals = new FieldValues(valList);
            //
            var pnts = new FieldDomainPointsByUV(new List<UV>() { face.GetBoundingBox().Min });
            var idx = sfm.AddSpatialFieldPrimitive(face, Transform.Identity);
            sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, schemaId);
        }
        public static void PaintSolid(this Document doc, Solid soild, double value, bool bClear = true)
        {
            var bClearTmp = bClear;

            foreach (Face face in soild.Faces)
            {
                PaintFace(doc, face, value, bClearTmp);

                bClearTmp = false;
            }
        }
        public static void PaintSolid(this Document doc, Face face, double thickness, double value, bool bClear = true)
        {
            var solid = GeometryCreationUtilities.CreateExtrusionGeometry(face.GetEdgesAsCurveLoops(), (face as PlanarFace).FaceNormal, thickness);

            PaintSolid(doc, solid, value, bClear);
        }

        #region UTILS

        static void CreateAVFDisplayStyle(Document doc, View view)
        {
            var coloredSurfaceSettings = new AnalysisDisplayColoredSurfaceSettings();

            coloredSurfaceSettings.ShowContourLines = true;

            var color = new Color(0xae, 0xc1, 0xe9);
            var colorSettings = new AnalysisDisplayColorSettings()
            {
                MinColor = color,
                MaxColor = color,
            };

            var legendSettings = new AnalysisDisplayLegendSettings() { ShowLegend = false };

            var analysisDisplayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(
                doc,
                "Paint Solid",
                coloredSurfaceSettings,
                colorSettings,
                legendSettings);

            view.AnalysisDisplayStyleId = analysisDisplayStyle.Id;
        }
        static SpatialFieldManager InitAnalysisDisplayStyle(View view)
        {
            if (view.AnalysisDisplayStyleId == ElementId.InvalidElementId)
                CreateAVFDisplayStyle(view.Document, view);

            var sfm = SpatialFieldManager.GetSpatialFieldManager(view);

            return sfm == null ? SpatialFieldManager.CreateSpatialFieldManager(view, 1) : sfm;
        }

        #endregion
    }

 

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页