Author Topic: Add photos to chunk from dynamic folder  (Read 1483 times)


  • Newbie
  • *
  • Posts: 1
    • View Profile
Add photos to chunk from dynamic folder
« on: June 18, 2018, 12:40:59 PM »
Hi Community ,

I would like to add photos to the chunk from dynamic folder automatically, but when I run my script it will pop-up window to select folder and I have to use the mouse to click and select folder that stored photos, instead of automatic add photos to the chunk.

my code is following:

Code: [Select]
import os
import glob
import PhotoScan
from datetime import datetime

directory = "H:/Projects/9HX124375.50 Nam Theun 1 - Pre-Design Works/Drone Post Processing/Flights"

# select last item in directory
y_month = []
path = os.listdir(directory)
for i in path:
y_month = y_month[-1]

#access last item in directory
folder = max(glob.glob(os.path.join(directory,y_month)),
key = os.path.getmtime)

#access Overview folder
overview_path = max(glob.glob(os.path.join(folder,'Overview')),
key = os.path.getmtime)

#select the last item in Overview folder
latest_day = []
y_day = os.listdir(overview_path)
for i in y_day:
latest_day = latest_day[-1]

#access the last item in Overview Folder
day_path = max(glob.glob(os.path.join(overview_path,latest_day)),
key = os.path.getmtime)

#access Original file Folder
original_path = max(glob.glob(os.path.join(day_path,"Original files")),
key = os.path.getmtime)


doc =
chunk = doc.addChunk()
chunk.label = "New Chunk"

project_output = "E:\\James Yuwanant"
photo_path =
get_time = os.path.getmtime(day_path)
project_date = datetime.fromtimestamp(get_time).strftime('%Y%m%d')
project_name = project_date + '_Overview'
image_list = os.listdir(photo_path)
photo_list = list()

#save + project_name + ".psx")

for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([photos_path, photo]))
« Last Edit: June 18, 2018, 01:04:50 PM by Nattawut »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14615
    • View Profile
Re: Add photos to chunk from dynamic folder
« Reply #1 on: July 01, 2018, 07:06:59 PM »
Hello Nattawut,

In your code you are using function - it creates the GUI dialog that prompts for the folder (for the selected folder the path will be returned).

I assume you need just to make the direct assignment in the line 45:
Code: [Select]
photo_path = original_path
Best regards,
Alexey Pasumansky,
Agisoft LLC