import os import time import pyautogui import pywinauto from selenium import webdriver from selenium.webdriver.common.by import By def slcer_3Dtiles(root, file, enu=None): browser = webdriver.Chrome() browser.maximize_window() browser.get('http://localhost:9003/index.html#/data/model') # 选择 通用模型切片 time.sleep(2) browser.find_element(By.XPATH, '//*[@id="right_box"]/div/div[1]/ul/a[8]/li/button').click() time.sleep(2) # 选择输入文件 fbx browser.find_element(By.XPATH, '//*[@id="input_button"]/button[2]').click() time.sleep(1) # 使用pywinauto来选择文件 app = pywinauto.Desktop() # 选择文件上传的窗口 dlg = app["打开"] # 选择文件地址输入框,点击激活 # dlg["Toolbar3"].click() # 键盘输入上传文件的路径 # send_keys(r"D:\osg\wenxingyuan\test\tyzzkcc001.obj") # 键盘输入回车,打开该路径 # send_keys("{VK_RETURN}") # 选中文件名输入框,输入文件名 dlg["文件名(&N):Edit"].type_keys(os.path.join(root, file)) # dlg["文件名(&N):Edit"].type_keys(r'D:\osg\wenxingyuan\test\tyzzkcc001.obj') # 点击打开 dlg["打开(&O)"].click() time.sleep(2) # fbx设置空间参考范围 if enu: browser.find_element(By.XPATH, '//*[@id="setting_general"]').click() input_box = browser.find_element(By.XPATH, '//*[@id="all_right"]/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div[1]/textarea') input_box.clear() time.sleep(1) input_box.send_keys('ENU:%s' % enu) time.sleep(1) browser.find_element(By.XPATH, '//*[@id="all_right"]/div[3]/div/div/div[3]/button[2]').click() time.sleep(20) # 操作鼠标选择存储类型 # 获取鼠标位置(x,y) # pyautogui.position() time.sleep(2) pyautogui.moveTo(3552, 667) pyautogui.click() time.sleep(2) pyautogui.moveTo(3553, 732) pyautogui.click() time.sleep(2) # 数据存储 browser.find_element(By.XPATH, '//*[@id="all_right"]/div[1]/div/div[16]/div/div[3]/div[4]/div[1]/button').click() app = pywinauto.Desktop() # 选择文件上传的窗口 dlg = app["选择文件夹"] # print(dlg.print_control_identifiers()) # 选择文件地址输入框,点击激活 dlg["Toolbar3"].click() # 键盘输入上传文件的路径 # send_keys(r"D:\osg\wenxingyuan\test\111") # 键盘输入回车,打开该路径 # send_keys("{VK_RETURN}") # 选中文件名输入框,输入文件名 if not os.path.exists(os.path.join(root, file.split('.')[0])): os.makedirs(os.path.join(root, file.split('.')[0])) time.sleep(3) dlg["文件夹:Edit"].type_keys(os.path.join(root, file.split('.')[0])) # 点击打开 dlg["选择文件夹2"].click() time.sleep(1) # 提交处理 browser.find_element(By.XPATH, '//*[@id="newfile_button"]/button').click() if __name__ == '__main__': input_path = r'D:\FBX\ojk_small\1' eun = '27.9262613,120.9439152' for root, dirs, files in os.walk(input_path): for file in files: if os.path.splitext(file)[-1] in ['.FBX']: if file.split('.')[0] not in os.listdir(os.path.join(root)): if isinstance(eun, str): slcer_3Dtiles(root, file, eun) elif isinstance(eun, dict): slcer_3Dtiles(root, file, eun.get(file)) else: slcer_3Dtiles(root, file)