Revit SDK 介绍:AttachedDetailGroup

前言

这个例子介绍如何创建带附着的详图组(AttachedDetailGroup)的组(Group),然后单独控制 AttachedDetailGroup 的显示和隐藏。例子在 SDK: Revit 2020 SDK\Samples\AttachedDetailGroup

内容

下面分两个部分来介绍这个例子:

  1. 生成 Ribbon 菜单,有两个按钮,一个负责显示附着的详图组,一个负责隐藏附着的详图组;
  2. 实现两个命令,一个负责显示附着的详图组,一个负责隐藏附着的详图组。

菜单

结果如下:
Revit SDK 介绍:AttachedDetailGroup_第1张图片
例子里面是通过实现一个 IExternalApplication 来让菜单出现在这里。如果想要使用 IExternalApplication,必须加入 addin 文件到对应目录,默认为 C:\ProgramData\Autodesk\Revit\Addins\2020


<RevitAddIns>
  <AddIn Type="Application">
    <Name>AttachedDetailGroupName>
    <Assembly>AttachedDetailGroup.dllAssembly>
    <ClientId>91ef7f06-53b0-488c-a5bb-e005abfb542eClientId>
    <FullClassName>Revit.SDK.Samples.AttachedDetailGroup.CS.ApplicationFullClassName>
	<VendorId>ADSKVendorId>
	<VendorDescription>Autodesk, www.autodesk.comVendorDescription>
  AddIn>
RevitAddIns>

重写IExternalApplication::OnStartup,调用CreateAttachedDetailGroupPanel来创建菜单:

public Result OnStartup(UIControlledApplication application)
{
   CreateAttachedDetailGroupPanel(application);
   return Result.Succeeded;
}

CreateAttachedDetailGroupPanel 里面注意,typeof(Revit.SDK.Samples.AttachedDetailGroup.CS.AttachedDetailGroupShowAllCommand).FullName,这个将对应的命令绑定进来:

private void CreateAttachedDetailGroupPanel(UIControlledApplication application)
{
   // 创建 ribbon panel,用于放置各个菜单。
   RibbonPanel rp = application.CreateRibbonPanel("Attached Detail Group");

   // 创建显示附着的详图组的命令。
   PushButtonData pbdShowAllDetailGroups = new PushButtonData("ShowAttachedDetailGroups", "Show Attached\nDetail Groups",
                  addAssemblyPath,
                  typeof(Revit.SDK.Samples.AttachedDetailGroup.CS.AttachedDetailGroupShowAllCommand).FullName);

   pbdShowAllDetailGroups.LongDescription = "Show all of the selected element group's attached detail groups that are compatible with the current view.";

   PushButton pbShowAllDetailGroups = rp.AddItem(pbdShowAllDetailGroups) as PushButton;
   SetIconsForPushButton(pbShowAllDetailGroups, Revit.SDK.Samples.AttachedDetailGroup.CS.Properties.Resources.ShowAllDetailGroupsIcon);

   // 创建隐藏附着的详图组的命令。
   PushButtonData pbdHideAllDetailGroups = new PushButtonData("HideAttachedDetailGroups", "Hide Attached\nDetail Groups",
                  addAssemblyPath,
                  typeof(Revit.SDK.Samples.AttachedDetailGroup.CS.AttachedDetailGroupHideAllCommand).FullName);

   pbdHideAllDetailGroups.LongDescription = "Hide all of the selected element group's attached detail groups that are compatible with the current view.";

   PushButton pbHideAllDetailGroups = rp.AddItem(pbdHideAllDetailGroups) as PushButton;
         SetIconsForPushButton(pbHideAllDetailGroups, Revit.SDK.Samples.AttachedDetailGroup.CS.Properties.Resources.HideAllDetailGroupsIcon);
      }

实现命令

两个命令分别为 AttachedDetailGroupShowAllCommandAttachedDetailGroupHideAllCommand,最终调用的逻辑都是在 GroupHelper 里面:

public void ShowAllAttachedDetailGroups(Group modelGroup, Document doc, View view)
{
   using (Transaction transaction = new Transaction(doc, "ShowAllAttachedDetailGroups"))
   {
      transaction.Start("Show All Attached Detail Groups");
      modelGroup.ShowAllAttachedDetailGroups(view);
      transaction.Commit();
   }
}

public void HideAllAttachedDetailGroups(Group modelGroup, Document doc, View view)
{
   using (Transaction transaction = new Transaction(doc, "HideAllAttachedDetailGroups"))
   {
      transaction.Start("Hide All Attached Detail Groups");
      modelGroup.HideAllAttachedDetailGroups(view);
      transaction.Commit();
   }
}

从 Revit 界面可以看出 AttachedDetailGroups 和它的 Group 有个从属关系:
Revit SDK 介绍:AttachedDetailGroup_第2张图片

你可能感兴趣的:(Revit,SDK,介绍,C#)