예제 #1
0
파일: script.py 프로젝트: tkahng/ISGpyRevit
def create_section(el, section_type):
    # ensure wall is straight
    curve = wall.Location.Curve
    # determine section box
    curve_transform = curve.ComputeDerivatives(0.5, True)

    origin = el.Location.Point
    # wall_direction = curve_transform.BasisX.Normalize()  # type: XYZ
    wall_direction = el.FacingOrientation
    up = DB.XYZ.BasisZ
    section_direction = el.FacingOrientation.CrossProduct(up)
    right = up.CrossProduct(section_direction)

    transform = DB.Transform.Identity
    transform.Origin = origin
    transform.BasisX = wall_direction
    transform.BasisY = up
    transform.BasisZ = section_direction

    section_box = DB.BoundingBoxXYZ()
    section_box.Transform = transform

    # Try to retrieve element height, width and lenght
    try:
        el_depth = wall.WallType.Width
    except AttributeError:
        el_depth = 2

    el_width = curve.Length

    el_bounding_box = wall.get_BoundingBox(None)
    z_min = el_bounding_box.Min.Z
    z_max = el_bounding_box.Max.Z
    el_height = z_max - z_min

    depth_offset = 1
    height_offset = 1
    width_offset = 1

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

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

    return DB.ViewSection.CreateSection(revit.doc, section_type, section_box)
예제 #2
0
def create_room_axo_rotate(room, angle=None, view_scale=50, doc=revit.doc):
    if angle == None:
        angle = room_rotation_angle(room)

    # create 3D axo for a room, rotate the Section Box to fit
    threeD_type = database.get_view_family_types(
        DB.ViewFamily.ThreeDimensional, doc)[0]

    threeD = DB.View3D.CreateIsometric(doc, threeD_type.Id)
    threeD.Scale = view_scale

    # 1. rotate room geometry
    room_shell = room.ClosedShell
    rotation = DB.Transform.CreateRotationAtPoint(DB.XYZ.BasisZ, -angle,
                                                  room.Location.Point)
    rotated_shell = room_shell.GetTransformed(rotation)

    # 2. get the bbox of the rotated shell
    shell_bb = rotated_shell.GetBoundingBox()
    rotate_back = rotation.Inverse

    # rotate the bbox back
    new_bb = DB.BoundingBoxXYZ()
    new_bb.Transform = rotate_back
    new_bb.Min = shell_bb.Min
    new_bb.Max = shell_bb.Max

    # set bbox as section box
    sb = threeD.SetSectionBox(new_bb)

    # set orientation
    eye = DB.XYZ(0, 0, 0)
    up = DB.XYZ(-1, 1, 2)
    fwd = DB.XYZ(-1, 1, -1)

    view_orientation = DB.ViewOrientation3D(eye, up, fwd)
    threeD.SetOrientation(view_orientation)
    threeD.CropBoxActive = True
    doc.Regenerate()
    crop_axo(threeD)

    return threeD
예제 #3
0
def create_section(wall, section_type):
    # ensure wall is straight
    line = wall.Location.Curve
    # determine section box
    p = line.GetEndPoint(0)
    q = line.GetEndPoint(1)
    v = q - p

    bb = wall.get_BoundingBox(None)
    minZ = bb.Min.Z
    maxZ = bb.Max.Z

    w = v.GetLength()
    # h = maxZ - minZ
    # d = wall.WallType.Width
    offset = 0.1 * w

    bbox_min = DB.XYZ(-w, minZ - offset, -offset)
    bbox_max = DB.XYZ(w, maxZ + offset, 0)

    midpoint = p + 0.5 * v
    walldir = v.Normalize()
    up = DB.XYZ.BasisZ
    viewdir = walldir.CrossProduct(up)

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

    section_box = DB.BoundingBoxXYZ()
    section_box.Transform = t
    section_box.Min = bbox_min
    section_box.Max = bbox_max

    DB.ViewSection.CreateSection(revit.doc, section_type, section_box)
예제 #4
0
def create_parallel_bbox(line, crop_elem, offset=300/304.8):
    # create section parallel to x (solution by Building Coder)
    p = line.GetEndPoint(0)
    q = line.GetEndPoint(1)
    v = q - p

    # section box width
    w = v.GetLength()
    bb = crop_elem.get_BoundingBox(None)
    minZ = bb.Min.Z
    maxZ = bb.Max.Z
    # height = maxZ - minZ

    min = DB.XYZ(-w, minZ - offset, -offset)
    max = DB.XYZ(w, maxZ + offset, offset)

    centerpoint = p + 0.5 * v
    direction = v.Normalize()
    up = DB.XYZ.BasisZ
    view_direction = direction.CrossProduct(up)

    t = DB.Transform.Identity
    t.Origin = centerpoint
    t.BasisX = direction
    t.BasisY = up
    t.BasisZ = view_direction

    section_box = DB.BoundingBoxXYZ()
    section_box.Transform = t
    section_box.Min = min
    section_box.Max = max

    pt = DB.XYZ(centerpoint.X, centerpoint.Y, minZ)
    point_in_front = pt+(-3)*view_direction
    #TODO: check other usage
    return section_box
