在revit柱中添加钢筋

 

在柱中添加钢筋 


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.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;


namespace 在柱中添加钢筋
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document revitDoc = commandData.Application.ActiveUIDocument.Document;  //取得文档
            Application revitApp = commandData.Application.Application;             //取得应用程序
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;            //取得当前活动文档


            Selection sel = uiDoc.Selection;
            Reference ref1 = sel.PickObject(ObjectType.Element, "选择一根柱子");
            FamilyInstance column = revitDoc.GetElement(ref1) as FamilyInstance;
            if (column==null)
            {
                TaskDialog.Show("错误1", "没有选择柱子");
            }
            RebarBarType barType = revitDoc.GetElement(new ElementId(195080)) as RebarBarType;
            RebarHookType hookType = revitDoc.GetElement(new ElementId(195034)) as RebarHookType;


            using (Transaction transaction = new Transaction(revitDoc))
            {
                transaction.Start("在柱中创建一根钢筋");
                //在下面添加主要代码内容


                Rebar newRebar = CreateRebar(revitDoc, column, barType, hookType);
                //限制钢筋的范围可以用newRebar.ScaleToBox()来表示




                transaction.Commit();


            }
            return Result.Succeeded;
        }
        Rebar CreateRebar(Autodesk.Revit.DB.Document document, FamilyInstance column, RebarBarType barType, RebarHookType hookType)
        {
            // Define the rebar geometry information - Line rebar
            LocationPoint location = column.Location as LocationPoint;
            XYZ origin = location.Point;
            XYZ normal = new XYZ(1, 0, 0);
            // create rebar 9' long
            XYZ rebarLineEnd = new XYZ(origin.X, origin.Y, origin.Z + 9);
            Line rebarLine = Line.CreateBound(origin, rebarLineEnd);


            // Create the line rebar
            IList<Curve> curves = new List<Curve>();
            curves.Add(rebarLine);


            Rebar rebar = Rebar.CreateFromCurves(document, Autodesk.Revit.DB.Structure.RebarStyle.Standard, barType, hookType, hookType,
                                column, origin, curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, true);


            if (null != rebar)
            {
                // set specific layout for new rebar as fixed number, with 10 bars, distribution path length of 1.5'
                // with bars of the bar set on the same side of the rebar plane as indicated by normal
                // and both first and last bar in the set are shown
                rebar.SetLayoutAsFixedNumber(10, 1.5, true, true, true);
            }


            return rebar;
        }
    }
}
  • 10
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值