• Revit 二次开发 族的练习


    学习地址:https://www.bilibili.com/video/BV1mf4y1S72o?p=18

    实例练习一(创建一个柱的族)

    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.Attributes;
    using Autodesk.Revit.ApplicationServices;
    
    namespace FamilyAPI
    {
        [TransactionAttribute(TransactionMode.Manual)]
        public class FamilyAPI : IExternalCommand
        {
            public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                //族样板位置
                string rftPath = @"C:ProgramDataAutodeskRVT 2018Family TemplatesChinese公制柱.rft";
                UIApplication uiapp = commandData.Application;
                Application app = uiapp.Application;
                UIDocument uidoc = commandData.Application.ActiveUIDocument;
                Document doc = uidoc.Document;
                //创建族文件
                Document faDoc = app.NewFamilyDocument(rftPath);
                //开启事务
                Transaction trans = new Transaction(faDoc,"创建族");
                trans.Start();
                //创建FamilyManager
                FamilyManager manager = faDoc.FamilyManager;
                //添加材质参数
                FamilyParameter mfp = manager.AddParameter("材质",BuiltInParameterGroup.PG_MATERIALS,ParameterType.Material,false);
                //创建拉伸
                CurveArrArray array = GetCurves();
                SketchPlane skplane = GetSketchPlane(faDoc);
                //创建Extrusion
                Extrusion extrusion = faDoc.FamilyCreate.NewExtrusion(true, array, skplane, 4000 / 304.8);
                faDoc.Regenerate();
                //创建约束
                Reference topFaceRef = null;
                //创建Options
                Options opt = new Options();
                opt.ComputeReferences = true;
                opt.DetailLevel = ViewDetailLevel.Fine;
                GeometryElement gelm = extrusion.get_Geometry(opt);
                foreach (GeometryObject gobj in gelm)
                {
                    if (gobj is Solid)
                    {
                        Solid s = gobj as Solid;
                        foreach (Face face in s.Faces) //找面
                        {
                            if (face.ComputeNormal(new UV()).IsAlmostEqualTo(new XYZ(0,0,1)))
                            {
                                topFaceRef = face.Reference;
                            }
                        }
                    }
                }
                //创建View
                View v = GetView(faDoc);
                //创建Reference
                Reference r = GetTopLevel(faDoc);
                //创建
                Dimension d = faDoc.FamilyCreate.NewAlignment(v, r, topFaceRef);
                d.IsLocked = true;
                faDoc.Regenerate();
                //设置材质参数
                Parameter p = extrusion.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM);
                manager.AssociateElementParameterToFamilyParameter(p, mfp);
                //提交事务
                trans.Commit();
                Family fa = faDoc.LoadFamily(doc);
                faDoc.Close(false);
                //创建新事务
                trans = new Transaction(doc,"创建柱");
                trans.Start();
                fa.Name = "我的柱子";
                trans.Commit();//事务提交
                return Result.Succeeded;
            }
    
            private Reference GetTopLevel(Document faDoc)
            {
                //创建过滤器
                FilteredElementCollector temc = new FilteredElementCollector(faDoc);
                //过滤出标高
                temc.OfClass(typeof(Level));
                Level lvl = temc.First(m => m.Name == "高于参照标高") as Level;
                return new Reference(lvl);
            }
    
            private View GetView(Document faDoc)
            {
                FilteredElementCollector viewFilter = new FilteredElementCollector(faDoc);
                viewFilter.OfClass(typeof(View));
                View v = viewFilter.First(m => m.Name == "") as View;
                return v;
            }
    
            private SketchPlane GetSketchPlane(Document faDoc)
            {
                FilteredElementCollector temc = new FilteredElementCollector(faDoc);
                //过滤
                temc.OfClass(typeof(SketchPlane));
                SketchPlane sketchPlane = temc.First(m=>m.Name== "低于参照标高") as SketchPlane;
                return sketchPlane;
            }
    
            private CurveArrArray GetCurves()
            {
                double len = 300 / 304.8;
                //创建坐标
                XYZ p1 = new XYZ(-len,-len,0);
                XYZ p2 = new XYZ(len,-len,0);
                XYZ p3 = new XYZ(len,len,0);
                XYZ p4 = new XYZ(-len,len,0);
                //创建线
                Line l1 = Line.CreateBound(p1, p2);
                Line l2 = Line.CreateBound(p2, p3);
                Line l3 = Line.CreateBound(p3, p4);
                Line l4 = Line.CreateBound(p4, p1);
                CurveArrArray ary = new CurveArrArray();
                CurveArray arry = new CurveArray();
                arry.Append(l1);
                arry.Append(l2);
                arry.Append(l3);
                arry.Append(l4);
                ary.Append(arry);
                return ary;
            }
        }
    }
  • 相关阅读:
    2018 Android面试经历总结(京东、高德、爱奇艺、美团、摩拜等) csdn_aiyang的博客 CSDN博客
    @QQ音乐Android端120万行代码,编译耗时是怎样优化的_chuhe1989的博客CSDN博客
    @Android deeplink和AppLink原理 mingfeng002 博客园
    @Android冷启动优化解析_chuhe1989的博客CSDN博客
    (3条消息) Android 面试必备 http 与 https 协议_gdutxiaoxu的博客(微信公众号 stormjun94)CSDN博客_android 面试http
    @Android面试题(32)android编译过程和安装流程_pgg_cold的博客CSDN博客
    @Android面试题集2019版(包含答案整理)_A富得流油的咸鸭蛋的博客CSDN博客
    一道有意思的面试题目
    22
    @说说卡顿问题 简书
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/13288575.html
Copyright © 2020-2023  润新知