Hello 3D_Scan_Fan,
Please check, if the following script works for your needs:
import Metashape, os, glob
def get_chunk(label):
global doc
for chunk in doc.chunks:
if chunk.label == label:
return chunk
return None
def batch_import_mesh_to_chunks():
global doc
doc = Metashape.app.document
if not len(doc.chunks):
print("Empty project, script aborted.")
return 0
input_dir = Metashape.app.getExistingDirectory("Specify the folder with OBJ files:")
if not input_dir:
print("Invalid path, script aborted.")
return 0
import_list = [file for file in glob.iglob(input_dir + "\\*.*", recursive = False) if (os.path.isfile(file) and os.path.splitext(file)[1][1:].upper() in ["OBJ"])]
for input_model in import_list:
for chunk in doc.chunks:
if not (chunk.label.lower() == os.path.basename(input_model).rsplit(".",1)[0].lower()):
continue
chunk.model = None
try:
chunk.importModel(path = input_model, format = Metashape.ModelFormatOBJ, crs = chunk.crs)
except:
print("Can't import model. Skipping " + input_model)
print("No chunk found for " + input_model)
print ("Script finished")
return 1
label = "Custom menu/Batch Import Mesh"
Metashape.app.addMenuItem(label, batch_import_mesh_to_chunks)
print("To execute this script press {}".format(label))