Exemple #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
Exemple #2
0
        av = uidoc.GetOpenUIViews()[0]
        av.ZoomAndCenterRectangle(vc1, vc2)
    except:
        __window__.Show()
        print('CAN NOT FIND ZOOM STATE FILE:\n{0}'.format(datafile))

elif selected_switch == '3D Section Box State':
    datafile = usertemp + '\\' + prjname + '_pySaveSectionBoxState.pym'

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

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

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

        av = uidoc.ActiveGraphicalView
        avui = uidoc.GetOpenUIViews()[0]
        if isinstance(av, View3D):
            with Transaction(doc, 'Paste Section Box Settings') as t:
                t.Start()
                av.SetSectionBox(sb)
                av.SetOrientation(vor)
                t.Commit()
Exemple #3
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
Exemple #4
0
def get_bbox_of_solid_vertices(fam_inst):
    """
    retrieves a bounding box from first volumetric
    element in family instance
    """
    s0_geo = fam_inst.get_Geometry(geo_opt)

    pts = {
        "xmin": None,
        "xmax": None,
        "ymin": None,
        "ymax": None,
        "zmin": None,
        "zmax": None
    }

    for geo_elem in s0_geo:
        for solid in geo_elem.GetInstanceGeometry():
            if solid.GetType().Name == "Solid":
                if solid.Volume > 0.0:
                    edges = solid.Edges
                    for edge in edges:
                        ep = edge.AsCurve().GetEndPoint(0)
                        # first populate coords in dict
                        if not pts["xmin"]:
                            pts["xmin"] = ep.X

                        if not pts["xmax"]:
                            pts["xmax"] = ep.X

                        if not pts["ymin"]:
                            pts["ymin"] = ep.Y

                        if not pts["ymax"]:
                            pts["ymax"] = ep.Y

                        if not pts["zmin"]:
                            pts["zmin"] = ep.Z

                        if not pts["zmax"]:
                            pts["zmax"] = ep.Z

                        # then keep updating
                        if ep.X < pts["xmin"]:
                            pts["xmin"] = ep.X
                        elif ep.X > pts["xmax"]:
                            pts["xmax"] = ep.X

                        if ep.Y < pts["ymin"]:
                            pts["ymin"] = ep.Y
                        elif ep.Y > pts["ymax"]:
                            pts["ymax"] = ep.Y

                        if ep.Z < pts["zmin"]:
                            pts["zmin"] = ep.Z
                        elif ep.Z > pts["zmax"]:
                            pts["zmax"] = ep.Z
                    break

    vertex_bbox = BoundingBoxXYZ()
    vertex_bbox.Max = XYZ(pts["xmax"], pts["ymax"], pts["zmax"])
    vertex_bbox.Min = XYZ(pts["xmin"], pts["ymin"], pts["zmin"])
    return vertex_bbox
Exemple #5
0
def get_bbox_of_solid_vertices(fam_inst):
    inst_geo = fam_inst.get_Geometry(geo_opt)
    ortho = True
    orthos = (
        XYZ.BasisX.ToString(),
        (XYZ.BasisX * -1).ToString(),
        XYZ.BasisY.ToString(),
        (XYZ.BasisY * -1).ToString(),
        XYZ.BasisZ.ToString(),
        (XYZ.BasisZ * -1).ToString(),
    )

    pts = {
        "xmin": None,
        "xmax": None,
        "ymin": None,
        "ymax": None,
        "zmin": None,
        "zmax": None,
    }

    for geo_elem in inst_geo:
        for solid in geo_elem.GetInstanceGeometry():
            if solid.GetType().Name == "Solid":
                if solid.Volume > 0.0:
                    faces = solid.Faces
                    for face in faces:
                        if ortho:
                            if face.FaceNormal.ToString() not in orthos:
                                ortho = False
                    edges = solid.Edges
                    for edge in edges:
                        ep = edge.AsCurve().GetEndPoint(0)
                        # first populate coords in dict
                        if not pts["xmin"]:
                            pts["xmin"] = ep.X

                        if not pts["xmax"]:
                            pts["xmax"] = ep.X

                        if not pts["ymin"]:
                            pts["ymin"] = ep.Y

                        if not pts["ymax"]:
                            pts["ymax"] = ep.Y

                        if not pts["zmin"]:
                            pts["zmin"] = ep.Z

                        if not pts["zmax"]:
                            pts["zmax"] = ep.Z

                        # then keep updating
                        if ep.X < pts["xmin"]:
                            pts["xmin"] = ep.X
                        elif ep.X > pts["xmax"]:
                            pts["xmax"] = ep.X

                        if ep.Y < pts["ymin"]:
                            pts["ymin"] = ep.Y
                        elif ep.Y > pts["ymax"]:
                            pts["ymax"] = ep.Y

                        if ep.Z < pts["zmin"]:
                            pts["zmin"] = ep.Z
                        elif ep.Z > pts["zmax"]:
                            pts["zmax"] = ep.Z
                    if not ortho:
                        dprint(" non-ortho!! ")
                    break

    vertex_bbox = BoundingBoxXYZ()
    vertex_bbox.Max = XYZ(pts["xmax"], pts["ymax"], pts["zmax"])
    vertex_bbox.Min = XYZ(pts["xmin"], pts["ymin"], pts["zmin"])
    return vertex_bbox, ortho
Exemple #6
0
        # factor for direction of section view
        if p.X > q.X or (p.X == q.X and p.Y < q.Y): fc = 1
        else: fc = -1

        midpoint = p + 0.5 * v
        walldir = fc * v.Normalize()
        up = XYZ.BasisZ
        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
Exemple #7
0
    # Create a BoundingBoxXYZ oriented parallel to the element
    curve_transform = curve.ComputeDerivatives(0.5, True)

    origin = curve_transform.Origin
    wall_direction = curve_transform.BasisX.Normalize()  # type: XYZ
    up = XYZ.BasisZ
    section_direction = wall_direction.CrossProduct(up)
    right = up.CrossProduct(section_direction)

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

    section_box = BoundingBoxXYZ()
    section_box.Transform = transform

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

    el_width = curve.Length

    el_bounding_box = element.get_BoundingBox(None)
    z_min = el_bounding_box.Min.Z
    z_max = el_bounding_box.Max.Z
    el_height = z_max - z_min
	upz = 0

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document

usertemp = os.getenv('Temp')
prjname = op.splitext( op.basename( doc.PathName ) )[0]
datafile = usertemp + '\\' + prjname + '_pySaveSectionBoxState.pym'

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

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

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

	av = uidoc.ActiveGraphicalView
	avui = uidoc.GetOpenUIViews()[0]
	if isinstance( av, View3D ):
		with Transaction(doc, 'Paste Section Box Settings') as t:
			t.Start()
			av.SetSectionBox( sb )
			av.SetOrientation( vor )
			t.Commit()