Notifications
Clear all

[Closed] Force file path, even on error?

Ok im trying to get the material path of a material. The material does not exist anymore.

My script is going to change the extension on the material so that it will be found.

The problem i have is collecting the path when the fileis missing, max just gives the following error…


Runtime error: Error opening bitmap: \\path\path\filename.dds 

Basically i want to get the path.

At the moment im using try and catch to get the error, is this the best way to go about getting the path, then editing it as a string?

3 Replies

I guess this is what you need (or something similar):

thePath = getFilenamePath mEditMaterials[1].maps[2].fileName
theFileName = getFilenameFile mEditMaterials[1].maps[2].fileName
theNewExt = ".jpg"
mEditMaterials[1].maps[2].fileName = thePath + theFileName + theNewExt

So this is what this piece of code does.

First it gets the path of the diffuse map (maps[2]) of the material in the slot #1 of the material editor and stores it in the “thePath” variable.

Then get the file name and stores it in the “theFileName” variable.

Finally, declares the new extension “theNewExt” and concatenates the three strings to build the new full file name, and assigns it to the diffuse map filename.

Hope you get the idea.

Using try/catch for this situation is the only way I’ve been able to trap it. Doing something like, if blah == undefined won’t stop mxs from bailing. You can do something like this:

try (
– get the path here
)
catch (
– If it failed
assert = getCurrentException();

– Probably parse the assert to get the file path and then replace it
)

ok cool