Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Load & Create a Pit FamilyInstance/Component

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
sam.z
682 Views, 2 Replies

Load & Create a Pit FamilyInstance/Component

Hello

 

I am attempting to create a FamilyInstance of a Pit. My families name is called Drainage Pit.rfa. The family only contains 1 component/instance called Drainage Pit.

 

The code below attempts to create 1 Drainage Pit inside the current document/project. But I dont know what symbol (if any) I am supposed to specify for the Drainage Pit component/instance? How do I specify 'create a pit' using doc.Create.NewFamilyInstance()?

 

// Load the Drainage Pit component from the family Drainage Pit
if (!doc.LoadFamilySymbol(DRAINAGE_FAMILY_PATH, "Drainage Pit"))
{
    throw new Exception("Load Family failed: Unable to load " + DRAINAGE_FAMILY_PATH);
    return false;
}


XYZ location = new XYZ(x, y, 10.0);
FamilyInstance instance = doc.Create.NewFamilyInstance(location, /*What symbol should I use?*/, StructuralType.NonStructural);

 

2 REPLIES 2
Message 2 of 3
gopinath.taget
in reply to: sam.z

I would suggest, you use the overloaded version of LoadFamilySymbol that returns the symbol instance in one of its parameters:

 

public bool LoadFamilySymbol(
	string filename,
	string name,
	out FamilySymbol symbol
)

This is the easiest approach.

 

If for some reason you want to use the version of LoadFamilyInstance you are already using, you could try using the FilteredElementCollector something like this ( in VB .NET):

 

Private Function GetFamilySymbol(ByVal symbolname As String, _
ByVal commandData As Autodesk.Revit.UI.ExternalCommandData) _
As Autodesk.Revit.DB.FamilySymbol
Dim component As Autodesk.Revit.DB.FamilySymbol = Nothing
Dim collector As New Autodesk.Revit.DB.FilteredElementCollector(commandData.Application.ActiveUIDocument.Document)
Dim collection As ICollection(Of Autodesk.Revit.DB.Element) = collector.OfClass(GetType(Autodesk.Revit.DB.FamilySymbol)).ToElements()
For Each e As Autodesk.Revit.DB.Element In collection
component = TryCast(e, Autodesk.Revit.DB.FamilySymbol)
If component IsNot Nothing Then
If component.Name = symbolname Then
Return component
End If
End If
Next
Return Nothing
End Function

 

I stole this piece of code from placeplant.vb I found in Jeremy's blog post: http://thebuildingcoder.typepad.com/blog/2010/11/place-site-component.html

 

Hope this helps.

 

Best Regards

Gopinath

 

Message 3 of 3
sam.z
in reply to: sam.z

Thanks for the reply. The function you specified is what I needed just need to place the last param in (the symbol). Always very helpful 😄

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community