A macroscript that references PBR materials wrote only works if I evaluate it myself

A macroscript that references PBR materials wrote only works if I evaluate it myself

michael_grosberg
Advocate Advocate
342 Views
1 Reply
Message 1 of 2

A macroscript that references PBR materials wrote only works if I evaluate it myself

michael_grosberg
Advocate
Advocate

I wrote a macroscript that changes the UV channels on materials of selected objects. It only works on physical and PBR materials, and only bitmap textures. It's a pretty simple script. My problem is, when I start up 3ds max, this script doesn't work on objects with PBR materials. To get it to work if I have to open the script in the editor and press CTRL+E.

 

I pinpointed the problem to a single line. As far as I can tell, this conditional statement gets interpreted as false first, then as true after manual evaluation:

     if (classof CCmat == PBRMetalRough) then (...)

a similar condition for Physical materials works just fine "out of the box".

 

I have a test file plus the script attached.

 

0 Likes
343 Views
1 Reply
Reply (1)
Message 2 of 2

Swordslayer
Advisor
Advisor

If I understand the purpose of the script right, you want to change map channel for all the BitmapTextures (and nothing else) used in materials of selected objects? If so, this might be easier:

 

macroScript ChangeChannels
category:"AAA" 
tooltip:"ChangeChannels" 
ButtonText:"ChangeChannels"
icon:#("MergeAnim",4)
(
	mapped fn changeBitmapChannels obj channel =
		for map in getClassInstances BitmapTexture target:obj do
			map.coords.mapChannel = channel

	rollout ChangeChannelsUI "Multitool" width:200 height:100
	(
		button btnChangeChan "Change" width:60 height:24 across:2 tooltip:"change materials on selected objects to using a different map channel"
		spinner spnChangeChan "Channel:" width:80 height:20 type:#integer range:[1,99,2]
		
		on btnChangeChan pressed do
			changeBitmapChannels selection spnChangeChan.value
	)

	on execute do if not ChangeChannelsUI.open do 
		createDialog ChangeChannelsUI 200 100 900 300
)
0 Likes