revit二次开发(根据元素原点创建XYZ三个方向的模型线)

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

namespace 绘制位置线_点
{
    [Transaction(TransactionMode.Manual)]
    public class Class1 : IExternalCommand
    {
        
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;//获取活动文档
            Document doc = uidoc.Document;

            //选择元素
            Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "请选择族");
            Element elem = doc.GetElement(refer);

            //获取原点
            LocationPoint lc = elem.Location as LocationPoint;
            XYZ point = lc.Point;

            //创建模型线
            Transaction trans = new Transaction(doc);
            //CreateModelLine(doc);
            NewModelLineXYZ(doc, point);
            return Result.Succeeded;
        }
        private void CreateModelLine(Document RevitDoc)
        {
            using (Transaction transaction = new Transaction(RevitDoc))
            {
                transaction.Start("Create Model Line");
                Line geoLine = Line.CreateBound(XYZ.BasisY * 10, XYZ.BasisX * 10);
                SketchPlane modelSketch = SketchPlane.Create(RevitDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero));
                ModelCurve modelLine = RevitDoc.Create.NewModelCurve(geoLine, modelSketch);
                transaction.Commit();
            }
        }
        private void NewModelLineXYZ(Document RevitDoc, XYZ point)
        {
            XYZ startpoint1 = new XYZ(point.X, point.Y, point.Z);
            XYZ endpoint1 = new XYZ(point.X + 10, point.Y, point.Z);

            XYZ startpoint2= new XYZ(point.X, point.Y, point.Z);
            XYZ endpoint2 = new XYZ(point.X , point.Y+10, point.Z);

            XYZ startpoint3 = new XYZ(point.X, point.Y, point.Z);
            XYZ endpoint3= new XYZ(point.X , point.Y, point.Z+10);


            using (Transaction transaction = new Transaction(RevitDoc))
            {
                transaction.Start("Create Model Line");
                //创建sketchPlane
                SketchPlane modelSketch1 = SketchPlane.Create(RevitDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, point));
                SketchPlane modelSketch2 = SketchPlane.Create(RevitDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, point));
                SketchPlane modelSketch3 = SketchPlane.Create(RevitDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisX, point));
                //创建线
                Line Line1 = Line.CreateBound(startpoint1, endpoint1);
                Line Line2 = Line.CreateBound(startpoint2, endpoint2);
                Line Line3 = Line.CreateBound(startpoint3, endpoint3);

                //创建模型线
                RevitDoc.Create.NewModelCurve(Line1, modelSketch1);
                RevitDoc.Create.NewModelCurve(Line2, modelSketch2);
                RevitDoc.Create.NewModelCurve(Line3, modelSketch3);
                transaction.Commit();
            }

        }
    }
}
 

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值