完善主體資料,免費(fèi)贈(zèng)送VIP會(huì)員!
    * 主體類型
    * 企業(yè)名稱
    * 信用代碼
    * 所在行業(yè)
    * 企業(yè)規(guī)模
    * 所在職位
    * 姓名
    * 所在行業(yè)
    * 學(xué)歷
    * 工作性質(zhì)
    請(qǐng)先選擇行業(yè)
    您還可以選擇以下福利:
    行業(yè)福利,領(lǐng)完即止!

    下載app免費(fèi)領(lǐng)取會(huì)員

    NULL

    ad.jpg

    二次開(kāi)發(fā)教程:Revit開(kāi)發(fā)通過(guò)API 創(chuàng)建族

    發(fā)布于:2019-08-23 17:20:00

    網(wǎng)友投稿

    更多

    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.Attributes;

    using Autodesk.Revit.ApplicationServices;



    namespace CreateFamily

    {

        [Transaction(TransactionMode.Manual)]

        public class Class1:IExternalCommand

        {

            public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)

            {

                string rftPath = @"C:\ProgramData\Autodesk\RVT 2016\Family Templates\Chinese\公制柱.rft";

                UIApplication uiapp = commandData.Application;

                Application app = uiapp.Application;

                UIDocument uidoc = commandData.Application.ActiveUIDocument;

                Document doc = uidoc.Document;



                //創(chuàng)建族文件

                Document faDoc = app.NewFamilyDocument(rftPath);


                Transaction trans = new Transaction(faDoc, "Create Family");

                trans.Start();

                FamilyManager manager = faDoc.FamilyManager;

                //添加材質(zhì)參數(shù)

                FamilyParameter mfp = manager.AddParameter("材質(zhì)", BuiltInParameterGroup.PG_MATERIALS, ParameterType.Material, false);


                //創(chuàng)建拉伸

                CurveArrArray arry = GetCurves();

                SketchPlane skplane = GetSketchPlane(faDoc);

                Extrusion extrusion = faDoc.FamilyCreate.NewExtrusion(true, arry, skplane, 4000 / 304.8);

                faDoc.Regenerate();


                //創(chuàng)建約束

                Reference topFaceRef = null;

                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 v = GetView(faDoc);

                Reference r =GetTopLevel(faDoc);

                Dimension d = faDoc.FamilyCreate.NewAlignment(v, r, topFaceRef);

                d.IsLocked = true;

                faDoc.Regenerate();


                //關(guān)聯(lián)材質(zhì)參數(shù)

                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, "CreateColumn");

                trans.Start();

                fa.Name = "我的柱";

                trans.Commit();

                return Result.Succeeded;

            }


            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;

            }


            private SketchPlane GetSketchPlane(Document doc)

            {

                FilteredElementCollector temc = new FilteredElementCollector(doc);

                temc.OfClass(typeof(SketchPlane));

                SketchPlane sketchPlane = temc.First(m => m.Name == "低于參照標(biāo)高") as SketchPlane;

                return sketchPlane;

            }


            private View GetView(Document doc)

            {

                FilteredElementCollector viewFilter = new FilteredElementCollector(doc);

                viewFilter.OfClass(typeof(View));

                View v = viewFilter.First(m => m.Name == "前") as View;

                return v;

            }


            private Reference GetTopLevel(Document doc)

            {

                FilteredElementCollector temc = new FilteredElementCollector(doc);

                temc.OfClass(typeof(Level));

                Level lvl = temc.First(m => m.Name == "高于參照標(biāo)高") as Level;

                return new Reference(lvl);

            }

        }

    }

    本文版權(quán)歸腿腿教學(xué)網(wǎng)及原創(chuàng)作者所有,未經(jīng)授權(quán),謝絕轉(zhuǎn)載。

    未標(biāo)題-1.jpg

    上一篇:二次開(kāi)發(fā)教程:Revit開(kāi)發(fā)樓梯創(chuàng)建

    下一篇:二次開(kāi)發(fā)教程:Revit開(kāi)發(fā)之標(biāo)注創(chuàng)建

    主站蜘蛛池模板: 日韩精品一区二区三区中文| 国产精品无码一区二区三级| 日韩一区二区三区在线观看 | 国产亚洲福利精品一区二区| 国产微拍精品一区二区| 欧亚精品一区三区免费| 无码午夜人妻一区二区不卡视频| 免费人人潮人人爽一区二区| 红杏亚洲影院一区二区三区| 精品国产一区二区三区无码| 国产小仙女视频一区二区三区| 国产精品免费大片一区二区| 午夜福利一区二区三区在线观看| 亚洲av永久无码一区二区三区| 午夜视频久久久久一区| 久久婷婷久久一区二区三区| 亚洲av乱码一区二区三区按摩 | 亚洲AV乱码一区二区三区林ゆな | 一区二区网站在线观看| 91麻豆精品国产自产在线观看一区 | 日本v片免费一区二区三区 | 国产精品亚洲一区二区无码| 中文字幕一区二区在线播放| 91一区二区三区四区五区| 精品一区二区三区水蜜桃| 无码精品一区二区三区免费视频| 国内精品一区二区三区最新| 久久se精品一区二区国产| 国产伦精品一区二区| 久久久精品人妻一区二区三区蜜桃 | 丝袜无码一区二区三区| 国精产品999一区二区三区有限 | 久久精品一区二区免费看| 日本精品啪啪一区二区三区| 91在线看片一区国产| 不卡无码人妻一区三区音频| 日韩在线一区视频| 无码av免费一区二区三区| 无码日韩人妻AV一区二区三区| 亚洲av日韩综合一区久热| 男女久久久国产一区二区三区|