Notifications
Clear all

[Closed] ZoomToObjBB

Based on a previous thread:
http://forums.cgsociety.org/showthread.php?f=98&t=977505&highlight=zoom+extents

I was expecting this to work?:

viewport.ZoomToBounds false (point3 bmin.x bmin.y 0) (point3 bmax.x bmax.y 0)

MXS chm states:

The second and third arguments define the bounding region to zoom to.

In context:

global ZoomToObjBB

fn ZoomToObjBB =
(
	nodes = for node in selection where iskindof node GeometryClass collect node
	if nodes.count > 0 do
	(
		view = viewport.activeViewport
		local bmin = [1e9,1e9,0], bmax = [-1e9,-1e9,0]

		gw.setTransform (matrix3 1)
		transPoint = gw.hTransPoint
		for node in nodes do
		(
			mesh = snapshotasmesh node
			for v=1 to mesh.numverts do
			(
				vp = transPoint (GetVert mesh v)
				if vp.x < bmin.x do bmin.x = vp.x
				if vp.x > bmax.x do bmax.x = vp.x
				if vp.y < bmin.y do bmin.y = vp.y
				if vp.y > bmax.y do bmax.y = vp.y
			)
			free mesh
		)
		w = (bmax.x - bmin.x) as integer
		h = (bmax.y - bmin.y) as integer
		print bmin.x
		print bmin.y
		print bmax.x
		print bmax.y
		
		viewport.ZoomToBounds false (point3 bmax.x bmax.y 0) (point3 bmin.x bmin.y 0)
		completeRedraw()
	)
)

ZoomToObjBB()

Guess I’m missing something?!

Thanks,
Mike

4 Replies

Well first of all “node” and “mesh” are reserved words in MaxScript. You should change those variables.

Second, it seems that gw methods only work inside of view port callbacks now. There’s an example at the top here: http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-1B088FF0-6A36-420E-9F37-F0DBE9FB2676.htm,topicNumber=d30e689013

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

they are reserved in global scope only. i like to use reserved words in local scope because the mxs editor nicely colors them for me

Yep, this is essentially Denis’s code, so the local scope is ok as he says.
What got me is that I’m using Max2011, so NO Nitrous is present and hence I don’t need to be inside of a callback.
ZoomToBounds doesn’t seem to work?


viewport.ZoomToBounds false selection.min selection.max

That works for me in Max 2011 and 2013. Maybe you can explain what you are trying to accomplish in your script.

Your script evaluates fine for me in 2011. But it looks like you are giving viewport.ZoomToBounds screen space coordinates when it’s expecting world coordinates. The results of your bmin and bmax are inconsistent, if you run the script a few times in a row. (Because the screen space is changing of course, but I don’t think that’s what you want when you are trying to zoom to a location.)


ZoomToObjBB()
121.0
16.0
513.0
384.0

ZoomToObjBB()
178.0
34.0
353.0
221.0

ZoomToObjBB()
-107.0
-250.0
323.0
270.0

ZoomToObjBB()
247.0
194.0
359.0
298.0

ZoomToObjBB()
-10297.0
-13559.0
36465.0
105049.0