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:
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.append(i)
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.append(i)
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 = PhotoScan.app.document
chunk = doc.addChunk()
chunk.label = "New Chunk"
project_output = "E:\\James Yuwanant"
photo_path = PhotoScan.app.getExistingDirectory(original_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
doc.save(project_output + 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]))
chunk.addPhotos(photo_list)