Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "One-Click Architecture: Using the Revit API to Build Your Models Danny Polkinhorn."— Presentation transcript:

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

2 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

3 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

4 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

5 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

6 Geometry Walls.vb 30’ in Y direction 30’ in X direction 30’ in Y direction NW Cornerstone (SW) NE SE

7

8 Document Application (DocCreator) (AppCreator)

9 Creators Walls.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

10 ‘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)

11 Transactions Walls Roof Views Sheet Command ERROR SucceededFailed

12 Transactions 'Create a transaction, a bucket of database changes to the Revit model Using trans As Transaction = New Transaction( _ uiApp.ActiveUIDocument.Document, "Walls“) End Using Walls.vb

13 Transactions 'Create a transaction, a bucket of database changes to the Revit model Using trans As Transaction = New Transaction( _ uiApp.ActiveUIDocument.Document, "Walls") End Using Walls.vb 'Start the transaction trans.Start

14 Transactions 'Create a transaction, a bucket of database changes to the Revit model Using trans As Transaction = New Transaction( _ uiApp.ActiveUIDocument.Document, "Walls") End Using Walls.vb 'Start the transaction trans.Start 'create the walls Walls.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))

15 Transactions End Using Walls.vb 'create the walls Walls.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))

16 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 'create the walls Walls.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))

17 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.MoveNext Dim 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

18 Transactions Do While iter.MoveNext... Loop 'commit the walls to the model trans.Commit() End Using Walls.vb

19 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

20 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 wall Families.AddDesk(point) Commands.vb

21 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

22 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 items collector.OfCategory(BuiltInCategory.OST_Doors) 'Filter the collector for only symbols (types in Revit UI) collector.OfClass(GetType(FamilySymbol)) 'Grab the first element from the collector Dim doorSymbol As FamilySymbol = collector.FirstElement Families.vb

23 Add the Door 'Add the door door = docCreator.NewFamilyInstance( _ doorLocation, doorSymbol, wall, _ wall.Level, [Structure].StructuralType.NonStructural) Families.vb

24 Desk Insertion Point 'Insertion point Dim inspt As XYZ = startpoint.Add(New XYZ(8, 8, 0)) Families.vb

25 Desk Insertion Point 'Insertion point Dim inspt As XYZ = startpoint.Add(New XYZ(8, 8, 0))... docCreator.NewFamilyInstance( _ inspt, deskSymbol, [Structure].StructuralType.NonStructural) Families.vb

26 Gut Check time... Compile and Run your project Start the Plugins > External Command >RTC2012 Start

27 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

28 Floor Plan Type 'Get the element ID of the floor plan view type... Dim planID As ElementId = viewFamilyTypes.First.Id Views.vb

29 Create floor plan 'Get the element ID of the floor plan view type... Dim planID As ElementId = viewFamilyTypes.First.Id 'Create the floor plan view floorPlan = ViewPlan.Create(uiApp.ActiveUIDocument.Document, planID, levelId) floorPlan.Name = name Views.vb

30 Annotation 'Annotate the views Dimensions.AddDimensions(newGrids, newViews(0)) Families.AddDoorTag(newDoor, newViews(0)) Commands.vb

31 Door Tag 'The door's location Dim doorLoc As LocationPoint = door.Location 'Add the door tag docCreator.NewTag(view, door, False, _ TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, doorLoc.Point) Families.vb

32 'Create the sheets Sheets.AddSheets(newViews, "RTC2012 Sheet") Commands.vb

33 Create Sheet 'Create the sheet and change its name Dim sheet As ViewSheet = docCreator.NewViewSheet(titleblock) sheet.Name = name Sheets.vb

34 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 exception If Viewport.CanAddViewToSheet( _ uiApp.ActiveUIDocument.Document, sheet.Id, view.Id) Then End If Sheets.vb

35 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 exception If 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.Outline width = outline.Max.U - outline.Min.U height = outline.Max.V - outline.Min.V End If Sheets.vb

36 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

37 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 sheet Dim vp As Viewport = Viewport.Create( _ uiApp.ActiveUIDocument.Document, sheet.Id, view.Id, inspt) End If Sheets.vb

38 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 sheet Dim vp As Viewport = Viewport.Create( _ uiApp.ActiveUIDocument.Document, sheet.Id, view.Id, inspt) 'Add the view's width to the insertion point pt = pt.Add(New XYZ(width + 0.1, 0, 0)) End If Sheets.vb

39 Gut Check Time #2... Compile and Run your project Start the Plugins > External Command >RTC2012 Start

40 Questions?

41

42


Download ppt "One-Click Architecture: Using the Revit API to Build Your Models Danny Polkinhorn."

Similar presentations


Ads by Google