Duct hanger - place family instance Revit API

Duct hanger - place family instance Revit API

Or.levi
Contributor Contributor
1,350 Views
4 Replies
Message 1 of 5

Duct hanger - place family instance Revit API

Or.levi
Contributor
Contributor

hey,

i'm trying to place a family using the API (c#).

When using the NewFamiltInstace overloaded method that takes (location, symbol,host, level, structural) - i'm expecting to get the instance of the hanger family in the level i have inserted, and in the elevation of the host ( the duct).

instead - i get the duct hanger in the ground floor no matter what i'm doing, can any one understand why, and what sholud i do to get it in the desired level? 

 the code from my transaction: 

 

using (Transaction trans = new Transaction(doc, "Place Family"))
{
trans.Start();


int indx = 0;
foreach (XYZ hanger_xyz in hangerCoordinates)
{

if (!hangerSymbol.IsActive)
{
hangerSymbol.Activate();
}

doc.Create.NewFamilyInstance(hanger_xyz, hangerSymbol,duct,level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

}

trans.Commit();
}

Orlevi_0-1646494927344.png

 

 

0 Likes
Accepted solutions (1)
1,351 Views
4 Replies
Replies (4)
Message 2 of 5

caroline.gitonga
Autodesk
Autodesk

Hi @Or.levi ,

 

Thank you for raising this question.

I believe you need to get the level on which your host element resides first, in this case the level of the duct.

// get ducts's level for hanger creation
Level level = document.GetElement(duct.LevelId) as Level;

 

This is the level object you need to pass to the NewFamilyInstance overload.

 

You can refer to https://www.revitapidocs.com/2022/168d4c67-73dd-d7c8-4969-12846eeaddfa.htmfor more details.

Let me know if you get the solution, 

Thanks

 

Carol Gitonga, Developer Advocacy and Support, ADN Open
0 Likes
Message 3 of 5

Or.levi
Contributor
Contributor

hey @ caroline.gitonga
thank you for your response!
unfortunately it did not change the situation.
The duct hangers are still being placed only in the ground floor for some reason.
i also tried inserting name for the level by user input like so -

 

 

// get user input for desired level
string inputLevelName = Microsoft.VisualBasic.Interaction.InputBox("Please insert the EXACT name of the desired level", "Insert Level", "");
//Get Level(in order to create hanger element)
Level level = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Levels)
.WhereElementIsNotElementType()
.Cast<Level>()
.First(x => x.Name == inputLevelName);

 

 


[still did not work..] 

any idea why? 

thanks!

Orlevi_0-1646511890726.png

 

0 Likes
Message 4 of 5

Or.levi
Contributor
Contributor
Accepted solution

figured it out. 

After testing all of the 11 overloaded methods for newFamilyInstance and their required arguments, and snooping around with RevitLookUp, i  managed to get the right overloded method which is:

   FamilyInstance familyInstance = doc.Create.NewFamilyInstance(face, hanger_xyz, new XYZ(0, 1, 0), hangerSymbol);

face==> as a  Referemce object (extracted it from a face Face that i got from a GeoElement that i got from the desired level's floor)

hanger_xyz==>an XYZ location

new XYZ(0,1,0)==> a direction of the family as it is when it's attached to a cielling host ( got it from revitLookUp)

hangerSymbol ==> the familysymbol.

 

cheers!

0 Likes
Message 5 of 5

Chris-VC_Studio
Advocate
Advocate
Good day, Or.levi

I am a total noob when with C#, and I would like to write a transaction similar to yours except with flow arrows for pipe. I was wondering if you wouldn't mind sharing all your code from the duct selection to the transaction so I could adopt my coding to work pipe and my flow arrow families.