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);
Solved! Go to Solution.
Solved by gopinath.taget. Go to Solution.
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
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 😄