简体   繁体   English

新加载的Revit API系列中的GetFamilySymbolsId为null

[英]GetFamilySymbolsId null in newly loaded family Revit API

I'm curious the results of the code snip below. 我很好奇下面代码片段的结果。 I want to grab a family by name and insert the very first symbol found in that family. 我想按名称抓住一个家庭,并插入该家庭中发现的第一个符号。

This works fine for families with multiple symbols. 这对于带有多个符号的家庭来说效果很好。 However, for those with no specific type definitions, sometimes symId.Count() = 1 and other times, a null exception is returned. 但是,对于那些没有特定类型定义的对象,有时symId.Count() = 1等等,则返回null异常。 Why is this the case? 为什么会这样?

  Element el1 = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.Family)).FirstOrDefault(x => x.Name == familyName);

                Autodesk.Revit.DB.Family fam = el1 as Autodesk.Revit.DB.Family;

                ISet<ElementId> symIds = fam.GetFamilySymbolIds();

                foreach (ElementId elid in symIds)
                {
                    FamilySymbol symbol = doc.GetElement(elid) as FamilySymbol;
                    try
                    {
                        uidoc.PromptForFamilyInstancePlacement(symbol);
                    }
                    catch { }
                    break;
                }

Interesting follow up. 有趣的跟进。 When I go into the base family, add some types, delete fom project, and reload - I get the same error. 当我进入基本系列时,添加一些类型,删除fom项目,然后重新加载-我遇到相同的错误。

You say, 'sometimes a null exception is returned'. 您说,“有时会返回null异常”。

That is rather unspecific. 这是相当具体的。

I suggest you debug the code step by step and determine exactly which API call is throwing the exception, and exactly what the exception message says. 我建议您逐步调试代码,并确切确定哪个API调用引发了异常以及异常消息的内容。

That will probably clarify what is going on. 这可能会澄清正在发生的事情。

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

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