Revit开发之载入族的创建小技巧


在Revit中创建载入族的实例,要用到NewFamilyInstance 这个方法,

但是这个 这个方法有很多的重载,有时候很难找到正确的那个重载.

如果是我们自己建的族,我们还可以有一些选择方向,如果是别人

的族,那就比较麻烦了。

起始RevitAPI里虽然没有明确的方法可以让你一下找到正确的重载,

但是在Family里提供了参考:

Family.FamilyPlacementType

这返回的是一个枚举,他包含了以下类容:

OneLevelBasedThe family is placed referencing a single level.
OneLevelBasedHostedThe family is placed referencing a single level and host.
TwoLevelsBasedThe family is placed referencing two levels (e.g. a column).
ViewBasedThe family is view-specific (e.g. a detail annotation)
WorkPlaneBasedThe family is placed on a work plane or face.
CurveBasedThe family is based on a line and placed on a work plane.
CurveBasedDetailThe family is based on a line and place on a specific view (e.g. a detail component).
CurveDrivenStructuralThe family is a structural curve driven member (beam, brace, or slanted column)
AdaptiveThe family is an adaptive family.
InvalidThis signals an invalid value for the enum. 

我们可以参考这些信息,快速找到正确的方法。


注意:自适应族不能用NewFamilyInstance 这个创建


博主会经常更新一些技术文章,请大家多多关注,多多交流

更多技术交流,请加qq群480950299





  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
如果你想要在Revit创建窗体并执行命令,可以使用Revit API进行二次开发。下面是一个简单的示例代码,演示如何创建一个窗体,并在单击按钮时执行Revit命令。 ``` c# using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Events; using System; using System.Windows.Forms; namespace RevitAddin { [Transaction(TransactionMode.Manual)] public class CreateWindow : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // 创建窗体 MyForm myForm = new MyForm(); // 获取Revit应用程序对象 UIApplication uiApp = commandData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; Document doc = uiDoc.Document; // 窗体中的按钮单击事件 myForm.ButtonClick += (sender, e) => { // 执行Revit命令 uiDoc.PostCommand(e.CommandId); }; // 监听Revit文档关闭事件 uiApp.Idling += (sender, e) => { if (uiDoc.Document.Equals(doc) && myForm.Visible) { myForm.Close(); } }; // 显示窗体 myForm.ShowDialog(); return Result.Succeeded; } } public class MyForm : Form { public event EventHandler<ButtonClickEventArgs> ButtonClick; public MyForm() { this.Text = "My Form"; this.Width = 300; this.Height = 150; // 创建按钮 Button button = new Button(); button.Text = "Execute Command"; button.Click += (sender, e) => { // 触发按钮单击事件 ButtonClick?.Invoke(this, new ButtonClickEventArgs(new Autodesk.Revit.UI.PostableCommandId(Autodesk.Revit.UI.RevitCommandId.LookupPostableCommandId(Autodesk.Revit.UI.RevitCommandIdEnum.ID_VIEW_ZOOM_EXTENTS)))); }; // 添加按钮到窗体 this.Controls.Add(button); } } public class ButtonClickEventArgs : EventArgs { public Autodesk.Revit.UI.PostableCommandId CommandId { get; set; } public ButtonClickEventArgs(Autodesk.Revit.UI.PostableCommandId commandId) { CommandId = commandId; } } } ``` 在这个示例中,我们创建了一个名为“My Form”的窗体,其中包含一个名为“Execute Command”的按钮。当用户单击该按钮时,它将执行Revit命令“ID_VIEW_ZOOM_EXTENTS”。 我们使用Revit API中的PostCommand方法来执行Revit命令。我们还监听了Revit应用程序的Idling事件,以便在用户关闭Revit文档时关闭窗体。 请注意,此示例仅演示了如何创建窗体并执行Revit命令。在实际应用中,你可能需要更复杂的逻辑来实现你的需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值