Create instance on a linked host

Create instance on a linked host

Anonymous
Not applicable
2,828 Views
10 Replies
Message 1 of 11

Create instance on a linked host

Anonymous
Not applicable

Hi ! My add-in is creating objects on Element Faces (like walls) and it works well on local objects. But it does not work on linked object via API (it works with UI and in the "host Object" parameter i can read the name of the linked file which contains walls).

 

For local host my code is : 

var instance = CachedDoc.Create.NewFamilyInstance(HostElement, ReCenter, new XYZ(0,0,0), ResRectangular);

 Any ideas ? Thank you !

0 Likes
Accepted solutions (1)
2,829 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

In a nutshell I want this result (obtained with UI) via API :


 

PS : If i'm giving the wall face as host, Revit crash due to Fatal Error.

0 Likes
Message 3 of 11

Charles.Piro
Advisor
Advisor

Hi,

 

for work with link, you must use two options :

 

First : Transformation between the documents :

 

Reference refwall = uiDoc.Selection.PickObject(ObjectType.LinkedElement, "Select linked Element");
RevitLinkInstance rvtLink = doc.GetElement(refwall.ElementId) as RevitLinkInstance;
Transform transfLinkStr = null;
Instance ins = rvtLink as Instance;
 if (ins != null)
   transfLinkStr = ins.GetTotalTransform();

The Second : It's a different method for insert an host element :

 

Wall _wall= elmntStruct as Wall;
                    Reference lnkrefface = HostObjectUtils.GetSideFaces(_wall, ShellLayerType.Exterior).First<Reference>();
                    Reference linkref = lnkrefface.CreateLinkReference(rvtLink);
                    famInst = doc.Create.NewFamilyInstance(linkref, coordins, refDir, famSym);

Work with link is not easy !

 

Smiley Wink

 



PIRO Charles
Developer

PIRO CIE
Linkedin


Message 4 of 11

Anonymous
Not applicable

Hi ! Thanks for the quick reply! 

Reference refwall = item.HostFace.Reference;

                RevitLinkInstance rvtLink = CachedDoc.GetElement(refwall.ElementId) as RevitLinkInstance;


                Reference linkextFaceref = refwall.CreateLinkReference(rvtLink);

The problem : linkextFaceref is always null. Even if refwall and rvtLink are not. 

 

0 Likes
Message 5 of 11

Charles.Piro
Advisor
Advisor

Hi,

 

 

It's not good. You use Id of a face for RevitlinkInstance but the RevitLinkInstance must be a document, not other.

 

Look my first code.

I choose a wall but RefWall.ElementId is the Id of the document.

 

Smiley Wink

 



PIRO Charles
Developer

PIRO CIE
Linkedin


Message 6 of 11

Anonymous
Not applicable

Is there an other way than selection to get refwall ? Using a Wall Element or a Face ?

0 Likes
Message 7 of 11

Charles.Piro
Advisor
Advisor
Accepted solution

Yes,

 

you can use this for find the RevitLinkInstance :

 

RevitLinkInstance _rvtlink = null;
FilteredElementCollector flt = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance));
foreach(Element elmnt in flt)
{
_rvtlink = elmnt as RevitLinkInstance;
if(rvtlink.Name.Contains(refwall.document.Title))
break;
}

Smiley Wink

 

PS: I read your various post and I think you want develope an application, for insert an object "reservation" in the intersections between strcuture and MEP objects. I have already developed a similar application. Look : SCREENCAST



PIRO Charles
Developer

PIRO CIE
Linkedin


Message 8 of 11

Anonymous
Not applicable

FilteredElementCollector linkedColl = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType();
RevitLinkInstance linkedInst = linkedColl.First() as RevitLinkInstance;

 

Reference docRef = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior).First();

Reference linkRef = docRef.CreateLinkReference(linkedInst);

 

Above linkRef can be used in activeView to place a family.

0 Likes
Message 9 of 11

mponcioG8WP4
Explorer
Explorer

Adding link to the `NewFamilyInstance` method overload:

 

https://apidocs.co/apps/revit/2024/be4b822c-829a-7e7b-8c03-a3a324bfb75b.htm

0 Likes
Message 10 of 11

jackmrdoctor
Contributor
Contributor

After reading you solution. I'm finally able to place new family by host face in revit link 
but this message was shown. let me know if you know how to fix it. i have try many orientation.

jackmrdoctor_0-1747989327064.png

 

0 Likes
Message 11 of 11

Charles.Piro
Advisor
Advisor

Hi @jackmrdoctor,

 

your problem stems from the from axis from rotation. I think the best way to understand the roration axis, is to represent it in Revit with a model line.

 

😉



PIRO Charles
Developer

PIRO CIE
Linkedin


0 Likes