one-click architecture: using the revit api to build your models

Post on 11-Jan-2016

66 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

One-Click Architecture: Using the Revit API to Build Your Models. Danny Polkinhorn. Setup. Copy the Addins From: ...RTC2012.OneClick\ Addins To: % ProgramData %\ Autodesk\Revit\ Addins \2013 or C:\ProgramData\Autodesk\Revit\Addins\2013 Open both Solutions - PowerPoint PPT Presentation

TRANSCRIPT

One-Click Architecture: Using the Revit API to Build Your Models

Danny Polkinhorn

Setup

• Copy the Addins– From:

• ...RTC2012.OneClick\Addins– To:

• %ProgramData%\Autodesk\Revit\Addins\2013 or• C:\ProgramData\Autodesk\Revit\Addins\2013

• Open both Solutions– ...RTC2012.OneClick\_Start\RTC2012.OneClick_Start.sln– ...RTC2012.OneClick\_Finish\RTC2012.OneClick_Finish.sln

Variables

'Create some buckets for the various things we'll be creating             

Dim newGrids As ElementSet             Dim newWalls As ElementSet             Dim newViews As ElementSet = New ElementSet             Dim newDoor As FamilyInstance             

'Get the application             uiApp = commandData.Application

Commands.vb

Starting Point

'Get a starting point from the user Dim sel As Selection = uiApp.ActiveUIDocument.Selection Dim point As XYZ = sel.PickPoint("Please select a cornerstone

location")

'Add walls and grids newWalls = Walls.AddWalls(point)

Commands.vb

Four corners

'this is going to be my return value         Dim walls As ElementSet = New ElementSet        'Create the 4 corners of the building, using the start point ‘as the southwest corner. Make it 30 feet square, ‘Revit API units are in Feet.         Dim swPt As XYZ = startPoint         Dim nwPt As XYZ = startPoint.Add(New XYZ(0, 30, 0))         Dim sePt As XYZ = swPt.Add(New XYZ(30, 0, 0))         Dim nePt As XYZ = swPt.Add(New XYZ(30, 30, 0))

Walls.vb

GeometryWalls.vb

30’ in Y direction

30’ in X direction

30’ in X direction

30’ in Y direction

NW

Cornerstone(SW)

NE

SE

Document

Application

(DocCreator)

(AppCreator)

CreatorsWalls.vb

'Get our creator objects so we can create lines and grids Dim appCreator As Autodesk.Revit.Creation.Application = _

uiApp.Application.Create Dim doc As Autodesk.Revit.DB.Document = _

uiApp.ActiveUIDocument.Document Dim docCreator As Autodesk.Revit.Creation.Document =

doc.Create

‘Create the 4 curve objects that will make up the wall baselines

Dim westWall As Curve = appCreator.NewLineBound(swPt, nwPt)

Dim southWall As Curve = appCreator.NewLineBound(swPt, sePt)

Dim eastWall As Curve = appCreator.NewLineBound(sePt, nePt)

Dim northWall As Curve = appCreator.NewLineBound(nwPt, nePt)

Transactions

Walls

Roof

Views

SheetCommand

ERROR

SucceededFailed

Transactions

'Create a transaction, a bucket of database changes to the Revit modelUsing trans As Transaction = New Transaction( _

uiApp.ActiveUIDocument.Document, "Walls“)

End Using

Walls.vb

Transactions

'Create a transaction, a bucket of database changes to the Revit modelUsing trans As Transaction = New Transaction( _

uiApp.ActiveUIDocument.Document, "Walls")

End Using

Walls.vb

'Start the transactiontrans.Start

Transactions

'Create a transaction, a bucket of database changes to the Revit modelUsing trans As Transaction = New Transaction( _

uiApp.ActiveUIDocument.Document, "Walls")

End Using

Walls.vb

'Start the transactiontrans.Start

'create the wallsWalls.Insert(Wall.Create(doc, westWall, levelId, False))Walls.Insert(Wall.Create(doc, eastWall, levelId, False))Walls.Insert(Wall.Create(doc, northWall, levelId, False))Walls.Insert(Wall.Create(doc, southWall, levelId, False))

Transactions

End Using

Walls.vb

'create the wallsWalls.Insert(Wall.Create(doc, westWall, levelId, False))Walls.Insert(Wall.Create(doc, eastWall, levelId, False))Walls.Insert(Wall.Create(doc, northWall, levelId, False))Walls.Insert(Wall.Create(doc, southWall, levelId, False))

Transactions

'Let's make each wall go up to Level 2...

'Use an iterator to loop through all the walls we just createdDim iter As ElementSetIterator = Walls.ForwardIterator

End Using

Walls.vb

'create the wallsWalls.Insert(Wall.Create(doc, westWall, levelId, False))Walls.Insert(Wall.Create(doc, eastWall, levelId, False))Walls.Insert(Wall.Create(doc, northWall, levelId, False))Walls.Insert(Wall.Create(doc, southWall, levelId, False))

Transactions

'Let's make each wall go up to Level 2...

'Use an iterator to loop through all the walls we just created

Dim iter As ElementSetIterator = Walls.ForwardIterator

End Using

Walls.vb

Do While iter.MoveNextDim w As Wall = iter.Current

'This WALL_HEIGHT_TYPE parameter is the name for the Top Constraint

'Use the RevitLookup tool in the SDK to help you discover parameter names.

w.Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set( _levels.Item("Level 2").Id)

Loop

Transactions

Do While iter.MoveNext...

Loop

'commit the walls to the modeltrans.Commit()

End Using

Walls.vb

Add Grids

