[3ds max][mxs]old script not working with newer version of max

Hi everyone, I’ve started working with max again lately. And wanted to use a collection of my old scripts again. But a particular script isn’t working with the newer version of max. I can’t figure out whats wrong with it. Here is the code with the faulty bit commented out:

global myGrid = undefined

fn _alignViewToFace obj orthoView:True =
(
	if obj != undefined and classOf obj == Editable_Poly then
	(
		selectedFaces = (getfaceselection obj) as array
		if selectedFaces.count == 1 then
		(
			local myCam = ::createCamera()
			print obj
			myCam.dir = (polyOp.getFaceNormal obj selectedFaces[1])
			viewport.setCamera myCam
			completeRedraw()
			delete myCam
			max zoomext sel
			if orthoView == True then
			(
				viewport.setType #view_iso_user
			)
		)
		else
		(
			messageBox  "Needs 1 Face"
		)
	)
	else
	(
		messageBox "Need Editable Poly"
	)
)

fn _deleteGridIfItExists =
(
	if myGrid != undefined then
	(
		if isDeleted myGrid == False then
		(
			delete myGrid
		)
	)
)

/* BELOW DOES NOT WORK */

/*
fn _getRotationArray axis =
(	
	local rotArray = #(0, 0, 0)
	case axis of
	(
		"x": 
		(
	 * * * *rotArray[1] = 0
	 * * * *rotArray[2] = 90
	 * * * *rotArray[3] = 0
	 * *)
	 * *"-x": *
		(
	 * * * *rotArray[1] = 0
	 * * * *rotArray[2] = -90
	 * * * *rotArray[3] = 0
	 * *)
	 * *"y": *
		(
	 * * * *rotArray[1] = -90
	 * * * *rotArray[2] = 0
	 * * * *rotArray[3] = 180
	 * *)
	 * *"-y": *
		(
	 * * * *rotArray[1] = 90
	 * * * *rotArray[2] = 0
	 * * * *rotArray[3] = 0
	 * *)
	 * *"z": *
		(
	 * * * *rotArray[1] = 0
	 * * * *rotArray[2] = 0
	 * * * *rotArray[3] = 0
	 * *)
	 * *"-z": *
		(
	 * * * *rotArray[1] = 0
	 * * * *rotArray[2] = 180
	 * * * *rotArray[3] = 0
		)
		default:
		(
			messageBox "getRotationArray = Default!"
		)
	)
	rotArray
)
*/
	
fn _alignViewportToGeometry obj alignTo:"z" gridOn:True gridSize:1000 gridSquare:50 orthoView:True =
(
	local myCam = ::createCamera()
	local rotArray = _getRotationArray alignTo	
	::align myCam obj rotX:rotArray[1] rotY:rotArray[2] rotZ:rotArray[3]
	viewport.setCamera myCam
	completeRedraw()
	delete myCam
	max zoomExt sel
	if orthoView == True then
	(
		viewport.setType #view_iso_user
	)
	if gridOn == True then
	(
		::myGrid = ::createGrid lengthValue:gridSize widthValue:gridSize gridValue:gridSquare
		::align myGrid obj rotX:rotArray[1] rotY:rotArray[2] rotZ:rotArray[3] offsetZ:-1000
		select myGrid
		max activate grid object
		select obj
	)
)

The error message:

– Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2014\scripts echniArt echniArt-alignViewToMesh.ms; position: 980; line: 58
– Syntax error: at string, expected :
– In line: * *"-x":

Thank you for your time and help.

What are all those asterisks doing there?

This works for me:


global myGrid = undefined

fn _alignViewToFace obj orthoView:True =
(
	if obj != undefined and classOf obj == Editable_Poly then
	(
		selectedFaces = (getfaceselection obj) as array
		if selectedFaces.count == 1 then
		(
			local myCam = ::createCamera()
			print obj
			myCam.dir = (polyOp.getFaceNormal obj selectedFaces[1])
			viewport.setCamera myCam
			completeRedraw()
			delete myCam
			max zoomext sel
			if orthoView == True then
			(
				viewport.setType #view_iso_user
			)
		)
		else
		(
			messageBox  "Needs 1 Face"
		)
	)
	else
	(
		messageBox "Need Editable Poly"
	)
)

fn _deleteGridIfItExists =
(
	if myGrid != undefined then
	(
		if isDeleted myGrid == False then
		(
			delete myGrid
		)
	)
)

fn _getRotationArray axis =
(	
	local rotArray = #(0, 0, 0)
	case axis of
	(
		"x": 
		(
			 rotArray[1] = 0
			 rotArray[2] = 90
			 rotArray[3] = 0
		 )
	 "-x": 
		(
			 rotArray[1] = 0
			 rotArray[2] = -90
			 rotArray[3] = 0
		 )
	 "y":
		(
			 rotArray[1] = -90
			 rotArray[2] = 0
			 rotArray[3] = 180
		)
	 "-y":
		(
			 rotArray[1] = 90
			 rotArray[2] = 0
			 rotArray[3] = 0
		)
	 "z":
		(
			 rotArray[1] = 0
			 rotArray[2] = 0
			 rotArray[3] = 0
		)
	 "-z":
		(
			 rotArray[1] = 0
			 rotArray[2] = 180
			 rotArray[3] = 0
		)
		default:
		(
			messageBox "getRotationArray = Default!"
		)
	)
	rotArray
)

	
fn _alignViewportToGeometry obj alignTo:"z" gridOn:True gridSize:1000 gridSquare:50 orthoView:True =
(
	local myCam = ::createCamera()
	local rotArray = _getRotationArray alignTo	
	::align myCam obj rotX:rotArray[1] rotY:rotArray[2] rotZ:rotArray[3]
	viewport.setCamera myCam
	completeRedraw()
	delete myCam
	max zoomExt sel
	if orthoView == True then
	(
		viewport.setType #view_iso_user
	)
	if gridOn == True then
	(
		::myGrid = ::createGrid lengthValue:gridSize widthValue:gridSize gridValue:gridSquare
		::align myGrid obj rotX:rotArray[1] rotY:rotArray[2] rotZ:rotArray[3] offsetZ:-1000
		select myGrid
		max activate grid object
		select obj
	)
)

Those asterisk shouldn’t be there, something must have happened when I edited the post!
Thank you sir, whatever you did it works now! Five stars from me.

Thanks. Glad I could help hehe :slight_smile:

Take care,
Artur