Revit 2018二次开发 从一个几何实例得到它的几何数据

改编的Revit二次开发基础教程,适用Revit 2018,测试时自己载入公制常规模型,公制常规模型里要有模型线。

本代码在模型线位置建墙,以做程序测试效果。

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

namespace LearnTime2
{
    //必备写法
    [Transaction(TransactionMode.Manual)]
    [Journaling(JournalingMode.NoCommandData)]
    [Regeneration(RegenerationOption.Manual)]


    class _59_GetInstanceGeometryCurve : IExternalCommand
    {
        
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {


            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document doc = commandData.Application.ActiveUIDocument.Document;
            UIApplication uiApp = commandData.Application;
            Application app = uiApp.Application;

            FamilyInstance familyInstance = doc.GetElement(new ElementId(206090)) as FamilyInstance;
            GetGeometryOptions getGeometryOptions = new GetGeometryOptions();
            Options option = getGeometryOptions.GetGeometryOption(app);
            Autodesk.Revit.DB.GeometryElement geomElement = familyInstance.get_Geometry(option);

            foreach (GeometryObject geomObj in geomElement)
            {
                GeometryInstance geomInstance = geomObj as GeometryInstance;
                if (null != geomInstance)
                {
                    foreach (GeometryObject instObj in geomInstance.SymbolGeometry)
                    {
                        Curve curve = instObj as Curve;
                        if (null != curve)
                        {
                            // 把取到的线变换到实例的坐标系中
                            //TaskDialog.Show("Revit", curve.Length.ToString());
                            curve = curve.CreateTransformed(geomInstance.Transform);
                            Line line = curve as Line;
                            
                            Level level = new FilteredElementCollector(doc).
                            OfClass(typeof(Level)).FirstOrDefault(x => x.Name == "标高 1") as Level;
                            Transaction transaction = new Transaction(doc,"创建墙");
                            transaction.Start();
                            Wall wall = Wall.Create(doc, line, level.Id, false);
                            transaction.Commit();

                        }
                        else
                        {
                            TaskDialog.Show("Revit", "没有curve");
                        }
                    }
                }
                else
                {
                    TaskDialog.Show("Revit", "没有geomInstance");
                }
            }






            return Result.Succeeded;

        }
        

    }

    class GetGeometryOptions
    {
        public Options GetGeometryOption(Application app)
        {
            Autodesk.Revit.DB.Options option = app.Create.NewGeometryOptions();
            option.ComputeReferences = true;
            option.DetailLevel = ViewDetailLevel.Fine;
            return option;
        }
    }




}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值