Here's a small improvement/alternative that considers the distance to the actual viewpoint of the frustum rather than the point on the ground on which the view is focussed:
// If this function returns a true, the default draw code of the object will not be executed.
Vec3 mgroundviewpoint=Vec3(viewpointx(view).value,viewpointy(view).value,viewpointz(view).value);
Vec3 mcurrcentre=current.getLocation(0.5,0.5,0.5).project(current.up,model());
Vec3 groundpath=mgroundviewpoint-mcurrcentre;
double azimuth=-1*viewpointrx(view).value;
double elevation=Math.radians(azimuth);
double viewradius=viewpointradius(view).value;
double groundradius=Math.cos(elevation)*viewradius;
double z=Math.sin(elevation)*viewradius;
double bearing=viewpointrz(view).value-90;
double rotation=Math.radians(bearing);
double y=Math.sin(rotation)*groundradius;
double x=Math.cos(rotation)*groundradius;
Vec3 topov=Vec3(x,y,z);
Vec3 mpov=mgroundviewpoint+topov;
Vec3 path=mpov-mcurrcentre;
//print("dist:",path.magnitude,"azimuth",azimuth,"groundRadius",groundradius,"height",z,"bearing",bearing,"x",x,"y",y,"flexdistfromview:",distfromviewpoint(current,view));
if (path.magnitude>20)
switch_hidecontents(current,1);
else
switch_hidecontents(current,0);
It probably still worth have frustum culling enabled with this because you could be very close but looking in the other direction.