Maxscript: Zoom Extents
by Dave Buchhofer on Aug.18, 2008, under maxscript
Who would have thought this would be a pain? All i wanted to do was have a default camera zoom to fit on all objects in a scene, regardless of their size/distrobution.
turns out theres code in the maxscript docs that can do it, but it does it by way of modifying the FOV of the camera to fit. thats all good, as long as you’re not working with hugely varying size objects.. re: how far away from the objects is your camera to start will determine how wide the view is. functional, but not ideal.
here’s a little function snippet that does the same functions, but will create a camera, rig it up to a certain direction, and then move it out on its local Z axis until the set of objects is fully in view.
Again, something i’m using in conjunction with Paul’s Batching script refrenced below.












November 7th, 2008 on 8:23 am
I have the same question with you.
My opinion is: first,to set a user view to macth your camera ,then zoom extents all object ,last match your camera to the user view.
IF you have any progress,please share with me,thank you very much.
November 7th, 2008 on 12:07 pm
William, Thanks, that was actually my first try, and it appeared to work for many objects, but failed completely on others, and i was unable to really figure out why.
going that way there is also the issue of resetting the viewports to ensure that you only have 1 perspective view
I noticed the other day that Andrew http://andklv2.narod.ru/maxscripts/ak-maxscripts.html has a script 111_batch_preview_maker_v0.9 that has a few more robust options for building that default camera that I was planning to look at once things clear up again.
November 8th, 2008 on 4:27 am
I also found an example “Simulating Zoom Extents All” in MAXScript_Reference.
http://www.kxcad.net/autodesk/Autodesk_MAXScript_Reference_9/camera_common_properties_operators_and_methods.htm
May it be helpful.
November 8th, 2008 on 4:08 pm
Here’s the math involved to figure out the distance needed to move the camera in -Z to keep a bounding box in view without having to adjust the fov to fit
“the distance D so that:
D = R / sin( FOV/2 );
where R is the object’s bounding sphere radius
”
taken from: http://www.theswapmeet-forum.com/viewtopic.php?t=4214
June 22nd, 2010 on 7:36 am
Hi,Dave Buchhofer.
Now, you have find out the right way to do this maxscript?
July 6th, 2010 on 7:44 am
I never did find the best way, I think I bounce between using the above, and just setting to perspective view, selecting all, zooming extents, and then calling create camera from view
both methods were effective enough for my purposes at the time, so I hadn’t gone any further
June 1st, 2011 on 11:57 am
followup of some more information and some nicer code @ http://forums.cgsociety.org/showthread.php?t=977505 if anyone ends up landing on this page still.