Notifications
Clear all

[Closed] Automatic material type conversion

I don’t have max2009 design so I can’t test it with these new materials, but something like this might work:

(
	-- Replace 'Architectural' with whichever class you want to convert
	local ArchMats = getClassInstances Architectural
	
	-- Locals
	local StandardMat, Props, Prop
	
	-- Iterate through all material instances
	for ArchMat in ArchMats do
	(
		-- Create a standard material
		StandardMat = standardMaterial name:(ArchMat.name + "_Converted")
		
		-- Collect property names of the original material
		Props = getPropNames ArchMat
		
		-- Iterate through property names
		for Prop in Props where isProperty StandardMat Prop do
		(
			try
			(
				-- Try to set the property on the standard material
				setProperty StandardMat Prop (getProperty ArchMat Prop)
			)
			catch
			(
				format "Cannot set property % : \"%\".
" Prop (getCurrentException())
			)
		)
		
		-- Replace the original material with the new standard material
		replaceInstances ArchMat StandardMat
	)
)

I just wrote this real quick, it doesn’t check anything but simply tries to transfer all properties from the old to the new material. So make sure you save/hold your scene before running the script.

Anyway, replace Architectural (at the first line of the script) with any of the material classes you have and see what it does.

Cheers,
Martijn

Hmm. I get “Type error: getClassInstances requires MAXClass, got: undefined” when I replace Architectural with Simple_Mtl_Hardwood_adsk, so perhaps that’s not the correct class. Is there another way of finding the class than “classof $.material” as was suggested below?

It’s actually not Arch & Design (mi) as I’d thought it was using. The materials all seem to be various ProMaterials, in this case “ProMaterials: Hardwood”. There are separate ProMaterial types for glass, wall paint, masonry, plastic, etc. But I have no clue why getClassInstances isn’t liking the class that classof gives me for the hardwood.

1 Reply
(@magicm)
Joined: 11 months ago

Posts: 0

When you execute the following line in the Listener, you should get a list of all the available material classes you have. So the ones you want to change should be in there too:

for m in material.classes do print m

Also, try executing superClassOf $.material (with an object containing the arch material selected). This should return material.

I have no idea why classOf $.material would return an invalid class name (evaluating to undefined). As far as I know that’s impossible [EDIT]Unless of course, as Richard stated, the class name has a typo [/Edit]

I do know a similar problem arises when working with the bitmap class, but I suspect this is simply because the word “bitmap” could actually mean three different things in mxs, namely an actual bitmap value, a rollout control and a class:

b = bitmap 10 10
BitMap:
c = classOf b
BitMap
getClassInstances c
-- Type error: getClassInstances requires MAXClass, got: BitMap

Martijn

Is that -exactly- as used?

The reason I ask is because the class has -two- underscores before ‘adsk’:


Simple_Mtl_Hardwood_adsk -- incorrect
Simple_Mtl_Hardwood__adsk -- correct


getClassInstances Simple_Mtl_Hardwood__adsk -- should work just fine

Good catch, ZeBoxx! I’m dumb.

New errors now:

Cannot set property #diffuse_color : "-- Unable to convert: Wood-100_hardwood_color:Simple Image Map (Bitmap) (adsk) to type: Point3".
  Cannot set property #diffuse_color : "-- Unable to convert: Wood-095_hardwood_color:Simple Image Map (Bitmap) (adsk) to type: Point3".
  Cannot set property #diffuse_color : "-- Unable to convert: Wood-096_hardwood_color:Simple Image Map (Bitmap) (adsk) to type: Point3".
  Cannot set property #diffuse_color : "-- Unable to convert: Wood-095_hardwood_color:Simple Image Map (Bitmap) (adsk) to type: Point3".
  OK

EDIT: I’m guessing that the Wood-095, Wood-096, and Wood-100 refer to the three different woods used for the countertop, door, and table, but I could be wrong.

1 Reply
(@magicm)
Joined: 11 months ago

Posts: 0

Like I said, my script doesn’t do any intelligent conversion, it’s just a crude attempt at transferring properties from one material type to the other. I don’t have 2009/design so I’m afraid I can’t be of much help.

Martijn

Page 2 / 2