1 / 40

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

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

aitana
Télécharger la présentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 DimnewGridsAsElementSet DimnewWallsAsElementSet DimnewViewsAsElementSet = NewElementSet DimnewDoorAsFamilyInstance 'Get the application uiApp = commandData.Application Commands.vb

  4. Starting Point 'Get a starting point from the user Dim selAs 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 AsElementSet = NewElementSet '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. DimswPtAsXYZ = startPoint DimnwPtAsXYZ = startPoint.Add(NewXYZ(0, 30, 0))          DimsePtAsXYZ = swPt.Add(NewXYZ(30, 0, 0))          DimnePtAsXYZ = swPt.Add(NewXYZ(30, 30, 0)) Walls.vb

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

  7. Application (AppCreator) Document (DocCreator)

  8. Creators 'Get our creator objects so we can create lines and grids Dim appCreatorAs Autodesk.Revit.Creation.Application= _ uiApp.Application.Create Dim doc As Autodesk.Revit.DB.Document= _ uiApp.ActiveUIDocument.Document Dim docCreatorAs Autodesk.Revit.Creation.Document= doc.Create Walls.vb

  9. ‘Create the 4 curve objects that will make up the wall baselines Dim westWallAs Curve = appCreator.NewLineBound(swPt, nwPt) Dim southWallAs Curve = appCreator.NewLineBound(swPt, sePt) Dim eastWallAs Curve = appCreator.NewLineBound(sePt, nePt) Dim northWallAs Curve = appCreator.NewLineBound(nwPt, nePt)

  10. Transactions Walls Roof ERROR Views Command Sheet Succeeded Failed

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

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

  13. Transactions 'Create a transaction, a bucket of database changes to the Revit model Using trans AsTransaction = NewTransaction( _ 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))

  14. 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))

  15. Transactions 'Let's make each wall go up to Level 2... 'Use an iterator to loop through all the walls we just created DimiterAsElementSetIterator = 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))

  16. Transactions 'Let's make each wall go up to Level 2... 'Use an iterator to loop through all the walls we just created DimiterAsElementSetIterator = Walls.ForwardIterator End Using Walls.vb DoWhileiter.MoveNext Dim w AsWall = 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

  17. Transactions DoWhileiter.MoveNext ... Loop 'commit the walls to the model trans.Commit() End Using Walls.vb

  18. Add Grids 'Get a starting point from the user Dim selAs 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

  19. Add Families 'Get a starting point from the user Dim selAs 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

  20. Door Location 'Get the midpoint of the wall, using the location curve DimwallCurveAsLocationCurve = TryCast(wall.Location, LocationCurve) DimdoorLocationAsXYZ = _ MidPoint(wallCurve.Curve.EndPoint(0), wallCurve.Curve.EndPoint(1)) Families.vb

  21. Door Type 'Create a collector so we can get the door symbol (Door Type in Revit UI) Dim collector AsFilteredElementCollector = _ NewFilteredElementCollector(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 DimdoorSymbolAsFamilySymbol = collector.FirstElement Families.vb

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

  23. Desk Insertion Point 'Insertion point DiminsptAsXYZ = startpoint.Add(NewXYZ(8, 8, 0)) Families.vb

  24. Desk Insertion Point 'Insertion point DiminsptAsXYZ = startpoint.Add(NewXYZ(8, 8, 0)) ... docCreator.NewFamilyInstance( _ inspt, deskSymbol, [Structure].StructuralType.NonStructural) Families.vb

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

  26. 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

  27. Floor Plan Type 'Get the element ID of the floor plan view type... DimplanIDAsElementId = viewFamilyTypes.First.Id Views.vb

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

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

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

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

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

  33. 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 IfViewport.CanAddViewToSheet( _ uiApp.ActiveUIDocument.Document, sheet.Id, view.Id) Then End If 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 IfViewport.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 AsBoundingBoxUV = view.Outline width = outline.Max.U - outline.Min.U height = outline.Max.V - outline.Min.V End If Sheets.vb

  35. Create Sheet height = outline.Max.V - outline.Min.V 'Set up the insertion point of the view, the center of the view DiminsptAsXYZ = pt.Add(NewXYZ(width / 2, height / 2, 0)) 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 DiminsptAsXYZ = pt.Add(NewXYZ(width / 2, height / 2, 0)) 'Add the viewport which places the view on the sheet DimvpAsViewport = Viewport.Create( _ uiApp.ActiveUIDocument.Document, sheet.Id, view.Id, inspt) 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 DiminsptAsXYZ = pt.Add(NewXYZ(width / 2, height / 2, 0)) 'Add the viewport which places the view on the sheet DimvpAsViewport = Viewport.Create( _ uiApp.ActiveUIDocument.Document, sheet.Id, view.Id, inspt) 'Add the view's width to the insertion point pt = pt.Add(NewXYZ(width + 0.1, 0, 0)) End If Sheets.vb

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

More Related