Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import clr
- import System
- clr.AddReference('RevitAPI')
- clr.AddReference('RevitAPIUI')
- from Autodesk.Revit.DB import *
- app = __revit__.Application
- doc = __revit__.ActiveUIDocument.Document
- t = Transaction(doc, 'Place an adaptive component with Points from Excel')
- t.Start()
- # accessing the Excel application
- xlApp = System.Runtime.InteropServices.Marshal.GetActiveObject('Excel.Application')
- # specify number of repetition; numBays and number of points in each; numPoints
- numBays = 3
- numPoints = 8
- # worksheet, row, and column parameters
- worksheet = 1
- rowStart = 1
- rowEnd = numBays * numPoints
- colStart = 1
- colEnd = 2
- j = 2
- for bay in range(numBays):
- # family symbol name to place
- symbName = 'Rig6ptSolid'
- # create a filtered element collector set to Category OST_GenericModel and Class FamilySymbol
- collector = FilteredElementCollector(doc)
- collector.OfCategory(BuiltInCategory.OST_GenericModel)
- collector.OfClass(FamilySymbol)
- famtypeitr = collector.GetElementIdIterator()
- famtypeitr.Reset()
- # search family symbols in document
- for item in famtypeitr:
- famtypeID = item
- famsymb = doc.get_Element(famtypeID)
- # if the FamilySymbol is the name we are looking for, create a new instance
- if famsymb.Family.Name == symbName:
- adaptComp = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, famsymb)
- adptPoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(adaptComp)
- # starting adaptive point locations. get_Element returns a Reference Point
- aPt = []
- loc = []
- trans = []
- for i in range(numPoints):
- aPt.append(doc.get_Element(adptPoints[i]))
- # desired Adaptive Point locations from Excel Spreadsheet
- for i in range(numPoints):
- # for j in range(numBays):
- loc.append(XYZ(float(xlApp.Worksheets(worksheet).Cells(i+2, j).Text), float(xlApp.Worksheets(worksheet).Cells(i+2, j+1).Text), 0))
- for i in range(numPoints):
- # some vector math to get the translation for MoveElement()
- trans.append(loc[i].Subtract(aPt[i].Position))
- # position adaptive component using MoveElemnt()
- ElementTransformUtils.MoveElement(doc, adptPoints[i], trans[i])
- j = j+2
- t.Commit()
Add Comment
Please, Sign In to add comment