para-analytics

Automating Placement: Adaptive Components

Jan 29th, 2013
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. import clr
  2. import System
  3. clr.AddReference('RevitAPI')
  4. clr.AddReference('RevitAPIUI')
  5. from Autodesk.Revit.DB import *
  6.  
  7. app = __revit__.Application
  8. doc = __revit__.ActiveUIDocument.Document
  9.  
  10. t = Transaction(doc, 'Place an adaptive component with Points from Excel')
  11.  
  12. t.Start()
  13.  
  14. # accessing the Excel application
  15. xlApp = System.Runtime.InteropServices.Marshal.GetActiveObject('Excel.Application')
  16.  
  17. # specify number of repetition; numBays and number of points in each; numPoints
  18. numBays = 3
  19. numPoints = 8
  20.  
  21. # worksheet, row, and column parameters
  22. worksheet = 1
  23. rowStart = 1
  24. rowEnd = numBays * numPoints
  25. colStart = 1
  26. colEnd = 2
  27.  
  28. j = 2
  29. for bay in range(numBays):
  30.        
  31.     # family symbol name to place
  32.     symbName = 'Rig6ptSolid'
  33.  
  34.     # create a filtered element collector set to Category OST_GenericModel and Class FamilySymbol
  35.     collector = FilteredElementCollector(doc)
  36.     collector.OfCategory(BuiltInCategory.OST_GenericModel)
  37.     collector.OfClass(FamilySymbol)
  38.  
  39.     famtypeitr = collector.GetElementIdIterator()
  40.     famtypeitr.Reset()
  41.  
  42.     # search family symbols in document
  43.     for item in famtypeitr:
  44.         famtypeID = item
  45.         famsymb = doc.get_Element(famtypeID)
  46.        
  47.         # if the FamilySymbol is the name we are looking for, create a new instance
  48.         if famsymb.Family.Name == symbName:
  49.        
  50.             adaptComp = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, famsymb)
  51.             adptPoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(adaptComp)
  52.  
  53.             # starting adaptive point locations. get_Element returns a Reference Point
  54.             aPt = []
  55.             loc = []
  56.             trans = []
  57.  
  58.             for i in range(numPoints):
  59.                 aPt.append(doc.get_Element(adptPoints[i]))
  60.  
  61.             # desired Adaptive Point locations from Excel Spreadsheet
  62.             for i in range(numPoints):
  63.                 # for j in range(numBays):
  64.                     loc.append(XYZ(float(xlApp.Worksheets(worksheet).Cells(i+2, j).Text), float(xlApp.Worksheets(worksheet).Cells(i+2, j+1).Text), 0))
  65.                    
  66.             for i in range(numPoints):
  67.                 # some vector math to get the translation for MoveElement()
  68.                 trans.append(loc[i].Subtract(aPt[i].Position))
  69.                
  70.                 # position adaptive component using MoveElemnt()
  71.                 ElementTransformUtils.MoveElement(doc, adptPoints[i], trans[i])
  72.                
  73.     j = j+2
  74.        
  75.        
  76. t.Commit()
Add Comment
Please, Sign In to add comment