예제 #5
0
    except Exception:
        logger.error('CAN NOT FIND ZOOM STATE FILE:\n{0}'.format(datafile))

elif selected_switch == '3D Section Box State':
    datafile = \
        script.get_document_data_file(file_id='SaveSectionBoxState',
                                      file_ext='pym',
                                      add_cmd_name=False)

    try:
        f = open(datafile, 'r')
        sbox = pickle.load(f)
        vo = pickle.load(f)
        f.close()

        sb = DB.BoundingBoxXYZ()
        sb.Min = DB.XYZ(sbox.minx, sbox.miny, sbox.minz)
        sb.Max = DB.XYZ(sbox.maxx, sbox.maxy, sbox.maxz)

        vor = DB.ViewOrientation3D(DB.XYZ(vo.eyex,
                                          vo.eyey,
                                          vo.eyez),
                                   DB.XYZ(vo.upx,
                                          vo.upy,
                                          vo.upz),
                                   DB.XYZ(vo.forwardx,
                                          vo.forwardy,
                                          vo.forwardz))

        av = revit.activeview
        avui = revit.uidoc.GetOpenUIViews()[0]
예제 #6
0
 def deserialize(self):
     bbox_xyz = DB.BoundingBoxXYZ()
     bbox_xyz.Min = self.min.deserialize()
     bbox_xyz.Max = self.max.deserialize()
     bbox_xyz.Transform = self.transform.deserialize()
     return bbox_xyz
예제 #7
0
def create_dest_view(view_type, view_name, view_scale):
    with DB.Transaction(doc, 'Create model view') as t:
        t.Start()
        try:
            new_dest_view = None

            if view_type == 'Floor Plan':
                level = get_view_level()
                view_fam_typeid = \
                    doc.GetDefaultElementTypeId(
                        DB.ElementTypeGroup.ViewTypeFloorPlan
                        )
                new_dest_view = \
                    DB.ViewPlan.Create(doc, view_fam_typeid, level.Id)

            elif view_type == 'Reflected Ceiling Plan':
                level = get_view_level()
                view_fam_typeid = \
                    doc.GetDefaultElementTypeId(
                        DB.ElementTypeGroup.ViewTypeCeilingPlan
                    )
                new_dest_view = \
                    DB.ViewPlan.Create(doc, view_fam_typeid, level.Id)

            elif view_type == 'Section':
                view_fam_typeid = \
                    doc.GetDefaultElementTypeId(
                        DB.ElementTypeGroup.ViewTypeSection
                        )
                view_direction = DB.BoundingBoxXYZ()
                trans_identity = DB.Transform.Identity
                trans_identity.BasisX = -DB.XYZ.BasisX  # x direction
                trans_identity.BasisY = DB.XYZ.BasisZ  # up direction
                trans_identity.BasisZ = DB.XYZ.BasisY  # view direction
                view_direction.Transform = trans_identity
                new_dest_view = \
                    DB.ViewSection.CreateSection(doc,
                                                 view_fam_typeid,
                                                 view_direction)
                scale_param = new_dest_view.Parameter[
                    DB.BuiltInParameter.
                    SECTION_COARSER_SCALE_PULLDOWN_IMPERIAL]
                scale_param.Set(1)

            elif view_type == 'Elevation':
                view_fam_typeid = \
                    doc.GetDefaultElementTypeId(
                        DB.ElementTypeGroup.ViewTypeElevation
                        )
                elev_marker = \
                    DB.ElevationMarker.CreateElevationMarker(
                        doc,
                        view_fam_typeid,
                        DB.XYZ(0, 0, 0),
                        1)
                default_floor_plan = find_first_floorplan()
                new_dest_view = \
                    elev_marker.CreateElevation(doc, default_floor_plan.Id, 0)
                scale_param = new_dest_view.Parameter[
                    DB.BuiltInParameter.
                    SECTION_COARSER_SCALE_PULLDOWN_IMPERIAL]
                scale_param.Set(1)

            elif view_type == 'Drafting':
                view_fam_typeid = \
                    doc.GetDefaultElementTypeId(
                        DB.ElementTypeGroup.ViewTypeDrafting
                        )
                new_dest_view = DB.ViewDrafting.Create(doc, view_fam_typeid)

            revit.update.set_name(new_dest_view, view_name)
            new_dest_view.Scale = view_scale
            model_visib_param = new_dest_view.Parameter[
                DB.BuiltInParameter.VIEW_MODEL_DISPLAY_MODE]
            if model_visib_param:
                model_visib_param.Set(2)
            new_dest_view.CropBoxActive = False
            new_dest_view.CropBoxVisible = False
            t.Commit()
            return new_dest_view
        except Exception as create_err:
            t.RollBack()
            logger.debug('Can not create model view: {} | {}'.format(
                view_name, create_err))
            raise create_err