简体   繁体   中英

Autodesk Revit Architecture 2014 .NET API C# find host for FamilyInstance in link

The host property of a familyInstance returns a RevitLinkInstance when the host is placed within a linked document. I there a way to get the real Element (or its ID) instead of the RevitLinkInstance?

I was hoping that the stableREpresentation could give me more information, but unfortunatly, it doesn't.

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

this would give "ac669fa6-4686-4f47-b1d0-5d7de6a40550-000a6a4a:0:RVTLINK:234297:0:218" where 234297 is the ID of the referenced element, in this case, still the RevitLinkInstance.

Have you tried this?

ElementId hostFaceReferenceId = instance.HostFace.LinkedElementId;

You could then try getting the Element via the linkedDocument.

Document LinkedDoc = RevitLinkInstance01.GetLinkDocument();

Element linkedEl = LinkedDoc.GetElement(hostFaceReferenceId);

Depending on the host you may have to go about it a few ways. For example, with a wall you could try the following (this is using LINQ by the way):

// 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);

Ultimately, according to the docs anyway, you're supposed to utilize the CreateReferenceInLink method to get your item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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