04-Revit API Programming - Families
04-Revit API Programming - Families
2014 Autodesk
Background
2014 Autodesk
Agenda
What is it?
Where to begin, flavors, editor, what is possible
Best practice
2014 Autodesk
Geometry in 3D or 2D
Data that supports definition/creation of objects
Generically - 3 Types
2014 Autodesk
Which is better?
2014 Autodesk
Revit Architecture
Revit Structure
Revit MEP
2014 Autodesk
2014 Autodesk
2014 Autodesk
2014 Autodesk
Family Resources
Newsgroups
discussion.autodesk.com
AUGI - http://forums.augi.com
2014 Autodesk
Family API
Learn basics along the best practice
What is it?
2014 Autodesk
FamilyManager class:
2014 Autodesk
Labs Exercises
Hands-on
Hands-on
2014 Autodesk
rvtDoc.IsFamilyDocument()
rvtDoc.OwnerFamily.FamilyCategory.Name
rvtDoc.FamilyCreate.NewExtrusion()
rvtDoc.FamilyCreate.NewAlignment()
familyMgr = rvtDoc.FamilyManager
familyMgr.NewType()
familyMgr.Parameter(); familyMgr.Set()
2014 Autodesk
rvtDoc.FamilyCreate.NewReferencePlane()
familyMgr.AddParameter()
rvtDoc.FamilyCreate.NewDimension()
2014 Autodesk
add formulas
add materials
familyMgr.SetFormula()
pSolid.Parameter(Material)
familyMgr.AddParameter(MyColumnFinish,
BuiltInParameterGroup.PG_MATERIALS, ParameterType.Material, True)
familyMgr.AssociateElementParameterToFamilyParameter()
2014 Autodesk
Objective:
rvtDoc.FamilyCreate.NewSymbolicCurve()
rvtDoc.FamilyCreate.NewModelCurve()
FamilyElementVisibility(FamilyElementVisibilityType.ViewSpecific/Model)
FamilyElementVisibility.IsShownInFine, etc.
pLine.SetVisibility(pFamilyElementVisibility)
2014 Autodesk
Reference planes
Parameters
Dimensions
Types
Geometry
Alignments
2014 Autodesk
Plan
Reference planes
Parameters
Types
Geometry
1. Plan
Center (Left/Right)
Right
Back
Center (Front/Back)
Front
2014 Autodesk
1. Plan
document
2014 Autodesk
Reference Plane :
OffsetV
Reference Plane :
OffsetH
2014 Autodesk
2014 Autodesk
z (0,0,1)
pt2
pt1
x
2014 Autodesk
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")
Dim refPlane As ReferencePlane = _
z
m_rvtDoc.FamilyCreate.NewReferencePlane2(pt1, pt2, pt3, view)
refPlane.Name = "OffsetV"
End Sub
pt3
y
pt2
pt1
x
2014 Autodesk
3. Add Parameters
Parameters
Dimensions
2014 Autodesk
Example: Tw
Dim m_familyMgr As FamilyManager = m_rvtDoc.FamilyManager
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
2014 Autodesk
2014 Autodesk
3b Add Dimensions
Example: Tw
Sub AddDimention_Tw()
'' find the plan view that we want to place a dimension
Dim pViewPlan As View = _
Utils.FindElement(m_rvtDoc, GetType(ViewPlan), "Lower Ref. Level")
'' find two reference planes which we want to add a dimension between
Dim ref1 As ReferencePlane = _
Utils.FindElement(m_rvtDoc, GetType(ReferencePlane), "Left")
Dim ref2 As ReferencePlane = _
Utils.FindElement(m_rvtDoc, GetType(ReferencePlane), "OffsetV")
'' make an array of references
Dim pRefArray As New ReferenceArray
pRefArray.Append(ref1.Reference)
pRefArray.Append(ref2.Reference)
'' define a dimension line
Dim p0 As XYZ = ref1.FreeEnd
Dim p1 As XYZ = ref2.FreeEnd
Dim pLine As Line = Line.CreateBound(p0, p1)
'' create a dimension
Dim pDimTw As Dimension = _
m_rvtDoc.FamilyCreate.NewDimension(pViewPlan, pLine, pRefArray)
'' add label to the dimension
pDimTw.Label = m_familyMgr.Parameter("Tw")
End Sub
2014 Autodesk
2014 Autodesk
2014 Autodesk
2014 Autodesk
Testing Procedure
2014 Autodesk
Add a solid
Add alignments
2014 Autodesk
Example: Extrusion
Function CreateSolid() As Extrusion
'' (1) define a simple L-shape profile
Dim pProfile As CurveArrArray = CreateProfileLShape()
'' (2) create a sketch plane
Dim pRefPlane As ReferencePlane = _
Utils.FindElement(m_rvtDoc, GetType(ReferencePlane), "Reference Plane")
Dim pSketchPlane As SketchPlane = _
SketchPlane.Create(m_rvtDoc, pRefPlane.Plane)
'' (3) height of the extrusion. distance between Lower and Upper Ref Level.
Dim dHeight As Double = Utils.mmToFeet(4000)
'' (4) create an extrusion here. at this point.
Dim bIsSolid As Boolean = True '' as oppose to void.
Dim pSolid As Extrusion = _
m_rvtDoc.FamilyCreate.NewExtrusion(bIsSolid, pProfile, pSketchPlane,
dHeight)
Return pSolid
End Function
2014 Autodesk
tw
5
2014 Autodesk
2014 Autodesk
2014 Autodesk
2014 Autodesk
2014 Autodesk
Visibility
Sub SetVisibility(ByVal pSolid As Extrusion)
'' set the visibility of the model not to shown in coarse.
Dim pVis As FamilyElementVisibility = _
New FamilyElementVisibility(FamilyElementVisibilityType.Model)
pVis.IsShownInCoarse = False
pSolid.SetVisibility(pVis)
End Sub
2014 Autodesk
Associate parameters
Sub addMaterials(ByVal pSolid As Extrusion)
'' get the material id that we are intersted in (e.g., "Glass")
Dim pMat As Material = Utils.FindElement(m_rvtDoc, GetType(Material), "Glass")
Dim idMat As ElementId = pMat.Id
'' add a parameter for material finish
Dim paramFamilyMaterial As FamilyParameter = _
m_familyMgr.Parameter("Column Finish")
'' associate material parameter to the family parameter we just added
Dim paramSolidMaterial As Parameter = pSolid.Parameter("Material")
m_familyMgr.AssociateElementParameterToFamilyParameter( _
paramSolidMaterial, paramFamilyMaterial)
'' let's add another type with Glass finish
AddType("Glass", 600.0, 600.0)
m_familyMgr.Set(paramFamilyMaterial, idMat)
End Sub
2014 Autodesk
Learning resources
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
2014 Autodesk
Learning resources
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
2014 Autodesk
Learning resources
CreateAirHandler RME
CreateTruss RST
2014 Autodesk
and more
Learning resources
Revit Developer Guide
Family Creation
RevitAPI.chm
Recordings
Revit Family API Webcast (July 2009)
AU 2009 virtual class AU2009 CP9118-1 :
The New Autodesk Revit Family API: Everything is Relative by Jeremy Tammik
In Revit 2010, but mostly still valid for Family API
Based on the exercise labs
2014 Autodesk
Summary
What is it?
Where to begin, flavors, editor, what is possible
Best practice
2014 Autodesk
2014 Autodesk
Autodesk is a registered trademark of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names,
product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications
and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document.
2014 Autodesk, Inc. All rights reserved.