Beispiel #1
0
def create_dest_view(view_type, view_name, view_scale):
    with Transaction(doc, 'Create model view') as t:
        t.Start()
        try:
            dest_view = None
            if view_type == 'Floor Plan':
                level = get_view_level()
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeFloorPlan)
                dest_view = ViewPlan.Create(doc, view_fam_typeid, level.Id)
            elif view_type == 'Reflected Ceiling Plan':
                level = get_view_level()
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeCeilingPlan)
                dest_view = ViewPlan.Create(doc, view_fam_typeid, level.Id)
            elif view_type == 'Section':
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeSection)
                view_direction = BoundingBoxXYZ()
                trans_identity = Transform.Identity
                trans_identity.BasisX = -XYZ.BasisX  # x direction
                trans_identity.BasisY = XYZ.BasisZ  # up direction
                trans_identity.BasisZ = XYZ.BasisY  # view direction
                view_direction.Transform = trans_identity
                dest_view = ViewSection.CreateSection(doc, view_fam_typeid,
                                                      view_direction)
                scale_param = dest_view.LookupParameter(
                    'Hide at scales coarser than')
                scale_param.Set(1)
            elif view_type == 'Elevation':
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeElevation)
                elev_marker = ElevationMarker.CreateElevationMarker(
                    doc, view_fam_typeid, XYZ(0, 0, 0), 1)
                default_floor_plan = find_first_floorplan()
                dest_view = elev_marker.CreateElevation(
                    doc, default_floor_plan.Id, 0)
                scale_param = dest_view.LookupParameter(
                    'Hide at scales coarser than')
                scale_param.Set(1)

            dest_view.ViewName = view_name
            dest_view.Scale = view_scale
            model_visib_param = dest_view.LookupParameter('Display Model')
            model_visib_param.Set(2)
            dest_view.CropBoxActive = False
            dest_view.CropBoxVisible = False
            t.Commit()
            return dest_view
        except Exception as create_err:
            t.RollBack()
            logger.debug('Can not create model view: {} | {}'.format(
                view_name, create_err))
            raise create_err
Beispiel #2
0
        def wrapped_f(*args):
            t = Transaction(doc, 'Create view section')

            # Select an element in Revit
            for element_id in uidoc.Selection.GetElementIds():

                point_bottom_left, point_top_right = bottom_left_top_right(
                    element_id,
                    X_Right=self.X_Right,
                    X_Left=self.X_Left,
                    Y_Up=self.Y_Up,
                    Y_Bottom=self.Y_Bottom)

                # get active view to put section
                ViewParent = doc.ActiveView

                # get id of viewparent
                ViewParentid = ViewParent.Id

                # get id of type view
                View_Family_Type_Id = ViewParent.GetTypeId()

                # start transaction
                t.Start()

                # create callout
                view = ViewSection.CreateCallout(doc, ViewParentid,
                                                 View_Family_Type_Id,
                                                 point_bottom_left,
                                                 point_top_right)

                # Rename view after create
                In_param_1, In_param_2 = args
                view.Name = f(In_param_1, In_param_2)

                # Increate number
                In_param_2 = str(int(In_param_2) + 1)

                # commit transaction
                t.Commit()
Beispiel #3
0
def rename_view_from_form(
    In_param_1,
    In_param_2,
):
    """ 
    rename view from from user input
    """
    t = Transaction(doc, 'Create view section')
    # start transaction
    t.Start()

    # Select an element in Revit
    for element_id in uidoc.Selection.GetElementIds():

        point_bottom_left, point_top_right = bottom_left_top_right(element_id)

        # get active view to put section
        ViewParent = doc.ActiveView

        # get id of viewparent
        ViewParentid = ViewParent.Id

        # get id of type view
        View_Family_Type_Id = ViewParent.GetTypeId()

        # create callout
        view = ViewSection.CreateCallout(doc, ViewParentid,
                                         View_Family_Type_Id,
                                         point_bottom_left, point_top_right)

        # Rename view after create
        view.Name = rename_name_view(In_param_1, In_param_2)

        # Increate number
        In_param_2 = str(int(In_param_2) + 1)

    # commit transaction
    t.Commit()
