简体   繁体   English

使用PromptForFamilyInstancePlacement的Revit API放置详细信息组件

[英]Revit API placing detail component using PromptForFamilyInstancePlacement

I'm trying to place a detail component using PromptForFamilyInstancePlacement , but am having trouble properly defining the FamilySymbol . 我正在尝试使用PromptForFamilyInstancePlacement放置一个详细信息组件,但是在正确定义FamilySymbol时遇到了麻烦。

Examples that I have found show how to to this using a FilteredElementCollector , but I am trying to define the FamilySymbol by name. 我发现的示例显示了如何使用FilteredElementCollector做到这一点,但是我试图通过名称定义FamilySymbol

Try this code (requires System.Linq) and .NET4 试试此代码(需要System.Linq)和.NET4

FamilySymbol symbol = GetElements<FamilySymbol>(commandData.Application.ActiveUIDocument.Document)
                          .Where(item => item.Name == "NameYouWant")
                          .First();
commandData.Application.ActiveUIDocument.PromptForFamilyInstancePlacement(symbol);


    /// <summary>
    /// Get the collection of elements of the specified type.
    /// <para>The specified type must derive from Element, or you can use Element but you get everything :)</para>
    /// </summary>
    /// <typeparam name="T">The type of element to get</typeparam>
    /// <returns>The list of elements of the specified type</returns>
    public IEnumerable<T> GetElements<T>(Document document) where T : Element
    {
        FilteredElementCollector collector = new FilteredElementCollector(document);
        collector.OfClass(typeof(T));
        return collector.Cast<T>();
    }

Have you already loaded the Family document into the project that you are working in? 您是否已经将“家庭”文档加载到您正在处理的项目中? If not then you can load the family into the project using Document.LoadFamilySymbol or Document.LoadFamily . 如果不是,则可以使用Document.LoadFamilySymbolDocument.LoadFamily将族加载到项目中。 Otherwise, to find the family symbol that you are looking for, you can use something similar to the code below: 否则,要查找所需的家庭符号,可以使用类似于下面的代码:

UIApplication application = commandData.Application;
UIDocument uiDocument = application.ActiveUIDocument;
Document document = application.ActiveUIDocument.Document;

FilteredElementCollector familyCollector = new FilteredElementCollector(document);
familyCollector.OfClass(typeof(FamilySymbol));

FamilySymbol familySymbolToFind = null;

foreach (FamilySymbol familySymbol in familyCollector)
{
  //To search by FamilySymbol name
  if (familySymbol.Name == "[Name of FamilySymbol to find]")
    familySymbolToFind = familySymbol;
  //To search by Family name
  else if (familySymbol.Family.Name = "[Name of Family to find]")
    familySymbolToFind = familySymbol;
}

uiDocument.PromptForFamilyInstancePlacement(familySymbolToFind);

They both work, even in Revit 2017. (On the second solution, the else if line needs a == instead of an = .) 它们都可以使用,即使在Revit 2017中也是如此。(在第二种解决方案中,如果行需要使用==而不是= ,则else)。

In the second solution, I used this to make sure I had the right family name and family symbol name: 在第二个解决方案中,我使用它来确保我拥有正确的姓氏和家庭符号名称:

foreach (FamilySymbol familySymbol in familyCollector)
{
  if (familySymbol.Name == "Put your Family Name here" && familySymbol.Family.Name == "Put your Family Symbol Name here")
                        familySymbolToFind = familySymbol;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM