0

Basically, I am trying to make some mesh models watertight using an algorithm. The algorithm is already built in C++ and can be run using the following command:

./manifold ../examples/input.obj ../examples/manifold.obj

Here I have to pass an input object, and the algorithm will output an object named manifold. I have thousands of input objects in different directories. And I am using a Python script to extract those input objects. The code is provided below.

def input_object(folder):
    for sub_folders in os.listdir(folder):
        for x in os.listdir(folder+sub_folders):
            if x == 'models':
                for y in os.listdir(folder+sub_folders+'/'+x):
                    if y == 'model_normalized.obj':
                        print(y)

                        #I want to execute the build file here


root = './02880940/'
input_object(root)

I want to execute the build file inside this commented area of the script. How can I do that? I am not well-versed in C++. Thanks in advance.

Nafees
  • 47
  • 1
  • 1
  • 7
  • Is this what you had in mind? https://stackoverflow.com/questions/89228/how-do-i-execute-a-program-or-call-a-system-command – Jeremy Friesner Apr 10 '23 at 00:55
  • 1
    There's probably some confusion here due to a very unfortunate choice of words. "Building" and "object files" have a common meaning in C++ that's utterly unrelated to this question. C++ converts source code into executables in two steps. This process is commonly called "building" and the intermediary files after the first step are called object files. But *this* question is not about C++ at all. There's some executable called `manifold`, and for all we care it could be written in FORTRAN. – MSalters Apr 11 '23 at 09:16
  • @MSalters thanks for clearing up the confusion. apologies for the wrong choice of words. – Nafees Apr 12 '23 at 10:15
  • @JeremyFriesner yes. I have solved the problem using the subprocess module. Thanks for the resource. – Nafees Apr 12 '23 at 10:16

1 Answers1

1

Have you ever heard of subprocess? if your C++ code is already built, simply import subprocess and call the run function. something like this:

import subprocess
def input_object(folder):
    for sub_folders in os.listdir(folder):
        for x in os.listdir(folder+sub_folders):
            if x == 'models':
                for y in os.listdir(folder+sub_folders+'/'+x):
                    if y == 'model_normalized.obj':
                        print(y)

                        #I want to execute the build file here

                        subprocess.run("manifold.obj")

root = './02880940/'
count_messages(root)

something like this

Prashanthv
  • 109
  • 7