ZBrushCentral

Retrieve full path to current material and load it

Hi guys, how’re you doing?

I’m trying to write a simple line which allows me to load the material currently in use.
I guess something is wrong with my code.

[FileNameSetNext, [FileNameExtract, [IGetTitle,Material:Current Material], 7]
[IPress,Material:Load]

Any clue?
Thanks a lot!

Hey guys I tried other approaches but still I can’t get it to work. Today I tried this with no luck:

[VarDef,materialPath,""]
[VarSet,materialPath,[FileNameResolvePath, [StrMerge,[IGetTitle,Material:Current Material], .ZMT] ]
[FileNameSetNext, [Var,matPath]][IPress,Material:Load]

IGetTitle doesn’t return a file name or path for the Material palette, only the button path. You can’t get the material file location using zscript.

Hey Marcus thanks for the reply. Do you think is there any other way I can re-load or default the currently used material through Zscript?

It depends a bit on what you are trying to do. Could you explain why you want to reload a material that’s already loaded?

Yes, it’s for a little script I’m writing.

Sometimes you end up modifying a material by playing with lightcaps or tweaking the material modifiers, etc. So loading back the active material it’s the quickest way I was thinking to reset it to its default values.

Well, there are some regular folders that you could search easily enough. Then if you didn’t find the material there you could inform the user and get them to select the material from disk (you could use FileNameAsk for that). The code below shows you the idea. Note that LightCaps are a bit more tricky though…

[VarDef,gStartupFolder,“ZBRUSH_ZDATA/Materials/Startup/”]
[VarDef,gMatcapFolder,“ZBRUSH_ZDATA/Materials/MatCap/”]
[VarDef,gUserFolder,“ZBRUSH_ZSTARTUP/Materials/”]
[VarDef,gLightboxFolder,“ZBRUSH_ZMATERIALS/”]

[IButton,“Reset mat”,“Reset the current material”,
[VarSet,lCurrentMat,[StrMerge,[IGetTitle,Material:Current Material],".zmt"]]
[VarSet,loadOK,0]
[Loop,1,

[VarSet,mat,[StrMerge,gStartupFolder,lCurrentMat]]

[If,[FileExists,mat],[VarSet,loadOK,1][LoopExit]]

[VarSet,mat,[StrMerge,gMatcapFolder,lCurrentMat]]

[If,[FileExists,mat],[VarSet,loadOK,1][LoopExit]]

[VarSet,mat,[StrMerge,gUserFolder,lCurrentMat]]

[If,[FileExists,mat],[VarSet,loadOK,1][LoopExit]]

[VarSet,mat,[StrMerge,gLightboxFolder,lCurrentMat]]

[If,[FileExists,mat],[VarSet,loadOK,1][LoopExit]]

]
[If,loadOK,

[FileNameSetNext,mat]

[IPress,Material:Load]

,//else not found

[Note,“Material not found. Please load file from disk”]

]
,1]

Marcus you’ve been tremendously helpful and that’s really clever.

I’d like to include your lines in a script I’m about to post for free on the forums. I’d obviously give you the necessary credits.
Would you authorize me to do that?

Yes, of course. It’s kind of you to ask. For anyone reading this, they are free to use any code I post.

Thanks Marcus,
this is the link to the plugin http://www.zbrushcentral.com/showthread.php?199697-Easy-Default-Lights-v1-0&p=1174708

it’s very simple but hopefully handy