'Get a starting point from the user Dim sel As Selection = uiApp.ActiveUIDocument.Selection Dim point As XYZ = sel.PickPoint("Please select a

cornerstone location")

'Add walls and grids newWalls = Walls.AddWalls(point) newGrids = Grids.AddGridLines(point)

Commands.vb

Add Families

'Get a starting point from the user Dim sel As Selection = uiApp.ActiveUIDocument.Selection Dim point As XYZ = sel.PickPoint("Please select a

cornerstone location")

'Add walls and grids newWalls = Walls.AddWalls(point) newGrids = Grids.AddGridLines(point)

'Add families

newDoor = Families.AddDoor(newWalls(1))   'east wallFamilies.AddDesk(point)

Commands.vb

Door Location

'Get the midpoint of the wall, using the location curve

Dim wallCurve As LocationCurve = TryCast(wall.Location, LocationCurve)

Dim doorLocation As XYZ = _MidPoint(wallCurve.Curve.EndPoint(0),

wallCurve.Curve.EndPoint(1))

Families.vb

Door Type

'Create a collector so we can get the door symbol (Door Type in Revit UI)

Dim collector As FilteredElementCollector = _

New FilteredElementCollector(uiApp.ActiveUIDocument.Document)'Filter the collector for only Door related itemscollector.OfCategory(BuiltInCategory.OST_Doors)'Filter the collector for only symbols (types in Revit UI)collector.OfClass(GetType(FamilySymbol))'Grab the first element from the collectorDim doorSymbol As FamilySymbol = collector.FirstElement

Families.vb

Add the Door

'Add the doordoor = docCreator.NewFamilyInstance( _

doorLocation, doorSymbol, wall, _wall.Level,

[Structure].StructuralType.NonStructural)

Families.vb

Desk Insertion Point

'Insertion pointDim inspt As XYZ = startpoint.Add(New XYZ(8, 8, 0))

Families.vb

Desk Insertion Point

'Insertion pointDim inspt As XYZ = startpoint.Add(New XYZ(8, 8, 0))

...

docCreator.NewFamilyInstance( _

inspt, deskSymbol, [Structure].StructuralType.NonStructural)

Families.vb

Gut Check time...

• Compile and Run your project• Start the Plugins > External Command >RTC2012 Start

Add Views

'Make the views

newViews.Insert(Views.AddPlanView("RTC2012 Floor Plan"))

newViews.Insert(Views.AddSectionView(point, "RTC2012 Section"))

newViews.Insert(Views.Add3DView(point, "RTC2012 3D View"))

Commands.vb

Floor Plan Type

'Get the element ID of the floor plan view type...Dim planID As ElementId = viewFamilyTypes.First.Id

Views.vb

Create floor plan

'Get the element ID of the floor plan view type...Dim planID As ElementId = viewFamilyTypes.First.Id

'Create the floor plan viewfloorPlan = ViewPlan.Create(uiApp.ActiveUIDocument.Document, planID, levelId)floorPlan.Name = name

Views.vb

Annotation

'Annotate the viewsDimensions.AddDimensions(newGrids, newViews(0))Families.AddDoorTag(newDoor, newViews(0))

Commands.vb

Door Tag

'The door's locationDim doorLoc As LocationPoint = door.Location

'Add the door tagdocCreator.NewTag(view, door, False, _

TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, doorLoc.Point)

Families.vb

'Create the sheetsSheets.AddSheets(newViews, "RTC2012 Sheet")

Commands.vb

Create Sheet

'Create the sheet and change its nameDim sheet As ViewSheet = docCreator.NewViewSheet(titleblock)sheet.Name = name

Sheets.vb

Create Sheet

'We need to make sure the view hasn't already been added to a sheet'If we don't check, and the view has been added, we'll get an exceptionIf Viewport.CanAddViewToSheet( _

uiApp.ActiveUIDocument.Document, sheet.Id, view.Id) Then End If

Sheets.vb

Create Sheet

'We need to make sure the view hasn't already been added to a sheet'If we don't check, and the view has been added, we'll get an exceptionIf Viewport.CanAddViewToSheet( _

uiApp.ActiveUIDocument.Document, sheet.Id, view.Id) Then 

'Get the outline of the view so we can determine its width and height

Dim outline As BoundingBoxUV = view.Outlinewidth = outline.Max.U - outline.Min.Uheight = outline.Max.V - outline.Min.V

End If

Sheets.vb

Create Sheet

height = outline.Max.V - outline.Min.V

'Set up the insertion point of the view, the center of the view

Dim inspt As XYZ = pt.Add(New XYZ(width / 2, height / 2, 0))

End If

Sheets.vb

Create Sheet

height = outline.Max.V - outline.Min.V

'Set up the insertion point of the view, the center of the view

Dim inspt As XYZ = pt.Add(New XYZ(width / 2, height / 2, 0))

'Add the viewport which places the view on the sheetDim vp As Viewport = Viewport.Create( _

uiApp.ActiveUIDocument.Document, sheet.Id, view.Id, inspt)

End If

Sheets.vb

Create Sheet

height = outline.Max.V - outline.Min.V

'Set up the insertion point of the view, the center of the view

Dim inspt As XYZ = pt.Add(New XYZ(width / 2, height / 2, 0))

'Add the viewport which places the view on the sheetDim vp As Viewport = Viewport.Create( _

uiApp.ActiveUIDocument.Document, sheet.Id, view.Id, inspt)

'Add the view's width to the insertion pointpt = pt.Add(New XYZ(width + 0.1, 0, 0))

End If

Sheets.vb

Gut Check Time #2...

• Compile and Run your project• Start the Plugins > External Command >RTC2012 Start

Questions?

top related