How do I tell a script to ignore the number on the end of a material name

I have script which looks at material names and replaces them with a material in a specific material library if the names match. So the Standard material named Roof-Gray will be replaced with my vray material Roof-Gray, for example. But sometimes because of the import process I end up with a material named Roof-Gray1 which isn't recognized as a match.

How can I tell mascript to ignore the number at the end when checking for a match?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

try this

This will solve your problem

fn replace_MEdit_with_MLib_Mtls strpath: = if strpath != unsupplied do
(
	if loadMaterialLibrary strpath do
	(
		local MLibMtls = for m in currentMaterialLibrary collect m.name
		for m in 1 to meditMaterials.count do
		(
			for n in 1 to MLibMtls.count where matchPattern meditMaterials[m].name pattern:(MLibMtls[n]+"*") do
			(
				meditMaterials[m] = currentMaterialLibrary[MLibMtls[n]]
			)
		) ; free MLibMtls
	)
)
-- example
replace_MEdit_with_MLib_Mtls strpath:@"c:\MyLib\VRayMtls.mat"

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.