欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Revit二次开发之创建倾斜楼板(Create a slope floor / slab)

程序员文章站 2022-07-12 14:57:48
...

一、函数

链接: 官方文档地址.

/*使用给定的水平轮廓创建默认样式楼板。*/
public Floor NewSlab(
	CurveArray profile,//斜板水平投影轮廓
	Level level,//水平投影标高
	Line slopedArrow,//倾斜轴,即水平投影与斜边相交的边
	double slope,//倾斜角度
	bool isStructural//是否结构
)

二、图示

Revit二次开发之创建倾斜楼板(Create a slope floor / slab)

三、代码

 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
         try {
             UIDocument uiDoc = commandData.Application.ActiveUIDocument;
             Document doc = uiDoc.Document;
             Selection sel = uiDoc.Selection;
             Autodesk.Revit.Creation.Application acreation = commandData.Application.Application.Create;
             Autodesk.Revit.Creation.Document dcreation = doc.Create;

             Transaction ts = new Transaction(doc, "www");
             ts.Start();

             
             double h = 7;//斜板较高一端与斜板较低一端的高度差
             double l = 5;//斜板水平投影长度
             double w = 10;//斜板水平投影宽度

             double x0 = 0;
             double y0 = 0;
             double z0 = 1;

             XYZ p_s0 = new XYZ(x0, y0, z0);
             XYZ p_s1 = new XYZ(x0, y0 + w, z0);
             XYZ p_s2 = new XYZ(x0 + l, y0 + w, z0);
             XYZ p_s3 = new XYZ(x0 + l, y0, z0);
             
             Line l_s0 = Line.CreateBound(p_s0, p_s1);
             Line l_s1 = Line.CreateBound(p_s1, p_s2);
             Line l_s2 = Line.CreateBound(p_s2, p_s3);
             Line l_s3 = Line.CreateBound(p_s3, p_s0);

             CurveArray fProfile = new CurveArray();
             fProfile.Append(l_s0);
             fProfile.Append(l_s1);
             fProfile.Append(l_s2);
             fProfile.Append(l_s3);

             var levelCollector = new FilteredElementCollector(doc).OfClass(typeof(Level));
             var slablevel = levelCollector.FirstOrDefault(e => e.Name == "斜板标高") as Level;
             if (slablevel == null) {
                 slablevel = Level.Create(doc, z0);
                 slablevel.Name = "斜板标高";
             } else slablevel.Elevation = z0;


            
             Line slopeLine = l_s0;//斜板与其投影面相交的线
             double slope = Math.Atan(h / w);//斜板的角度
             var slopeSlab = dcreation.NewSlab(fProfile, slablevel, slopeLine, slope, true);
             ts.Commit();

             return Result.Succeeded;
         } catch (Exception ex) {
             var r = 0;
             return Result.Succeeded;

         }

}
相关标签: revit二次开发