ZBrushCentral

How to get the name of an FBX file in a ZScript?

Hi!

I’m trying to get the name of an FBX file in a script, but I am having some issues.

In the script below, I have one button to import, one button to display the file name in a note. For some reason, when I press the button to display the note, if the file is an OBJ, I see the file name. If the file is an FBX, I do not see the file name.

How do I get the file name of an FBX?

Thanks in advance!

[VarDef, importFile, ""] // define the variable to hold the file name
[ISubPalette,"ZPlugin:MyScript"] // make subpalette
[IButton, "ZPlugin:MyScript:Import File", "Import File", // make button
	//[VarSet, importFile, [ FileNameAsk, "OBJ(*.obj)|*.obj||", , "Select OBJ..."]] // ask for file
	[VarSet, importFile, [ FileNameAsk, "FBX(*.fbx)|*.fbx||", , "Select FBX..."]] // ask for file
	[FileNameSetNext, importFile] // set next file
	[IPress, Tool:Import] // import
,,1]//end button

[IButton,"ZPlugin:MyScript:Print Screen","Print Screen", // print the file name to screen
	[Note, [StrMerge, "File Name: ", importFile]] // show note with the file name
,,1]//end button

Hi!
So in that case you are using [VarDef], so the variable is declared and assigned at the plugin Startup.
So for example if you press your first button, pick up a FBX file, then it loose focus on your plugin when it import the FBX file, but not when importing the OBJ fil.

So if you get back to your second button and press it:

if it’s an OBJ file then your script has never shutdown, so the variable will be valid.
If it’s a FBX file, as your plugin shutdown when the FBX file is imported. when you press the second button the plugin startup and assign the variable but is empty.

so you need to use a memory block using [MemCreate] to store your string use [MemWriteString] .
If you need some help tell me i could post a Script to demo it.

Hope it Helps,
Nicolas

Thanks Nicolas @facelessmindz . This is good to know! I didn’t realise that the variables would be cleared if we lose focus on the plugin. I will give memory blocks a try.