Digital Art Zone

 
     
DAZ Script: Get the path to a mapped Poser runtime or DAZ Content folder? SOLVED
Posted: 27 February 2013 04:57 AM   [ Ignore ]
Active Member
Avatar
RankRank
Total Posts:  456
Joined  2007-09-01

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.
<user-selected-DS-content-directory>\Scripts\3DCheapskate\WorldBall\WorldBallData.txt
Path is just one of the mapped DS Content directories, see Richard’s answers below.


TIA,
Pete

 Signature 

Website: UnrealImperfect | Freebies: Renderosity, ShareCG | ‘Art’: DeviantArt | Blog: Blogger
(aka Pete Williams)

Profile
 
 
Posted: 27 February 2013 06:25 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14008
Joined  2003-10-09

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).

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 27 February 2013 11:44 PM   [ Ignore ]   [ # 2 ]
Active Member
Avatar
RankRank
Total Posts:  456
Joined  2007-09-01

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?

 Signature 

Website: UnrealImperfect | Freebies: Renderosity, ShareCG | ‘Art’: DeviantArt | Blog: Blogger
(aka Pete Williams)

Profile
 
 
Posted: 28 February 2013 08:10 AM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14008
Joined  2003-10-09

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.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 28 February 2013 10:19 AM   [ Ignore ]   [ # 4 ]
Active Member
Avatar
RankRank
Total Posts:  456
Joined  2007-09-01

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.

 Signature 

Website: UnrealImperfect | Freebies: Renderosity, ShareCG | ‘Art’: DeviantArt | Blog: Blogger
(aka Pete Williams)

Profile