如何编程读取和修改墙上的各分层信息

转载请复制以下信息:

原文链接: http://blog.csdn.net/joexiongjin/article/details/7775576
作者:  叶雄进 , Autodesk ADN


墙的分层信息存储在墙类型里面。在墙类型面板中,点击“结构”参数后面的按钮可以进入到分层编辑界面。

很多时候需要读取Revit墙的分层信息,或者修改墙的分层的厚度,材料等。可以通过编程的方法来实现这些。


WallType.GetCompoundStructure 可以返回CompoundStructure对象,CompoundStructure类提供了许多的函数用来读取和编辑墙的分层信息。详见RevitAPI.chm文档。

CompoundStructure.GetLayers()函数返回所有的分层信息。

CompoundStructure.SetLayers() 函数可以把编辑后的分层信息写入到CompoundStructure中。

最有调用WallType.SetCompundStructure 把编辑后的结果写入。


请看下面的例子。代码来自Revit SDK中的CompoundStructure 例子。


        public void CreateCSforWall(Wall wall)
        {
            // Get CompoundStructure
            CompoundStructure wallCS = wall.WallType.GetCompoundStructure();

            // Get material for CompoundStructureLayer
            Material masonry_Brick = GetMaterial("Masonry - Brick");
            Material concrete = GetMaterial("Concrete");

            // Create CompoundStructureLayers
            List<CompoundStructureLayer> csLayers = new List<CompoundStructureLayer>();
            CompoundStructureLayer finish1Layer = new CompoundStructureLayer(0.2, MaterialFunctionAssignment.Finish1, masonry_Brick.Id);
            CompoundStructureLayer substrateLayer = new CompoundStructureLayer(0.1, MaterialFunctionAssignment.Substrate, ElementId.InvalidElementId);
            CompoundStructureLayer structureLayer = new CompoundStructureLayer(0.5, MaterialFunctionAssignment.Structure, concrete.Id);
            CompoundStructureLayer membraneLayer = new CompoundStructureLayer(0, MaterialFunctionAssignment.Membrane, ElementId.InvalidElementId);
            CompoundStructureLayer finish2Layer = new CompoundStructureLayer(0.2, MaterialFunctionAssignment.Finish2, masonry_Brick.Id);
            csLayers.Add(finish1Layer);
            csLayers.Add(substrateLayer);
            csLayers.Add(structureLayer);
            csLayers.Add(membraneLayer);
            csLayers.Add(finish2Layer);

            // Set the created layers to CompoundStructureLayer
            wallCS.SetLayers(csLayers);

            // Set shell layers and wrapping.
            wallCS.SetNumberOfShellLayers(ShellLayerType.Interior, 2);
            wallCS.SetNumberOfShellLayers(ShellLayerType.Exterior, 1);
            wallCS.SetParticipatesInWrapping(0, false);

            // Points for adding wall sweep and reveal.
            UV sweepPoint = UV.Zero;
            UV revealPoint = UV.Zero;

            // split the region containing segment 0.
            int segId = wallCS.GetSegmentIds()[0];
            foreach (int regionId in wallCS.GetAdjacentRegions(segId))
            {
                // Get the end points of segment 0.
                UV endPoint1 = UV.Zero;
                UV endPoint2 = UV.Zero;
                wallCS.GetSegmentEndPoints(segId, regionId, out endPoint1, out endPoint2);

                // Split a new region in splited point and orientation.
                RectangularGridSegmentOrientation splitOrientation = (RectangularGridSegmentOrientation)(((int)(wallCS.GetSegmentOrientation(segId)) + 1) % 2);
                UV splitUV = (endPoint1 + endPoint2) / 2.0;
                int newRegionId = wallCS.SplitRegion(splitUV, splitOrientation);
                bool isValidRegionId = wallCS.IsValidRegionId(newRegionId);

                // Find the enclosing region and the two segments intersected by a line through the split point
                int segId1;
                int segId2;
                int findRegionId = wallCS.FindEnclosingRegionAndSegments(splitUV, splitOrientation, out segId1, out segId2);

                // Get the end points of finding segment 1 and compute the wall sweep point.
                UV eP1 = UV.Zero;
                UV eP2 = UV.Zero;
                wallCS.GetSegmentEndPoints(segId1, findRegionId, out eP1, out eP2);
                sweepPoint = (eP1 + eP2) / 4.0;

                // Get the end points of finding segment 2 and compute the wall reveal point.
                UV ep3 = UV.Zero;
                UV ep4 = UV.Zero;
                wallCS.GetSegmentEndPoints(segId2, findRegionId, out ep3, out ep4);
                revealPoint = (ep3 + ep4) / 2.0;
            }

            // Create a WallSweepInfo for wall sweep
            WallSweepInfo sweepInfo = new WallSweepInfo(true, WallSweepType.Sweep);
            PrepareWallSweepInfo(sweepInfo, sweepPoint.V);
            // Set sweep profile: Sill-Precast : 8" Wide
            sweepInfo.ProfileId = GetProfile("8\" Wide").Id;  
            sweepInfo.Id = 101;
            wallCS.AddWallSweep(sweepInfo);

            // Create a WallSweepInfo for wall reveal
            WallSweepInfo revealInfo = new WallSweepInfo(true, WallSweepType.Reveal);
            PrepareWallSweepInfo(revealInfo, revealPoint.U);
            revealInfo.Id = 102;
            wallCS.AddWallSweep(revealInfo);

            // Set the new wall CompoundStructure to the type of wall.
            wall.WallType.SetCompoundStructure(wallCS);
        }



你可能感兴趣的:(如何编程读取和修改墙上的各分层信息)