- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All -
I'm trying to create a new (hosted) family instance by having a user pick a point in the in the project.
I start with picking a point, which is straightforward.
uidoc.Selection.PickObject(ObjectType.PointOnElement)
Then, retrieve the face in the linked element's geometry by:
Element element = doc.GetElement(pickedRef.ElementId);
RevitLinkInstance linkInstance = element as RevitLinkInstance;
Document linkedDoc = linkInstance.GetLinkDocument();
ElementId linkedElementId = pickedRef.LinkedElementId;
Element linkedElement = linkedDoc.GetElement(linkedElementId);
GeometryObject geomObj = linkedElement.GetGeometryObjectFromReference(pickedRef.CreateReferenceInLink());
Face face;
if (!(geomObj is Face f)) return Result.Cancelled;
face = geomObj as Face;
Options options = new Options();
options.ComputeReferences = true;
GeometryElement geomElem = linkedElement.get_Geometry(options);
foreach (GeometryObject go in geomElem)
{
if (go is Solid s)
{
foreach (Face fa in s.Faces)
{
if (fa == face)
{
face = fa;
}
}
}
}
FamilyInstance newInstance = doc.Create(face,
pickedRef.GlobalPoint,
XYZ.BasisZ,
familySymbol);
This is a bit convoluted for sure, but I don't know how else to get a Face that has references enabled as demanded by Create.NewFamilyInstance(Face, XYZ, XYZ, FamilySymbol) method. This is also the method that I'm trying to use to create the family instance. However, this gives the following error:
It appears that I've reached a dead end. But other methods I've tried including NewFamilyInstance(Reference, XYZ, XYZ, FamilySymbol) also don't work... I'm I using the wrong methods?
Any ideas on how to create a hosted element onto a linked element's face?
Thank you all in advance. 🙂
Solved! Go to Solution.