Donate Now Goal amount for this year: 3000 USD, Received: 1207 USD (40%)

Results 1 to 1 of 1

Thread: PyRevit: Elevation crop boxes + Elevation direction

  1. #1
    New Member
    Join Date
    January 11, 2019
    Current Local Time
    03:16 PM

    PyRevit: Elevation crop boxes + Elevation direction

    Hello everyone,

    I've been having some trouble using the RevitAPI to create elevations. I am using pyRevit to create a suite of buttons which can create elevations based off a model line (similar to Jeremy Graham's post: Module 2 Unwrapped Elevations | Learn Dynamo)

    I am currently having a few issues:

    - When using a model line to create elevation view. Sometimes the elevation is flipped away from the orientation of the curve. I believe this is because once the marker and view is created, the rotation is based on the direction of the input model line. Is there a way of ensuring the the model lines are all maintain a consistent direction? That way, all the elevation views will be facing in the correct direction.

    - Secondly, I would like the crop region to align perfectly with the extents of the Model Line. I have tried using the CropShapeRegionManager to set the boundary, however I keep getting error messages saying that the curveLoop I am inputting is not valid (created from an offset of the original line with additional line segments added to form a closed rectangular region if viewed in plan). I have no idea why it is not being taken as a valid input by the RevitAPI.

    Here is the code that sort of works, it does not try to apply a cropshape or change line directions. I would also welcome feedback on how I am coding. Still fairly new to using the RevitAPI. Any help would be greatly appreciated.

    """Aligns selected markers on sheets to a specified markers"""
    from pyrevit import revit, DB, UI
    from pyrevit import forms
    from pyrevit import script
    from math import atan2
    __author__ = 'Kai Zhu'
    __doc__ = 'WIP - This button uses a model line to create an elevation'
    logger = script.get_logger()
    # Get Document
    doc = revit.doc
        #Select model lines
        lines = revit.pick_elements()
        elements = []
        names = []
        counter_success = 0
        counter_failed = 0
        offset = 1000
        collector = DB.FilteredElementCollector(doc).OfClass(DB.ViewFamilyType).ToElements()
        for i in collector:
            if i.ViewFamily == DB.ViewFamily.Elevation:
                for j in i.Parameters:
                    if j.Definition.Name == "Type Name":
        type_name =, button_name='Select Type')
        zipped_view_types = zip(elements, names)
        for viewfamilytype in zipped_view_types:
            if viewfamilytype[1] == type_name:
                view_type = viewfamilytype[0]
        #Setup transaction
        t = DB.Transaction(revit.doc, "Line to elevation")
        for line in lines:
            geo_line = line.GeometryCurve
            #Get start, end point and midpoint on crv
            start_point = geo_line.GetEndPoint(0)
            end_point = geo_line.GetEndPoint(1)
            mid_point = geo_line.Evaluate(0.5, True)
            #Create Axis line for rotation of elevation marker
            axis_point = DB.XYZ(mid_point.X, mid_point.Y, (mid_point.Z + 100))
            axis_line = DB.Line.CreateBound(mid_point, axis_point)
            #Create Normal Vector along line
            normal = geo_line.Direction.Normalize()
            direction = axis_point
            cross = normal.CrossProduct(direction)
            pntEnd = mid_point + cross.Multiply(10)
            normal_line = DB.Line.CreateBound(mid_point, pntEnd)
            #Create offset curve to calculate 
            offset_line = geo_line.CreateOffset(offset, normal_line.Direction.Normalize())
            offset_line_midpoint = offset_line.Evaluate(0.5, True)
            #Find angle to rotate elevation marker
            elevationPTY = offset_line_midpoint.Y
            elevationPTX = offset_line_midpoint.X
            combY = elevationPTY - mid_point.Y
            combX = elevationPTX - mid_point.X
            angle = atan2(combY, combX) 
            #Create elevation Marker + elevation
            marker = DB.ElevationMarker.CreateElevationMarker(doc, view_type.Id, mid_point, 100)
            ele = marker.CreateElevation(doc, doc.ActiveView.Id, 0)
            #Rotate Elevation Marker
            DB.ElementTransformUtils.RotateElement(doc, marker.Id, axis_line, angle)
        #End transaction
    print('Something went wrong. Please contact Kai')
    Attached Thumbnails Attached Thumbnails PyRevit: Elevation crop boxes + Elevation direction-model_line_fail.jpg   PyRevit: Elevation crop boxes + Elevation direction-model_line_fail2.jpg  

Similar Threads

  1. Elevation Tag disappears when the crop region is turned on
    By katewood1989 in forum Architecture and General Revit Questions
    Replies: 4
    Last Post: February 20th, 2018, 10:48 PM
  2. Revit Elevation Scope Box and Edit Crop Problem
    By kpierce_tvs in forum Architecture and General Revit Questions
    Replies: 3
    Last Post: April 11th, 2017, 08:31 PM
  3. Non-rectangular crop in elevation only prints in Raster not Vector
    By ryntau in forum Architecture and General Revit Questions
    Replies: 1
    Last Post: January 27th, 2016, 06:52 PM
  4. Help with Scope Boxes on an Elevation View
    By svccess in forum Architecture and General Revit Questions
    Replies: 3
    Last Post: January 31st, 2014, 03:46 PM
  5. Elevation Depth & Scope Boxes
    By cellophane in forum Architecture and General Revit Questions
    Replies: 0
    Last Post: June 8th, 2012, 04:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts