3 Revit Family API
3 Revit Family API
3 Revit Family API
Background
Family content creation itself is highly customizable feature even
without API
Understanding how it works in UI is a key to successful creation in API
There used to be two Revit API expertise communities
those who know UI and content creation well
those who are fluent in programming, but are not familiar with UI
Revit Architecture
Basic building components with simplistic interactions in the model
Free placement objects - casework, furniture, etc.
“2 point” placement objects – beams, detail components, etc.
Hosted objects: windows, doors, columns (“level to level”), ceiling or “wall
based” lighting fixtures
Revit Structure
Additional components with complex interactions with other objects
Framing - beams (“beams to beam”, “beam to column”), columns
Trusses - layout for girder trusses; Boundary Conditions
Span Direction Symbols; Reinforcement Symbols - area reinforcement
expands to find edges, path reinforcement
Revit MEP
Connectors allowing objects to resize based on what they are connected to
Process order:
1. Plan (Insertion Point, Parametric Origin)
2. Layout Reference Planes (The Bones)
3. Add Parameters
4. Add multiple host thickness types (for testing hosted families)
5. Add 2 or more types
6. Flex Types and Host (Testing Procedure)
7. Add a Single Level of Geometry
8. Repeat Steps 6 and 7 until you are satisfied with the results
9. Test in Project Environment (create testing project)
Steven Campbell, Revit Content Project Manager
FamilyManager class:
add/remove/rename types, add/remove parameters, set values and
formulas
Document methods specific to family context:
IsFamilyDocument – identifies whether the current document is a family document
OwnerFamily – returns the owning family of this family document
FamilyManager – returns a FamilyManager object to provide access to family
types and parameters
FamilyCreate – returns a FamilyItemCreate object to create new instances of
elements within a family document, analogous to the Create object in a project
EditFamily – edit a family loaded in a project document
Objective:
add line representation
add visibility control
Reference planes
Parameters Plan
Dimensions Reference planes
Types Parameters
Geometry Types
Alignments Geometry
Center (Left/Right)
Left Right
Back
Center (Front/Back)
Front
Reference Plane
Reference Plane :
OffsetV
Reference Plane :
OffsetH
Sub AddReferencePlane_VerticalOffset()
'' create a reference plan, using NewReferencePlane
Dim pt1 As New XYZ(-0.5, -2.0, 0.0) '' one end
Dim pt2 As New XYZ(-0.5, 2.0, 0.0) '' the other end
Dim vec As XYZ = XYZ.BasisZ '' perpendicular to the first line.
Dim view As View = _
Utils.FindElement(rvtDoc, GetType(ViewPlan), "Lower Ref. Level")
Sub AddReferencePlane_VerticalOffset()
'' create a reference plan, using NewReferencePlane
Dim pt1 As New XYZ(-0.5, -2.0, 0.0) '' one end
Dim pt2 As New XYZ(-0.5, 2.0, 0.0) '' the other end
Dim vec As XYZ = XYZ.BasisZ '' perpendicular to the first line.
Dim view As View = _
Utils.FindElement(rvtDoc, GetType(ViewPlan), "Lower Ref. Level")
z (0,0,1)
y
pt1 pt2
x
© 2013 Autodesk The Revit Family API
2. Layout Reference Planes
Example: NewReferencePlane2()
Sub AddReferencePlane_VerticalOffset2()
'' create a reference plan, using NewReferencePlane
Dim pt1 As New XYZ(-0.5, -2.0, 0.0) '' one end
Dim pt2 As New XYZ(-0.5, 2.0, 0.0) '' the other end
Dim pt3 As New XYZ(-0.5, -1.0, 1.0) '' the third point
Dim view As View = _
Utils.FindElement(rvtDoc, GetType(ViewPlan), "Lower Ref. Level")
pt3
pt1 pt2
x
© 2013 Autodesk The Revit Family API
3. Add Parameters
Parameters
Dimensions
Sub AddParameter_Tw()
'' add a parameter "Tw"
Dim isInstance As Boolean = False
Dim paramTw As FamilyParameter = _ m_familyMgr.AddParameter( _
"Tw", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, isInstance)
'' give initial values.
Dim tw As Double = Utils.mmToFeet(150.0) '' in metric
'Dim tw As Double = 0.5 '' in feet
m_familyMgr.Set(paramTw, tw)
'' add a formula (optional)
m_familyMgr.SetFormula( _
paramTw, "Width / 4.0“)
End Sub
Sub AddParameter_Material()
Sub AddTypes()
'' AddType(name,Width,Depth)
AddType("600x900", 600.0, 900.0)
AddType("1000x300", 1000.0, 300.0)
AddType("600x600", 600.0, 600.0)
End Sub
Testing Procedure
Add a solid
Add alignments
'' (3) height of the extrusion. distance between Lower and Upper Ref Level.
Dim dHeight As Double = Utils.mmToFeet(4000)
End Function
Sub AddAlignment_Level( _
ByVal pSolid As Extrusion, ByVal normal As XYZ, ByVal nameLevel As String)
'' which direction are we looking at?
Dim pView As View = Utils.FindElement(m_rvtDoc, GetType(View), "Front")
'' find the upper ref level. FindElement() is a helper function.
Dim pLevel As Level = Utils.FindElement(m_rvtDoc, GetType(Level), nameLevel)
'' find the face of the box. FindFace() is a helper function.
Dim pFace As PlanarFace = Utils.FindFace(pSolid, normal)
'' create alignments
m_rvtDoc.FamilyCreate.NewAlignment(pView, pLevel.PlaneReference,
pFace.Reference)
End Sub
In <SDK folder>\Samples\FamilyCreation
AutoJoin
Automatically join geometry of multiple generic forms for use in family modeling and massing
Uses the method Document::CombineElements to join geometry between overlapping generic forms
Provide a utility method check geometry object overlap, based on Face::Intersect(Curve) method
AutoParameter
Batch mode automatic addition of shared or non-shared parameters to one or more family documents
Process active family document or all families in a folder
Uses FamilyManager class AddParameter methods
Reads input data from parameter text files in Revit shared parameter format
DWGFamilyCreation
Import DWG file into family document add type parameters to the imported instance
DWGFileName with the DWG file name and ImportTime when it was imported
GenericModelCreation
Create a generic model using extrusion, blend, revolution, sweep and swept blend elements
Checks that open document is a family one or creates a new family document
Exercises CreateSketchPlane, NewLineBound, and FamilyItemFactory methods to create profiles and shapes
TypeRegeneration
Use FamilyManager Types property to determine all types defined, and CurrentType to iterate through them
Report whether all types regenerated successfully, log errors to file
ValidateParameters
Check whether every type has valid values for certain parameters and log result to file
External application subscribing to DocumentSaving and DocumentSavingAs events runs check automatically
External command to launch manually
WindowWizard
Create a window family via wizard user interface
Start in window family template, e.g. Metric Window.rtf
User defines input dimensions for window parameters and materials
Create extrusion, alignment, dimension, reference plane, and family type
CreateAirHandler – RME
Create an air handler with pipe and duct connectors
Check the template family category to verify valid starting point
Use FamilyItemFactory class NewExtrusion, NewPipeConnector, NewDuctConnector methods
Set proper connector parameters and use Document::CombineElements to join the extrusions
CreateTruss – RST
Create a mono truss in a truss family document
Create truss curves using NewModelCurve, set truss type through ModelCurve TrussCurveType property
Add constraints to the truss curves with NewAlignment