ScriptSpot

Forum topic · General Scripting

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

By brodie · 2013-05-31

Description

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 (1)

try this

barigazy · 2013-05-31

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"