1. #1
    New Member Follow User Gallery
    Join Date
    Jul 2017
    Posts
    2

    Default Help on editing script

    I don't know scripting but I want to edit script made by recording a macro. So if someone can help it will be appreciated!
    In script is given filename for import for example C/345_File.obj but those numbers '345'are changeable so I want it to import File.obj no matter what numbers are there.
    Have anybody got solution to this?

  2. #2

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

    Default

    You can't use wildcards with file names in zscript, so you need to loop through all the possible names. This bit of code shows how it can be done. Note that the path and last part of the file name are set at the top. This will only load one file, the first it finds that has a path & name of the form "Test/323_File.obj".


    [VarDef,path,"Test/"]//set the path to the file here
    [VarDef,fileName,"_File.obj"]//set the end part of file name here


    [IButton,???,"Import a file", //macro button
    //start of code inside button
    [Loop,1000,//loop through all possible file names
    [If,n < 10,
    [VarSet,nStr,[StrMerge,"00",[Val,n]]]
    ,
    [If,n < 100,
    [VarSet,nStr,[StrMerge,"0",[Val,n]]]
    ,
    [VarSet,nStr,[Val,n]]
    ]
    ]
    [VarSet,fullFileName,[StrMerge,path,nStr,fileName]]
    [If,[FileExists,fullFileName],[LoopExit]]//exit loop if there's a file
    ,n]//end of loop
    [If,[FileExists,fullFileName],//need this check in case loop completed
    [FileNameSetNext,fullFileName]
    [IPress,Tool:Import]//import file
    ]
    //end of code inside button
    ]//end button

  4. #4
    New Member Follow User Gallery
    Join Date
    Jul 2017
    Posts
    2

    Default

    Thanks marcus_civis!
    Was hoping for those wildcards at first,like a easy fix.
    Nice suprise that you gave effort to help,thank you very much!!!

Posting Permissions

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