Adding Scripted modifier

Adding Scripted modifier

ztravnicky
Enthusiast Enthusiast
1,113 Views
6 Replies
Message 1 of 7

Adding Scripted modifier

ztravnicky
Enthusiast
Enthusiast

Having this script in scripts/startup (script.ms file)

 

plugin modifier modifier_B
name:"B"
classID:(genClassID returnValue:true)
(
	rollout b "TestB"(
		button btnB "ADD A"
		
		fn addA obj = (
			addmodifier obj (modifier_A())
		)
		
		on btnB pressed do (
			for o in objects do (
				addA o 
			)
		)
	)
)

plugin modifier modifier_A
name:"A"
classID:(genClassID returnValue:true)
(
	rollout ra "TestA"(
		button btnA "OK"
		
		on btnA pressed do (
			print "Modifier A"
		)
	)
)

 

When hitting buton "TestB" is causing an error (undefined modifier), even the modifiers should be global! Changing the order will fix this error. Why is this happening? Is it BUG with the chance to be fixed soon? It behaves the same way in all version of MAX.

 

0 Likes
1,114 Views
6 Replies
Replies (6)
Message 2 of 7

Steve_Curley
Mentor
Mentor
Modifier_A is undefined as far as modifier_B is concerned, or rather it's not defined within the rollout code. You need a "forward reference".
See http://help.autodesk.com/view/3DSMAX/2015/ENU/?guid=__files_GUID_608825CD_D025_4054_91E2_2562A6AB31C...

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 7

ztravnicky
Enthusiast
Enthusiast

I'm sorry, but this code is not giving success... Am I missing something?

 

plugin modifier modifier_B
name:"B"
classID:(genClassID returnValue:true)
(
	local modifier_A
	
	rollout b "TestB"(		
		button btnB "ADD A"
		
		fn addA obj = (
			addmodifier obj (modifier_A())
		)
		
		on btnB pressed do (
			for o in objects do (
				addA o 
			)
		)
	)
)

plugin modifier modifier_A
name:"A"
classID:(genClassID returnValue:true)
(
	rollout ra "TestA"(
		button btnA "OK"
		
		on btnA pressed do (
			print "Modifier A"
		)
	)
)

 

0 Likes
Message 4 of 7

Steve_Curley
Mentor
Mentor
Try putting it inside the rollout, after the rollout b "TestB"( line.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 7

ztravnicky
Enthusiast
Enthusiast

I already did...

Did you try and it worked for you?

0 Likes
Message 6 of 7

Steve_Curley
Mentor
Mentor
Nope, because I've not played with that kind of scripting before, but almost every error of that kind is pretty much always down to not following the info on the linked page exactly. Almost guaranteed - and there's rollout code in your example...

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 7 of 7

Steve_Curley
Mentor
Mentor
Ok, took a while to understand what's going on here.
The "forward declaration" does need to be inside the rollout code, but because both modifiers are being created globally the declaration has to be "global" not "local".

Also, I think you should change both of the classID statements to be actual class IDs not random ones. Having them random will cause errors if you execute the script twice because you'll get "Runtime error: Plugin redefinition: Cannot change ClassID".

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes