Forum

Poll

Running the workflow completely automatized

Yes
12 (54.5%)
No
10 (45.5%)

Total Members Voted: 22

Author Topic: Python Scripting  (Read 30851 times)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15403
    • View Profile
Re: Python Scripting
« Reply #15 on: July 14, 2014, 11:29:55 AM »
Hello Freiberg,

There's optional "frame" argument in the .exportModel() method, so you need to loop through all frames and export them individually:
Code: [Select]
for frame in range(chunk.frame_count):
    export_path = export_folder + "\\model_" + str(frame) + ".obj"
    chunk.exportModel(path = export_path, texture_format = "jpg", texture = True, format = "obj", frame = frame)

Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15403
    • View Profile
Re: Python Scripting
« Reply #16 on: May 12, 2017, 02:53:14 PM »
Due to some requests, I'm publishing the updated script version that should work both in versions 1.2.6 and 1.3:

Code: [Select]
import os
import PhotoScan

TYPES = ["JPG", "TIF", "TIFF", "PNG"]

doc = PhotoScan.app.document
print("Script started")

chunk = doc.addChunk()
chunk.label = "Multiframe"

path = PhotoScan.app.getExistingDirectory("main folder:")
folders = os.listdir(path)

for folder in list(folders):
if not os.path.isdir(path + "\\" +folder):
folders.remove(folder)
folders.sort()

image_folders = list()
for frame in range(len(folders)):
images = os.listdir(path + "\\" + folders[frame])
images.sort()
new_list = list()
image_folders.append(new_list)
for image in list(images):
if image.rsplit(".", 1)[1].upper() not in TYPES:
images.remove(image)
else:
image_folders[-1].append(path + "\\" + folders[frame] + "\\" + image)

#Loading images:
for frame in range(len(image_folders)):

if not frame:
chunk.addPhotos(image_folders[frame])
else:
f = chunk.addFrame()
for i in range(len(chunk.cameras)):
camera = chunk.cameras[i]
camera.frames[-1].open(image_folders[frame][i])

print("Script finished")
Best regards,
Alexey Pasumansky,
Agisoft LLC