Beispiel #4
0
def create_dest_view(view_type, view_name, view_scale):
    with Transaction(doc, 'Create model view') as t:
        t.Start()
        try:
            dest_view = None
            if view_type == 'Floor Plan':
                level = get_view_level()
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeFloorPlan)
                dest_view = ViewPlan.Create(doc, view_fam_typeid, level.Id)
            elif view_type == 'Reflected Ceiling Plan':
                level = get_view_level()
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeCeilingPlan)
                dest_view = ViewPlan.Create(doc, view_fam_typeid, level.Id)
            elif view_type == 'Section':
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeSection)
                view_direction = BoundingBoxXYZ()
                trans_identity = Transform.Identity
                trans_identity.BasisX = -XYZ.BasisX  # x direction
                trans_identity.BasisY = XYZ.BasisZ  # up direction
                trans_identity.BasisZ = XYZ.BasisY  # view direction
                view_direction.Transform = trans_identity
                dest_view = ViewSection.CreateSection(doc, view_fam_typeid,
                                                      view_direction)
                scale_param = dest_view.Parameter[
                    DB.BuiltInParameter.
                    SECTION_COARSER_SCALE_PULLDOWN_IMPERIAL]
                scale_param.Set(1)
            elif view_type == 'Elevation':
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeElevation)
                elev_marker = ElevationMarker.CreateElevationMarker(
                    doc, view_fam_typeid, XYZ(0, 0, 0), 1)
                default_floor_plan = find_first_floorplan()
                dest_view = elev_marker.CreateElevation(
                    doc, default_floor_plan.Id, 0)
                scale_param = dest_view.Parameter[
                    DB.BuiltInParameter.
                    SECTION_COARSER_SCALE_PULLDOWN_IMPERIAL]
                scale_param.Set(1)
            elif view_type == 'Drafting':
                view_fam_typeid = doc.GetDefaultElementTypeId(
                    ElementTypeGroup.ViewTypeDrafting)
                dest_view = ViewDrafting.Create(doc, view_fam_typeid)

            dest_view.ViewName = view_name
            dest_view.Scale = view_scale
            model_visib_param = dest_view.Parameter[
                DB.BuiltInParameter.VIEW_MODEL_DISPLAY_MODE]
            if model_visib_param:
                model_visib_param.Set(2)
            dest_view.CropBoxActive = False
            dest_view.CropBoxVisible = False
            t.Commit()
            return dest_view
        except Exception as create_err:
            t.RollBack()
            logger.debug('Can not create model view: {} | {}'.format(
                view_name, create_err))
            raise create_err
Beispiel #5
0
        viewdir = walldir.CrossProduct(up)

        t = Transform.Identity
        t.Origin = midpoint
        t.BasisX = walldir
        t.BasisY = up
        t.BasisZ = viewdir

        sectionBox = BoundingBoxXYZ()
        sectionBox.Transform = t
        sectionBox.Min = min  # scope box bottom
        sectionBox.Max = max  # scope box top

        with db.Transaction('Create Section'):
            # Create wall section view
            newSection = ViewSection.CreateSection(doc, viewFamilyTypeId,
                                                   sectionBox)
            newSections.append(newSection)
else:
    newSections = []
    for wall in walls:
        # Determine section box
        lc = wall.Location
        line = lc.Curve

        p = line.GetEndPoint(0)
        q = line.GetEndPoint(1)
        v = p - q

        bb = wall.get_BoundingBox(None)
        minZ = bb.Min.Z
        maxZ = bb.Max.Z
Beispiel #6
0
    z_min = el_bounding_box.Min.Z
    z_max = el_bounding_box.Max.Z
    el_height = z_max - z_min

   # Get Wall Offset Params if Element is Wall
    try:
        base_offset = element.Parameter[BuiltInParameter.WALL_BASE_OFFSET].AsDouble()
    except AttributeError:
        base_offset = 0    

    # Set BoundingBoxXYZ's boundaries
    section_box.Min = XYZ(-el_width / 2 - width_offset,
                          -height_offset + base_offset,
                          -el_depth / 2 - depth_offset)
    section_box.Max = XYZ(el_width / 2 + width_offset,
                          el_height + height_offset + base_offset,
                          el_depth / 2 + depth_offset)

    # Append necessary parameters to create sections in a list
    sections.append({"box": section_box,
                     "suffix": element.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString()
                     })

with rpw.db.Transaction("Create sections", doc):
    for section in sections:
        section_view = ViewSection.CreateSection(doc, section_type.Id, section["box"])
        try:
            section_view.Name = "{} {}".format(prefix, section["suffix"])
        except Exceptions.ArgumentException:
            logger.info("Failed to rename view {}. Desired name already exist.".format(section_view.Name))