Scripted Utility Disappearing

Scripted Utility Disappearing

Anonymous
Not applicable
717 Views
4 Replies
Message 1 of 5

Scripted Utility Disappearing

Anonymous
Not applicable

Hello,

 

I created a Scripted Utility as a UI for some other scripts. The utility creates and saves some custom attributes in the max file to be used as global variables. (Simply declaring and using global variables in the utility did nothing. I had to use custom attributes.) 

 

To run my custom utility, I do this:

 

Utility Tab > Maxscript Button > Utilities Pulldown > select my scripted utility

 

The first time I do this, it works as expected. However, if I navigate to another tab, like the Modify Tab, then go back to the Utility Tab, my custom utility isn't there. It doesn't show up in the Utilities pulldown. If I try to manually run the utiltiy or drag-and-drop the maxscript into a Max window, I get an Unknown System Exception error. 

 

Below is what shows up in the Listener. 

 

-- Error occurred during fileIn in <File:C:\Program Files\Autodesk\3ds Max 2011\scripts\startup\pko.ms>
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2011\scripts\startup\pko.ms; position: 3637; line: 121
>> MAXScript FileIn Exception: -- Unknown system exception <<

I can't figure out why this is happening. It does the same thing with other custom utilties, not just this particular one. 

 

I will post an example of the code in a follow up post. 

0 Likes
718 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
macroScript pko category:"Tools"
(
	(
		myAttrib = attributes CAMyCustAttrib
		(
			parameters main
			(
				timeRange type:#string default:"clipboard" animatable:false
				startFrame type:#float default: 0 animatable:false
				endFrame type:#float default: 0 animatable:false
				timeOffset type:#float default: 0 animatable:false
				valueOffset type:#float default: 0 animatable:false
				copies type:#integer default: 0 animatable:false
				connectCurves type:#boolean default:false animatable:false
				Setup_pivot type:#string default:"left"
			)
		)
		custAttributes.add rootNode myAttrib
	)

utility pko "Options"
( 
	rollout pkoSettings "Options"
	(
		group "Time Range"
		(
		)
		
		group "Offsets"
		(
		)	
		
		group "Connect"
		(
		)
		
		group "Align"
		(	
		)	
	) --end rollout
	
	on pko open do
	(
		(
			myAttrib = attributes CAMyCustAttrib
			(
				parameters main
				(
					timeRange type:#string default:"clipboard" animatable:false
					startFrame type:#float default: 0 animatable:false
					endFrame type:#float default: 0 animatable:false
					timeOffset type:#float default: 0 animatable:false
					valueOffset type:#float default: 0 animatable:false
					copies type:#integer default: 0 animatable:false
					connectCurves type:#boolean default:false animatable:false
					Setup_pivot type:#string default:"left"
				)
			)
			custAttributes.add rootNode myAttrib
		)
		addRollout pkoSettings
	) -- end on open
	
on pko close do
	(
		removeRollout pkoSettings
	) -- end on close
) --end utility
)--end macroscript

 Here's a stripped down version of my utility. On further testing, my original utility and this stripped down version work fine when I open an empty new max scene. But when I open a file with character rig, that's when it breaks. There could be something in the character rig that is conflicting with my utility. I'll have to ask our character TD. 

 

If anyone has experience with this, please let me know.

 

Thanks.

0 Likes
Message 3 of 5

Anonymous
Not applicable

I have been experimenting around with the order of the sections of code, in trying to give Maxscript "what it wants". I keep running into the same set of error messages.


Here's another simplified version of my code:

 

(
------------------------------Rollout----------------------------------------------
	rollout myRollout "Rollout"
	(
		group "Time Range"
		(
			radiobuttons timeRangeButton labels:#("Start","Start/End","Current", "Clipboard") default:4
			on timeRangeButton changed arg do
			(					
				rootNode.timeRange = case arg of
				(
					1: "start"
					2: "startEnd"
					3: "current"
					4:"clipboard"
				)
			)	
		)
	)

------------------------------Rollout Initialization---------------------------------------
	
	on execute do
	(
		addRollout myRollout
		
		if custAttributes.count rootNode == 0 then 
		(
			myAttrib = attributes CAMyCustAttrib
			(
				parameters main 
				(
					timeRange type:#string default:"clipboard" animatable:false
				)
			)
			custAttributes.add rootNode myAttrib
		)
		
		else if custAttributes.count rootNode != 0 then 
			for c in rootNode.custAttributes do
				if hasProperty c "timeRange" then 
					(
						mySelected = #("start", "startEnd", "current", "clipboard")
						myRollout.timeRangeButton.state = findItem mySelected rootNode.timeRange
					)
	) 
----------------------------------Macroscript Definition--------------------------------	
macroScript simpleRolloutTest category:"Tools"
(
	CreateDialog myRollout 200 330
)
)

 If I drag this macroscript into a toolbar button and press it, I get this error message:

"createDialog requires rollout class. Got Undefined."

 

If I open the script in the editor and evaluate it (ctrl + E), I get a "system exception" the first time, and then the second time my rollout appears in the Utility panel, not as a floating dialogue like it should.

 

If I comment out the "macroScript simpleRolloutTest category:"Tools"" line the floating dialog works, ONLY when I manually (ctrl + E) evaluate it from the maxscript editor.

 

The varied ways that it works or doesn't work is quite confusing.

 

 

0 Likes
Message 4 of 5

Swordslayer
Advisor
Advisor

Well, that's beacuse you are mixing different concepts together. There are several issues here, the on execute handler has to be in the macroscript definition - but most probably you wanted to use the rollout open handler; dragging a piece of code to a toolbar encloses the code in a new macroscript, as such it would only evaluate your existing macroscript and won't run it; when you checked if count == 0, you don't need to check if count != 0 in the else branch; the addRollout function adds the rollout in the utility tab, you don't need that here; whenever you see for x in y do if z do, you can replace it with for x in y where z do:

 

macroScript simpleRolloutTest category:"Tools"
(
------------------------------Rollout----------------------------------------------
	rollout myRollout "Rollout"
	(
		group "Time Range"
		(
			radiobuttons timeRangeButton labels:#("Start","Start/End","Current", "Clipboard") default:4
			on timeRangeButton changed arg do
			(			
				rootNode.timeRange = case arg of
				(
					1: "start"
					2: "startEnd"
					3: "current"
					4: "clipboard"
				)
			)	
		)

		on myRollout open do
		(
			if custAttributes.count rootNode == 0 then 
			(
				local myAttrib = attributes CAMyCustAttrib
				(
					parameters main 
					(
						timeRange type:#string default:"clipboard" animatable:false
					)
				)
				custAttributes.add rootNode myAttrib
			)
			else for c in rootNode.custAttributes where
				isProperty c #timeRange do 
				(
					local mySelected = #("start", "startEnd", "current", "clipboard")
					myRollout.timeRangeButton.state = findItem mySelected rootNode.timeRange
				)
		)
	)

------------------------------Rollout Initialization---------------------------------------
	on execute do
	(
		createDialog myRollout 200 330
	) 

)

 After running it you can finally assign the macroscript to a button on a toolbar.

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks for the tips. That improved my code. I had to take a couple more steps to get it to work. Once I get a free moment to tidy it up I'll repost in case anyone else is making the same mistakes I was. 

0 Likes