[SOLVED] File-Path of a Script
dyodyo
Posts: 42
This has probably been answered hundreds of times, but I can't seem to find the answer:
Is there a built-in Daz function that will tell me exactly where my script is located, file-path-wise (absolute or relative path); it could be where it's supposed to be in the Daz folder system, or on a networked-drive, or anywhere.
I've seen quite a few functions in the DzApp object (I think), but searching through the object reference docs doesn't seem to turn up anything (could be totally wrong, of course).
Thanks,
Post edited by dyodyo on
Comments
There's a global DzScriptContext, http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/scriptcontext_dz , so you can just use name = getScriptFileName(); which you could either parse or use to create a DzFileInfo from which you could obtain the path.
Something that tripped me up when I was figuring it out was that the script has to be a saved file on disk. It can't be an ad-hoc script in the Script editor, otherwise errors will occur.
Very obvious in retrospect, but I remember being frustrated for a little bit.
Thanks Richard!
This is what I came up with:
@djigneo: yep, that got me as well for a while ;)
Instead of doing the substring thing, I would suggest:
var sPath = new DzFileInfo(getScriptFileName()).path();
Yeah, the substring thing is a little bit hacky and could lead to issues -- using native objects is a much safer / faster. Thanks for the hint :)