Home Technical Talk

Windows Batch File Scripting

interpolator
Offline / Send Message
m4dcow interpolator
Whenever I finish a project and want to archive it away, I will convert my high res obj files to ctm format with openCTM, it makes the files almost 100 times smaller in some cases, and Xnormal can read these directly if something needed to be baked again.

OpenCTM has a command line converter which is easy enough to use and the syntax is:
ctmconv fileIn.obj fileOut.ctm
What I was trying to do was create a batch file that I could drop a file onto to convert, that would use the name of the obj coming in and generate a ctm file from that, would be the equivalent of this.
ctmconv myMesh.obj myMesh.ctm
I have a very loose grasp on windows batch file scripting and can't understand how to manipulate variables. I did the following, but the output file is hard coded:
ctmconv %1 myMesh.ctm
Ideally I would have a situation where I could drag and drop a couple meshes on the batch file and have those converted, but I would still be happy with dragging and dropping one at a time.

Replies

  • chronic
    Options
    Offline / Send Message
    chronic polycounter lvl 10
    here is what you want - dont know about multiple files through drag and drop - although you could do something that when you run the batch file does all the .obj files in that folder.
    ctmconv %1 "%~d1%~p1%~n1.ctm"
    

    d - refers to the drive
    p - refers to the path
    n - refers to the name

    they can be used on their own or in combination if you only need "%~n1" for example to get the file name
  • m4dcow
    Options
    Offline / Send Message
    m4dcow interpolator
    chronic wrote: »
    here is what you want - dont know about multiple files through drag and drop - although you could do something that when you run the batch file does all the .obj files in that folder.
    ctmconv %1 "%~d1%~p1%~n1.ctm"
    

    d - refers to the drive
    p - refers to the path
    n - refers to the name

    they can be used on their own or in combination if you only need "%~n1" for example to get the file name

    Thanks chronic does exactly what I was looking to do, and looking at your example helps me understand how to use those string manipulation techniques with a value passed into a batch file.
Sign In or Register to comment.