ZBrushCentral

Question: How to use zScript to load an obj from a file path

Hello,

I’m attempting to write a script which uploads an obj from a specific file path. I created a separate .zvr for the file path, in the event it needs to be changed in the future. The script seems to load without any issues. but when ran, nothing seems to happen. Is the script below the proper way to do this?

//Loads variable .zvr containing the address. RetopoFolderLoc.zvr simply contains address (SC:\Users\xxx\Documents\Retopo Repository ) and the Retopo Repository folder contains test.obj.

[VarLoad,RetopoFolderLoc,“RetopoFolderLoc.zvr”]

//Makes ready an obj to load upon IPress Import
[FileNameSetNext, test.obj]

//Loads in obj
[IPress, Tool:Import]

Thanks for the Help,
Log

Welcome to ZBC! :slight_smile:

You’ll need to make sure the whole path to the file is used, so something like this:

[FileNameSetNext,[StrMerge,  RetopoFolderLoc, "\test.obj"]]
//Loads in obj
[IPress, Tool:Import]

The [VarLoad] command simply reads a variable from a file, it doesn’t do anything with it.

HTH,
Marcus

1 Like

Thanks! So I can simply use the RetopoFolderLoc as a parameter without needing to load it in using the VarLoad function?

Also after making some adjustments, I got something like this:

//Routine Def to wrap in IPress command

[RoutineDef, LoadRoutine,

//Loads variable containing location string, comment out to test without it.

//[VarLoad,RetopoFolderLoc,"RetopoFolderLoc.zvr",[Note, Success Loading .zvr File,,2]]

    //Makes ready file using the provided location

    [FileNameSetNext,[StrMerge,  RetopoFolderLoc, "\test.obj"], [Note, Success Setting Next File,,2]]

        //Executes button press

        [IPress, Tool:Import, [Note, Success Loading obj,,2]]

]

However I get the same result. I actually got a “success” test message once, but didn’t get it again, even after loading in a different script and reloading this one.

Be sure to delete any .zsc file that was created from your text file or nothing will change…

1 Like

I just gave a code snippet. Your “RetopoFolderLoc” variable needs to have a value assigned, i.e. the folder path, otherwise ZBrush won’t know what it represents.

Also, you can’t just add stuff like your notes inside commands, you need to respect the number of arguments specified in the command reference.

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/

Marcus

Sorry I misunderstood. I thought the snippet you provided assumed the variable I created contained the rest of the file path, thus the reason for the string merge.

So would something like this be correct?

[FileNameSetNext,[StrMerge, RetopoFolderLoc, “C:\Users\xxx\Documents\Retopo Repository\test.obj”]]

Also the snippet I provided had a misplaced double slash I was using for testing (this guy → //[VarLoad,RetopoFolderLoc,“RetopoFolderLoc.zvr”,[Note, Success Loading .zvr File,2]]) So disregard that .

The notes was my attempt to add some sort of visual validation that that line executed properly. I’ll re-read how to do that correctly.

Thanks again for the help

Ah, I was forgetting to do this, thank you!

To avoid further misunderstanding :slight_smile: here’s a working script:

[VarDef,RetopoFolderLoc,""]//declare this variable


[IButton,"Import OBJ File","Import an OBJ file from disk",
	[If,[FileExists,"RetopoFolderLoc.zvr"],//OK we have our path file
		[VarLoad,RetopoFolderLoc,"RetopoFolderLoc.zvr"]
		[VarSet,fileName,[StrMerge,RetopoFolderLoc,"test.obj"]]
	,//else no file path stored so select a file
		[VarSet,fileName,[FileNameAsk,"OBJ(*.obj)|*.OBJ||", ,"Please Select File..."]]
		[If,[StrLength,fileName],//if the user didn't cancel
			[VarSet,RetopoFolderLoc,[FileNameExtract,fileName,1]]//get the path so we can save it
			[VarSave,RetopoFolderLoc,"RetopoFolderLoc.zvr"]//save the path variable
			,//else
			[Exit]//no file selected so exit zscript
		]
	]
	[If,[FileExists,fileName],
		//OK we have a file
		[Note,"File exists so we can attempt to import"]
		,//else no file
		[Note,"File does not exist"]
		[Exit]
	]
	[FileNameSetNext,fileName]
	[If,[FileNameHasNext],
		//OK we have set the next file
		[Note,"Next File has been set OK"]
		,//else some sort of error
		[Note,"Error - file has not been set"]
		[Exit]
	]
	[IPress,Tool:Import]
]

HTH,
Marcus