konstantin magnus Posted March 11, 2018 Share Posted March 11, 2018 How do I batch open randomly named OBJ-files from a folder on my harddisk and how can I batch save those in a different folder while keeping their file names? Quote Link to comment Share on other sites More sharing options...
Atom Posted March 11, 2018 Share Posted March 11, 2018 (edited) The only way I have been able to solve that is to use a Python shelf tool to read all the OBJ files in a folder and create a subnet of objects that points to those files. The script creates an index based name so you can batch export them in the /out context (using a Geometry node), however it does not preserve the original name. The main goal of the script is to take a random series of file .objs and create a new set that could be indexed for instancing. However, you could store the original name in the comment field of the object then in the post write of the Geometry output driver rename the newly exported indexed file to back to the original name. The script can be found here if you want to check it out. The script also creates companion nodes after the File node which would fall into the category of your do_something criteria. The script also shows how to drop down a wrangle and python node and install inline code processing if you need that. Edited March 11, 2018 by Atom Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted March 11, 2018 Author Share Posted March 11, 2018 (edited) Thank you Atom, but I wouldnt want to bulge-import dozens of models ; ) I was rather thinking of a few lines such as: List all OBJs from a directory Open one of them at a time Process in a subnetwork Export again as OBJ I would not mind doing this on a per frame-basis, albeit not ideal. Couldnt I pythonize just the file name slots in the Read and Write nodes? Edited March 11, 2018 by konstantin magnus Quote Link to comment Share on other sites More sharing options...
Atom Posted March 11, 2018 Share Posted March 11, 2018 (edited) Ok, what about something like this... Place this code in the Pre-Frame Script field of the rop_geometry1 node. Remember to switch code processing from the default of Hscript to Python. It basically scans the input folder on every frame change and uses the frame number as an index into the retrieved list. It re-writes the file1 input path and the rop_geometry1 output path to match the current file being processed. The results are stored in a folder named results, so you will have to manually create that. Quite a bit of hard coding, but it does seem to work. Just don't rename nodes and populate the input and output paths to match your folders. USAGE: Click Render on the rop_geometry1 node. # Process a series of .OBJ files. import os input_path = r"F:\Keep\Models\Rocks" output_path = r"F:\Keep\Models\Rocks\result" def returnFilesLike(passedFolderName, passedFileExtension = ".obj"): result = [] for file in os.listdir(passedFolderName): if file.endswith(passedFileExtension): result.append(os.path.join(passedFolderName,file)) return result lst_files = returnFilesLike(input_path, ".obj") l = len(lst_files) if (l>0): frame = hou.intFrame() if frame <= l: # Frame is within range of object count in this folder. file_source = os.path.split(lst_files[frame])[1] file_node = hou.node("/obj/geo1/file1") file_node.parm("file").set(lst_files[frame]) file_dest = os.path.join(output_path,file_source) rop_node = hou.node("/obj/geo1/rop_geometry1") rop_node.parm("sopoutput").set(file_dest) ap_re_process_folder_of_OBJs.hiplc Edited March 11, 2018 by Atom 5 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted March 11, 2018 Author Share Posted March 11, 2018 Atom, this is beyond cool ! Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted April 1, 2018 Share Posted April 1, 2018 geo = hou.pwd().geometry() for f in random_file_list: geo.loadFromFile(f) 1 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted December 22, 2018 Author Share Posted December 22, 2018 Thanks for the hint, Alex! Seems like you can do batch jobs completely within a python node : ) This one for example scales all OBJ files from a folder and its subfolders and saves them to another location: import os geo = hou.pwd().geometry() scale = hou.evalParm('scale') dir_imp = hou.evalParm('dir_import') dir_exp = hou.evalParm('dir_export') for root, dirs, files in os.walk(dir_imp): for file in files: if file.endswith('.obj'): path_import = os.path.join(root, file) path_export = dir_exp + file geo.loadFromFile(path_import) for point in geo.points(): pos = point.position() * scale point.setPosition(pos) geo.saveToFile(path_export) 2 Quote Link to comment Share on other sites More sharing options...
stephenanimation Posted February 21, 2020 Share Posted February 21, 2020 If you wanted to do this and then convert the file to a .fbx or another format how would you do that? Quote Link to comment Share on other sites More sharing options...
anim Posted February 22, 2020 Share Posted February 22, 2020 23 hours ago, stephenanimation said: If you wanted to do this and then convert the file to a .fbx or another format how would you do that? nowadays you can just use TOPs for any sort of batch processing like this 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.