通过编程的方式根据一组封闭的线绘制相同形状的箍筋


很多的时候我们希望给Revit的构件配筋, 通过编程的方式可以将你用手工绘制的模型线转化成箍筋。非常方便直观。

我们调用Rebar.CreateFromCurves() 函数来创建箍筋。

函数定义如下:

public static Rebar CreateFromCurves(
Document doc,
RebarStyle style,
RebarBarType barType,
RebarHookType startHook,
RebarHookType endHook,
Element host,
XYZ norm,
IList<Curve> curves,
RebarHookOrientation startHookOrient,
RebarHookOrientation endHookOrient,
bool useExistingShapeIfPossible,
bool createNewShape
)


创建箍筋需要注意的几个输入参数的理解:

第二个参数( RebarStyle style,)是 选择钢筋类型, 对于箍筋需要设置为: RebarStyle.StirupTie.  如果对于直线钢筋或纵筋设置为RebarStyle.Standard

第七个参数( XYZ norm) 是箍筋坐在平面的法向量方向。


请看下面的代码。


[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    public class Command1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            RebarBarType barType = null;
            RebarHookType hookType = null;

            Document doc = commandData.Application.ActiveUIDocument.Document;
            Transaction transaction = new Transaction(doc, "CreateRebar Tool");
            try
            {
                transaction.Start();

                IList<Curve> curves1 = new List<Curve>();
                ElementSet eleset = commandData.Application.ActiveUIDocument.Selection.Elements;
                //需要确保这些选择的线是首尾相连的。
                foreach (Element e in eleset)
                {
                    if (e is ModelLine)
                    {
                        Line l = (e as ModelLine).GeometryCurve as Line;
                        Line line = doc.Application.Create.NewLineBound(l.get_EndPoint(0), l.get_EndPoint(1));
                        curves1.Add(line);
                    }
                }

                foreach (RebarBarType bt in doc.RebarBarTypes)
                {
                  barType = bt;
                  break;
                }
                foreach (RebarHookType ht in doc.RebarHookTypes)
                {
                  hookType = ht;
                }

                {
             
   
                Reference hasPickOne = commandData.Application.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
                FamilyInstance hostFi = doc.get_Element(hasPickOne.ElementId) as FamilyInstance;

                Rebar rebar = CreateRebar1(commandData.Application.ActiveUIDocument, curves1, hostFi, barType, hookType);
          
                }

            }
            catch (Exception ex)
            {
                message += ex.Message;
                return Autodesk.Revit.UI.Result.Failed ;
            }
            finally
            {
                transaction.Commit();
            }


            return  Result.Succeeded ;
        }

        Rebar CreateRebar1(
            Autodesk.Revit.UI.UIDocument uidoc,
            IList<Curve> curves,
            FamilyInstance column,
            RebarBarType barType,
            RebarHookType hookType)
        {
             
            LocationPoint location = column.Location as LocationPoint;
            XYZ origin = location.Point;

            Rebar rebar = Rebar.CreateFromCurves(uidoc.Document, Autodesk.Revit.DB.Structure.RebarStyle.StirrupTie, barType, hookType, hookType,
                                column, new XYZ(0,0,1), curves, RebarHookOrientation.Left, RebarHookOrientation.Left, true, true);

            return rebar;
        }
    }

转载请复制以下信息:
原文链接: http://blog.csdn.net/joexiongjin/article/details/8950238
作者:  叶雄进 , Autodesk ADN

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值