1. #1
    Senior Member Follow User Gallery
    Join Date
    Jan 2003
    Location
    NYC
    Posts
    1,626

    Question Question: controlling Subdirectory paths in ZScript

    OK. Here's something I have been trying to figure out, but am about ready to give up on.

    The FileNameAsk command permits the script to ask the user for a filename, either something to be saved or loaded, and it does it in the typical dialog window which shows the files that already exist. You either select one of the existing files or enter a new filename.

    Swell, very useful. It works great...

    Problem is, I can't see anyway the FileNameAsk command can be pointed along a specific subdirectory path. Depending on the context, it selects the subdirectory that the ZScript is in, or the ZScript2 directory.

    I would really like to create an exclusive subdirectory where the script will save and load data... and point FileNameAsk command to it.

    Has anybody uncovered the technique to be used here?

    Sven

  2. #2
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    Hi Sven,

    I think if you insert the line:
    [IUnPress,Preferences:Misc:Use ZFolders]
    before your FileNameAsk command then the Save As and Open file dialogues will open in the same directory as your ZScript resides, wherever that happens to be...

    HTH

    Mark

  3. #3
    Senior Member Follow User Gallery
    Join Date
    Jul 2002
    Location
    Copenhagen
    Age
    45
    Posts
    2,561

    Default

    Heya Sven,

    As with most things it is pretty easy once you know it.


    The commands you need are FileNameAsk, FileNameResolvePath , FileNameExtract and StrMerge.

    FileNameAsk is of course used to open the Dialog.

    FileNameResolvePath is used to calculate the pathname of the executing zscript.

    FileNameExtract is used to remove the filename from the FileNameResolvePath supplied pathname

    StrMerge is used to add or subtract subdirectories.

    So your code could look like the following:

    [FileNameAsk, .psd, // set .psd as the default filename extension for the open/save dialog
    [StrMerge
    ,[FileNameExtract, [FileNameResolvePath, ] , 1 ] // Extract the path only from the executing zscripts pathname
    , "..\" // Go back to the parent directory
    ] //End of StrMerge, returned string is used as save dialog starting directory.
    , "Save .PSD"
    ] // FileNameAsk dialog title, could be anything. End of FileNameAsk command.
    The above code would open the Dialog window in the executing zscripts parent directory. StrMerge'ing "..\..\" would start two directories up from the executing zscript. "Svengali\" would open in the ..... Svengali directory . As you can see the important thing to remember is to add a final \ to the pathname, if you do not the last part is treated as a filename.

    Assuming your script is placed in the Zplugs folder you would merge "..\..\Ztools\" to start in the Ztools directory.

    A final note, [FileNameResolvePath, local filename] without any parameters returns the executing zscripts pathname and filename, [FileNameExtract, full path of filename, returned component] seperates them according to the supplied parameter.

    Hope that does it for you.
    Last edited by TVeyes; 08-12-04 at 04:47 PM. Reason: Formatting text

  4. #4
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    Hello TVeyes,

    That's interesting and useful but won't it only work for 'Save As' though? - that bit of the code needs to be blank for the 'Open' dialogue.

    Mark

  5. #5
    Senior Member Follow User Gallery
    Join Date
    Jul 2002
    Location
    Copenhagen
    Age
    45
    Posts
    2,561

    Default

    No it also works for FileNameAsk. If the filename passed to FileNameAsk only consists of the pathname (ends with a \ ) it will leave the Dialog filename field blank but locate the pathname directory.



  6. #6
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    Yes, certainly the field is blank and the directory is located but the dialog is a SaveDialog not an OpenDialog. Using your code I can't get an OpenDialog. The only way I can get an OpenDialog is to have nothing between those two commas. As it says in the Commands List 'Name should be omitted for OpenDialog' and this appears to apply to paths too - or am I missing something?

  7. #7
    Senior Member Follow User Gallery
    Join Date
    Jul 2002
    Location
    Copenhagen
    Age
    45
    Posts
    2,561

    Default

    Sorry, I misunderstood you.
    You are correct, it shows up as a save dialog. I had not thought about it since I only wanted to save when using FileNameAsk. Not sure how to get around it. Did some quick tests and I cannot make it a Open Dialog.

    Maybe time to use the FileExecute command to run GetOpenFileNameA from the Windows Common Dialogs DLL (comdlg32.dll) ?

  8. #8
    Senior Member Follow User Gallery
    Join Date
    Jan 2003
    Location
    NYC
    Posts
    1,626

    Default

    Hi Marks,

    Mark1: A few things about your recommendation to have my script turn off Use Zfolders.

    1. I had already turned that off some time ago and forgot about it and assumed that the Zscript folder was always the default folder... so, I guess I need to remember to explicitly turn Use Zfolders off in any ZScript where I want define alternate file paths. (it also makes me leary about what other changes I've made-and-forgot-about in my Zbrush configuration that could turn up as mysterious problems when my scripts are run under other configurations... )

    2. It turns out that if I DO turn off Use Zfolders the default path points to the folder containing the ZScript... UNLESS I try to run the FileNameAsk command from inside a Note window! Then it seems to default to the Zbrush2 folder *cough*.


    Mark2:
    Hi TV. I appreciate your explicit answer on this and I still have to compare it to the code I already have. After two days of coding on this one problem, I have lots of versions that look like similar to what you have explained. (a veritable "salad" of Filename commands, tossed and retossed...)

    But the other Mark has put his finger on the problem (one of the problems) when he points to the OpenDialog problem - the fact that it has to be blank?!? leaves me no way to indicate a path to the subdirectory I want to load something from...

    I also ran into a problem with how ZScript parses the path (or should I say how it doesn't parse the path?) Especially since the back slash inside a ZScript string is used as a special switch. When I would StrMerge a path, filename and extension together where the path led to a file in a subdirectory the absence of parsing led ZScript to conclude the subdirectory was part of the filename. *sigh*. So, I'm going to try the backslash again in concatenation and see if I can get it to work.

    Anyway, since I started writing this I see that you (TV) have a new idea about using FileExicute with GetOpenFileNameA as a way to manage the OpenDialog problem. Will that work???

    Sven

  9. #9
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    Ahh, This is really all out of my league - I just like trying to solve problems - but I think I'll leave the Windows dlls to you guys .

    I wondered whether you could use the
    FileNameSetNext command to give the path but it seems that has to have a file name...

    Good luck Sven!


  10. #10
    Senior Member Follow User Gallery
    Join Date
    Jul 2002
    Location
    Copenhagen
    Age
    45
    Posts
    2,561

    Default

    Sven:

    In theory calling functions from Comdlg32.dll should work fine. But I am not 100% it will work. It will also take a fair amount of extra work as you will need to define a zscript memory block that can be passed to GetOpenFileNameA.

    The memory block should be large enough to accommodate the data structure GetOpenFileNameA expects: http://www.mangovision.com/vbapi/ref...nfilename.html

    The actual length of the memory block will vary according to the data structures various string definitions. So a check to see if the memory block exists will be needed. If it exists, MemDelete it and MemCreate a new one each time you FileExecute GetOpenFileNameA. Or you could create the memory block with room to spare.

    It could be interesting to see if it works (nudge, nudge). But I think I will wait a day or two before trying, there might be a super simple solution to the aforementioned problem. But please, be my guest and give it a shot .

    Edit: Remember to match the Case of the .DLL function you wish to execute. It will not work otherwise.

    Marcus:

    I have very little knowledge of windows programming. I only started reading more about it after the Zbrush<>.DLL connectivity was announced. If I can get a rough handle on things I am sure you can too. So don't hang up the phone just yet, join or follow the threads in this forum, we need a little more activity around here.

    Cheers

    Mark

  11. #11
    Senior Member Follow User Gallery
    Join Date
    Jan 2003
    Location
    NYC
    Posts
    1,626

    Default

    Hi Marcus,

    Yes, I know where you are coming from since I love solving problems too . In this case, I am probably a little out of my league, as well.

    I'm just trying to write a utility in ZScript that might ultimately be very useful to everyone and I became frustrated and sidelined by the odd (and I feel incomplete) implimentation of ZScript tools for managing datafiles.

    I'm still trying to learn ZScripting and often run into difficulty because I just don't understand the command options or their particular syntaxes. That's when I post a call for help - Almost always I get a quick and useful response from TVEyes, Digits, Cameyo, EZ, GM or some of the other ZScript wisemen.

    But I feel like we all are handicapped by the lack of in-depth information on the ZScripting language. Right now all we have is the command glossary, the internal command listing which supplies a little more detail on usage for some of the commands, and the autoscripting, which can be examined after the fact to see how a Zbrush process is broken down into individual commands. Add to that, old ZScript source .TXT files, a lot of TRIAL and ERROR, and the generous help from other ZScriptors and that's about it.

    We (mostly the ZScriptors with no real background in programming) need documentation that is more comprehensive - with plenty of code examples.

    Anyway, this was one of those cases and I really appreciate the input from you and TVEyes. Thank you both.

    Sven

  12. #12
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    Thanks Sven & Mark, with your encouragement and generosity I shall hang on in here and watch when I can't contribute. I've never been much interested in programming before but ZB2, ZScripts and the great community here has sparked an interest. I'd certainly like to create something useful for everybody like you guys. I've a lot to learn... meanwhile, if I discover anything on this I'll let you know.

    Cheers,
    Marcus

  13. #13
    Senior Member Follow User Gallery
    Join Date
    Jan 2003
    Location
    NYC
    Posts
    1,626

    Default

    Hi TV,

    wow. do I really want to bite this off now? Depends on how desperate I get . Maybe there are some Windoz/Zscript programmers who might throw in a suggestion or two (he said, hopefully.)

    I promise that if I try it and get it working I'll post whatever I discover. Or, maybe Pix or Matt will come to the rescue with some special insight on the problem (after they get back from Siggraph and detox, that is ).

    I need to send you an email on some other subject, so keep an eye out.

    Sven

  14. #14
    Senior Member Follow User Gallery
    Join Date
    Jun 2004
    Posts
    361

    Default

    This might be a bit helpful ...

    To specify an alternate path, I've often used the method posted by TVEyes, which involves the [FileNameResolvePath... command.

    Here's another tip: you can specify any path starting at the 'top' of the ZBrush folder tree: i.e. 'ZBRUSH_ZData\ZPlugs\WebZPlug.dll' specifies the ZData\ZPlugs\WebZPlug.dll path within the ZBrush folder.

    dave

  15. #15
    Senior Member Follow User Gallery
    Join Date
    Jul 2002
    Location
    Copenhagen
    Age
    45
    Posts
    2,561

    Default

    Thanks for that pointer Davey, very useful. I guess there is no workaround for redirecting the [FileNameAsk,....] open dialog?

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •