Run CLI scripts through subfolders

Hi all,
I am trying to use a CLI bat script to process a few folders , one after another. The issue I am facing, is that the models and textures are exported to the root folder instead inside the folder next to the images.

The script works, goes through all the folders, and processes the images, but it overrides the exported model after each loop in the root.

My folder structure:

  • Root folder (where script is located and where the models are exported)
    – model folder 1
    — images
    – model folder 2
    — images
    – model folder 3
    — images

This is my script:

@echo off

call SetVariables.bat

:: set the name for the high-poly model
set HighPoly=HighPoly

:: set the name for the low-poly model
set LowPoly=LowPoly

:: set the value of triangles to which high-poly model will be simplified
set SimplifyTo=10000

:: set the path to the .xml with Texture Reprjection settings
set TextureReproSettings="%RootFolder%\TextureReprojectionSettings.xml"

:: set the path, where model is going to be saved, and its name
set Model="%RootFolder%\LowPolyModel.obj"

:: set the path, where project is going to be saved, and its name
set Project="%RootFolder%\Project.rcproj"

::Create loop on which to run RC for all subfolders
:: for /R %%f in (%RootFolder%\..) do >>runscriptrealitycapture

for /D %%f in ("%RootFolder%*") do (
        ::echo Processing folder: '%%f'^

        :: run RealityCapture
        %RealityCaptureExe% -newScene ^
                -addFolder "%%f\images" ^
                -align ^
                -selectMaximalComponent ^
                -setReconstructionRegionAuto ^
                -calculateHighModel ^
                -renameSelectedModel %HighPoly% ^
                -calculateTexture ^
                -simplify %SimplifyTo% ^
                -renameSelectedModel %LowPoly% ^
                -unwrap ^
                -reprojectTexture %HighPoly% %LowPoly% %TextureReproSettings% ^
                -selectModel %LowPoly% ^
                -exportModel %LowPoly% %Model% ^
                -save "%%f\Project.rcproj" ^
                -quit
)

How can I write this so that the models and textures are exported inside each folder – model folder 1 / – model folder 2 etc ??

Thank you.
I.F.

Hey,

there are a bunch of ways to achieve what you want, but for the quickest solution, I first edited lines 17 to 21.

Removed:

:: set the path, where model is going to be saved, and its name
set Model="%RootFolder%\LowPolyModel.obj"

:: set the path, where project is going to be saved, and its name
set Project="%RootFolder%\Project.rcproj"

And replaced with:

:: set the name for the exported model
set Model=LowPolyModel

Next I edited line 43.

Removed :

-exportModel %LowPoly% %Model% ^

And replaced with:

-exportModel %LowPoly% "%%f\%Model%.obj" ^

The new script now looks like this:

@echo off

call SetVariables.bat

:: set the name for the high-poly model
set HighPoly=HighPoly

:: set the name for the low-poly model
set LowPoly=LowPoly

:: set the value of triangles to which high-poly model will be simplified
set SimplifyTo=10000

:: set the path to the .xml with Texture Reprjection settings
set TextureReproSettings="%RootFolder%\TextureReprojectionSettings.xml"

:: set the name for the exported model
set Model=LowPolyModel

::Create loop on which to run RC for all subfolders
:: for /R %%f in (%RootFolder%\..) do >>runscriptrealitycapture

for /D %%f in ("%RootFolder%*") do (
        ::echo Processing folder: '%%f'^

        :: run RealityCapture
        %RealityCaptureExe% -newScene ^
                -addFolder "%%f\images" ^
                -align ^
                -selectMaximalComponent ^
                -setReconstructionRegionAuto ^
                -calculateHighModel ^
                -renameSelectedModel %HighPoly% ^
                -calculateTexture ^
                -simplify %SimplifyTo% ^
                -renameSelectedModel %LowPoly% ^
                -unwrap ^
                -reprojectTexture %HighPoly% %LowPoly% %TextureReproSettings% ^
                -selectModel %LowPoly% ^
                -exportModel %LowPoly% "%%f\%Model%.obj" ^
                -save "%%f\Project.rcproj" ^
                -quit
)
1 Like

Thank you, it works.

:beers:

1 Like