DAZ Script: Get the path to a mapped Poser runtime or DAZ Content folder? SOLVED

I've got a simple data file (basic CSV format) that needs to be included in a few freebies I'm working on. Various scripts (both PoserPython and DAZ Script) need read-only access to the file.

The script is currently in Poser's default /Runtime/Python/Poserscripts/... folder (by default I mean the same place as the poser.exe file - couldn't see how to pick up other mapped runtimes using PoserPython).

the PoserScript version's working fine. So's the DAZ script version, but I've currently got the full path to the data file hard-coded. So two questions:

1) How do I access a mapped Poser runtime from DAZ script?
Answer: see Richard's posts below

2) For users who only have DAZ Studio, and who don't map Poser runtimes, where would be the best place to put the datafile, and how would I pick up the path?
Answer: I decided to put the datafile in the Scripts folder of whatever DAZ Content directory the user selects. E.g.
\Scripts\3DCheapskate\WorldBall\WorldBallData.txt
Path is just one of the mapped DS Content directories, see Richard's answers below.


TIA,
Pete

Post edited by 3dcheapskate on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,905
    edited December 1969

    var relPath = App.getContentMgr().getRelativePath( absolutePath , useImportFolders );

    will return the relative path, within a content directory, to the file - you want the second input to be true for non-native files.

    var basePath = App.getContentMgr().findBaseDirectory( absolutePath , useImportFolders );

    will return the content directory holding the file, so basePath + relPath should be the full absolute path. You can also use

    var absPath = App.getContentMgr().getAbsolutePath( relativePath , useImportFolders );

    to go from a stored relative path to the absolute path on the local machine (assuming the file is in a mapped content directory, of course).

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited February 2013

    Thanks Richard, DzContentMgr is the one I'm after. Sometimes I just can't find what I'm after in the DAZ Script 2 Class Index even though I know it must be there.

    Next step, I need to ensure that my full pathname, i.e. something like this (which works on PC)...

    path = App.getContentMgr().getPoserDirectoryPath(i) + "/Runtime/Python/poserScripts/3DCheapskate/SmartPlusData.txt";

    ...is OS independent. Forward slashes should work on a MAC too, so the above should be okay. Correct?

    Post edited by 3dcheapskate on
  • Richard HaseltineRichard Haseltine Posts: 100,905
    edited December 1969

    Yes, forward slashes are used for all paths in DAZ Script as far as I know - certainly all presets, which are cross-platform, use them.

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited June 2013

    Thanks again. Next query over on the DazScript import external script file? thread, cos it fits neatly there!

    P.S. My PoserPython script simply checks whether the path/file exists in each of the mapped Poser runtimes.
    My DAZ Script checks whether the path/file exists in each of the mapped Poser runtimes AND each of the mapped DS content directories.
    Both scripts use the first matching file that they find. If more than one match the user is warned that there are duplicates and told exactly where they are.

    Post edited by 3dcheapskate on
Sign In or Register to comment.