获得与墙体垂直的平面——用于查看构造详图

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.Attributes;


namespace WorkingDymo
{
    [Transaction(TransactionMode.Manual)]
    class 拾取墙体创建垂直剖面 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document doc = uiDoc.Document;
         

            Reference reference = uiDoc.Selection.PickObject(ObjectType.Element);
            Wall wall = doc.GetElement(reference) as Wall;
            BoundingBoxXYZ boundingBox=  GetSectionViewPerpendiculatToWall(wall);

            //获取默认三维视图类型
            ElementTypeGroup typeGroup = ElementTypeGroup.ViewTypeSection;
            ElementId vid = doc.GetDefaultElementTypeId(typeGroup);

            //新建并启动事务
            Transaction transaction = new Transaction(doc, "创建平面视图");
            transaction.Start();
            //创建轴测图
            ViewSection view = ViewSection.CreateSection(doc, vid, boundingBox);
            transaction.Commit();
            //将当前视图跳转到该平面
            uiDoc.ActiveView = view;
            return Result.Succeeded;
        }


        /// <summary>
        /// Return a section box for a view perpendicular 
        /// to the given wall location line.
        /// </summary>
        BoundingBoxXYZ GetSectionViewPerpendiculatToWall(
          Wall wall)
        {
            LocationCurve lc = wall.Location
              as LocationCurve;

            // Using 0.5 and "true" to specify that the 
            // parameter is normalized places the transform
            // origin at the center of the location curve

            Transform curveTransform = lc.Curve
              .ComputeDerivatives(0.5, true);

            // The transform contains the location curve
            // mid-point and tangent, and we can obtain
            // its normal in the XY plane:

            XYZ origin = curveTransform.Origin;
            XYZ viewdir = curveTransform.BasisX.Normalize();
            XYZ up = XYZ.BasisZ;
            XYZ right = up.CrossProduct(viewdir);

            // Set up view transform, assuming wall's "up" 
            // is vertical. For a non-vertical situation 
            // such as section through a sloped floor, the 
            // surface normal would be needed

            Transform transform = Transform.Identity;
            transform.Origin = origin;
            transform.BasisX = right;
            transform.BasisY = up;
            transform.BasisZ = viewdir;

            BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();
            sectionBox.Transform = transform;

            // Min & Max X values define the section
            // line length on each side of the wall.
            // Max Y is the height of the section box.
            // Max Z (5) is the far clip offset.

            double d = wall.WallType.Width;
            BoundingBoxXYZ bb = wall.get_BoundingBox(null);
            double minZ = bb.Min.Z;
            double maxZ = bb.Max.Z;
            double h = maxZ - minZ;

            sectionBox.Min = new XYZ(-2 * d, -1, 0);
            sectionBox.Max = new XYZ(2 * d, h + 1, 5);

            return sectionBox;
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值