Autodesk Revit架构2014 . net API c#为FamilyInstance找到主机链接

本文关键字:FamilyInstance 主机 链接 架构 Revit 2014 net API Autodesk | 更新日期: 2023-09-27 18:17:29

familyInstance的host属性返回一个RevitLinkInstance当主机被放置在一个链接的文档中时。我有一个方法来获得真正的元素(或其ID),而不是RevitLinkInstance?

我希望稳定器能给我更多的信息,但不幸的是,它没有。

Reference hostFaceReference = instance.HostFace;
string stableRepresentation = hostFaceReference.ConvertToStableRepresentation(instance.Document);

这将给出"ac669fa6-4686-4f47-b1d0-5d7de6a40550-000a6a4a:0:RVTLINK:234297:0:218",其中234297是引用元素的ID,在这种情况下,仍然是RevitLinkInstance。

Autodesk Revit架构2014 . net API c#为FamilyInstance找到主机链接

你试过吗?

ElementId hostFaceReferenceId = instance.HostFace.LinkedElementId;

你可以尝试通过linkedDocument获取元素。

Document LinkedDoc = RevitLinkInstance01.GetLinkDocument();

Element linkedEl = LinkedDoc.GetElement(hostFaceReferenceId);

根据主机的不同,您可能需要使用几种方法。例如,对于墙壁,您可以尝试以下操作(顺便说一下,这是使用LINQ):

// filter the Host's document's items
FilteredElementCollector linkdocfec = new FilteredElementCollector(elem_inst.Host.Document);
// establish the host's type
linkdocfec.OfClass(elem_inst.Host.GetType());
// find the host in the list by comparing the UNIQUEIDS
Element hostwallinlinkedfile = (from posshost in linkdocfec
                                where posshost.UniqueId.ToString().Equals(elem_inst.Host.UniqueId.ToString())
                                select posshost).First();
// check the different faces of the host (wall in this case) and select the exterior one
Reference linkrefface = HostObjectUtils.GetSideFaces((hostwallinlinkedfile as HostObject), ShellLayerType.Exterior).First<Reference>();
// create a reference to the linked face in the the CURRENT document (not the linked document)
Reference linkref = linkrefface.CreateLinkReference(rvtlink_other);

最终,无论如何,根据文档,您应该使用CreateReferenceInLink方法来获取您的项目