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() avui.ZoomToFit()
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
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
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 p = line.GetEndPoint(0)
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 # 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"])
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() avui.ZoomToFit()