我不确定创建这样的新 ElementId 是否可行,而且我不确定您是否可以跨项目预测 ElementId?最好的方法是先进行过滤以搜索您正在寻找的家庭符号,然后使用该结果查找实例。
查看 SDK 中的 .chm 文件,这是其中的一个示例:
// Creates a FamilyInstance filter for elements that are family instances of the given family symbol in the document
// Find all family symbols whose name is "W10X49"
FilteredElementCollector collector = new FilteredElementCollector(document);
collector = collector.OfClass(typeof(FamilySymbol));
// Get Element Id for family symbol which will be used to find family instances
var query = from element in collector where element.Name == "W10X49" select element;
List<Element> famSyms = query.ToList<Element>();
ElementId symbolId = famSyms[0].Id;
// Create a FamilyInstance filter with the FamilySymbol Id
FamilyInstanceFilter filter = new FamilyInstanceFilter(document, symbolId);
// Apply the filter to the elements in the active document
collector = new FilteredElementCollector(document);
ICollection<Element> familyInstances = collector.WherePasses(filter).ToElements();