def create_dimension(element, point1, point2, reference_names_list, view, direction_to_move=XYZ(0, 0, 0)): line = Line.CreateBound(point1, point2) refArray = ReferenceArray() for ref in reference_names_list: refArray.Append(element.GetReferenceByName(ref)) dim = doc.Create.NewDimension(view, line, refArray) ElementTransformUtils.MoveElement(doc, dim.Id, direction_to_move) return dim
def CreateDimensions(filledRegion, dimensionDirection): document = filledRegion.Document view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) edgesDirection = dimensionDirection.CrossProduct(view.ViewDirection) edges = [] for x in FindRegionEdges(filledRegion): if IsEdgeDirectionSatisfied(x, edgesDirection): edges.append(x) if len(edges) < 2: return shift = UnitUtils.ConvertToInternalUnits( -10 * view.Scale, DisplayUnitType.DUT_MILLIMETERS) * edgesDirection dimensionLine = Line.CreateUnbound( filledRegion.get_BoundingBox(view).Min + shift, dimensionDirection) references = ReferenceArray() for edge in edges: references.Append(edge.Reference) document.Create.NewDimension(view, dimensionLine, references)
# import sys # sys.exit() from Autodesk.Revit.DB import DatumExtentType, FilteredElementCollector, BuiltInCategory, Line, Reference, ReferenceArray, Options, XYZ import rpw from rpw import revit doc = revit.doc uidoc = revit.uidoc selection = FilteredElementCollector(doc).OfCategory( BuiltInCategory.OST_Levels).WhereElementIsNotElementType() # All reference in reference will be dimensioned reference_array = ReferenceArray() options = Options(ComputeReferences=True, IncludeNonVisibleObjects=True) for element in selection: reference_array.Append(Reference(element)) crvs = [] ends = [] for element in selection: crvs.extend( element.GetCurvesInView(DatumExtentType.ViewSpecific, doc.ActiveView)) for crv in crvs:
geo = element_type.get_Geometry(opt) geometry_instance = [ g for g in geo if g.GetType().Name == 'Solid' and g.Volume > 0 ][0] new_list = [] edges = geometry_instance.Edges for e in edges: curve = e.AsCurve() if curve.GetType().Name == 'Line': direction = curve.Direction if direction.X > 0: new_list.append(e.AsCurve().ToProtoType()) refArray = ReferenceArray() # ref = [l.Reference for l in geometry_instance.SymbolGeometry if l.GetType().Name == 'Line'] # for r in new_list: # refArray.Append(r) # refArray.Append(new_list[0]) # refArray.Append(new_list[1]) # refArray.Append(ref[4]) # TransactionManager.Instance.EnsureInTransaction(doc) # bnews = [] # pt1 = XYZ(-2.89579276782608E-19, 6.22647337376248E-15, 0) # pt2 = XYZ(-2.01413037506538E-15, -1.24671916017717, 0)
# def isParallel(v1,v2): # return v1.CrossProduct(v2).IsAlmostEqualTo(XYZ(0,0,0)) el = UnwrapElement(IN[1]) # noqa crv = el.Location.Curve linedir = crv.GetEndPoint(1) - crv.GetEndPoint(0) opt = Options() opt.ComputeReferences = True opt.IncludeNonVisibleObjects = True opt.View = doc.ActiveView gem = el.get_Geometry(opt) ref = ReferenceArray() for g in gem: if isinstance(g, Solid): faces = g.Faces for face in faces: if face: faceNormal = face.FaceNormal if faceNormal.CrossProduct(linedir).IsAlmostEqualTo(XYZ(0, 0, 0)): ref.Append(face.Reference) TransactionManager.Instance.EnsureInTransaction(doc) dim = doc.Create.NewDimension(doc.ActiveView, crv, ref)
from Autodesk.Revit.Creation.ItemFactoryBase import NewDimension # Store current document into variable doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument # Get current view view = doc.ActiveView # Select all grids by filter gridsFilter = ElementCategoryFilter(BuiltInCategory.OST_Grids) gridsCollector = FilteredElementCollector(doc).WherePasses(gridsFilter) \ .WhereElementIsNotElementType() # Variables to split grids into columns and rows gridsColumn = ReferenceArray() gridsRow = ReferenceArray() gridsC = [] gridsR = [] # Check grids name and split in groups for grid in gridsCollector: gridName = grid.LookupParameter("Name").AsString() if any(char.isdigit() for char in gridName): gridsColumn.Append(Reference(grid)) gridsC.append(grid) else: gridsRow.Append(Reference(grid)) gridsR.append(grid) # Retrieve endpoints