Revit二次开发 通过boundingBox创建实体

用户选择任意元素,生成这个元素的包围盒实体。就这么简单。被curveLoop不封闭整到人傻掉

namespace SizeAdjustment

{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class WindowDoorOpening : IExternalCommand
    {

        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
            ref string message, ElementSet elements)
        {

            UIApplication uIApp = commandData.Application;
            Application application = uIApp.Application;
            UIDocument uIDoc = uIApp.ActiveUIDocument;
            Document document = uIDoc.Document;
            Selection selection = uIDoc.Selection;
            View view = uIDoc.ActiveView;
            //【】过滤墙体 用户选择
            IList<Element> faces = uIDoc.Selection.PickElementsByRectangle();


            Transaction trans = new Transaction(document, "LS");
            trans.Start();


            var solid  = solidBoundingBox(view, faces.First());
            var ds7 = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));
            ds7.GetGeneratingElementIds(solid);
            ds7.SetShape(new List<GeometryObject>() { solid });
            trans.Commit();


            return Result.Succeeded;
        }
        public static Solid solidBoundingBox(View view,Element inputSolid)
        {
            BoundingBoxXYZ bbox = inputSolid.get_BoundingBox(view);

            // corners in BBox coords
            XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z);
            XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z);
            XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z);
            XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z);
            //edges in BBox coords
            Line edge0 = Line.CreateBound(pt0, pt1);
            Line edge1 = Line.CreateBound(pt1, pt2);
            Line edge2 = Line.CreateBound(pt2, pt3);
            Line edge3 = Line.CreateBound(pt3, pt0);
            //create loop, still in BBox coords
            List<Curve> edges = new List<Curve>();
            edges.Add(edge0);
            edges.Add(edge1);
            edges.Add(edge2);
            edges.Add(edge3);
            Double height = bbox.Max.Z - bbox.Min.Z;
            CurveLoop baseLoop = CurveLoop.Create(edges);
            List<CurveLoop> loopList = new List<CurveLoop>();
            loopList.Add(baseLoop);
            Solid preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry(loopList, XYZ.BasisZ, height);

            Solid transformBox = SolidUtils.CreateTransformed(preTransformBox, bbox.Transform);

            return transformBox;

        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值