script to adjust subsurf levels based on distance

The idea is to have a script that can automatically adjust subsurf levels on meshes depending on their distance from the active camera.

So first thing to do is to check which items have a subsurf modifier
then measure the distance to each in turn and set the subsurf lower if its over a certain distance.

Would this be easy to do? I know almost nothing about coding.
Should it be run every frame?

yes it’s easy

Good good,

So how can you code to search for objects by their modifier.

there would need to be a checkbox on each object to exclude the object from the operation.

i can do pseudo code, but not the real thing.

boolean mesh
boolean subsurf
integer subsurf level

get all objects in the current scene
get active camera location

if object is mesh

[QUOTE]check if subsurf is true
[QUOTE]if subsurf is true then
get location
if distance between object and camera is in range (something, something) then
set subsurf level to 0
else
if distance between object and camera is in range (something, something) then
set subsurf level to 1
else
if distance between object and camera is in range (something, something) then
set subsurf level to 2
else
if distance between object and camera is in range (something, something) then
set subsurf level to 3
else
if distance between object and camera is in range (something, something) then
set subsurf level to 4
else
if distance between object and camera is in range (something, something) then
set subsurf level to 5
Move to the next object

else
move to the next object[/QUOTE]
else
move to the next object[/QUOTE]

So…
How do you translate that into actual code?

Actually i suppose this should be in the python support forum, is it possible to move myself or does a mod have to move it?

for ob in bpy.data.objects:
…for mod in ob.modifiers:
…if mod.type == ‘subsurf’:
…our code

is it possible to make it check for object type first?
then make a list of of all mesh objects, then work its way through that list?

Sorry for being so obtuse, my experience with programming so far is limited to a few expressions in spreadsheets so this is somewhat unknown

Checks for object type “mesh”:

for ob in bpy.data.objects:
	if ob.type != 'MESH':
		continue
	for mod in ob.modifiers:
		if mod.type == 'SUBSURF':
			# our code