Hi,
I am wonderinf how to import and move every obj file next to the previous one in sequence based on file name (files are numbered: example: chair01)?
Importing them all at once, they all fall into the same location.
Below is my reference script from Mitch Heynick.
import rhinoscriptsyntax as rs
import scriptcontext as sc
import os
"""Imports all .obj files in a folder. All geometry goes to current layer.
Import settings can be adjusted as needed, can be adapted to other formats.
Script by Mitch Heynick 02.09.19"""
def OBJImportSettings():
e_str = " _ImportObjGroupsAs=_ObjectNames "
e_str+= "_IgnoreTextures=_No "
e_str+= "_MapYtoZ=_No "
e_str+= "_MorphTargetOnly=_No "
e_str+= "_ReverseGroupOrder=_No "
e_str+= "_Split32BitTextures=_No"
return e_str
def BatchConvertToObj():
#Get folders
folder = rs.BrowseForFolder(message="Select folder to process")
if not folder: return
found = False ; counter=0 ; ext="obj"
rs.EnableRedraw(False)
sett=OBJImportSettings()
#Find Rhino files in the folder
for filename in os.listdir(folder):
if filename.endswith(ext):
found = True
fullpath=os.path.join(folder,filename).lower()
rs.EnableRedraw(False)
#Open file to convert
comm_str="_-Import "+chr(34)+fullpath+chr(34)+sett+" _Enter"
rs.Command (comm_str, False)
if rs.LastCommandResult()==0: counter+=1
rs.EnableRedraw(True)
if not found:
msg="No .{} files found in selected folder!".format(ext)
else:
msg="Successfully imported {} .{} files.".format(counter,ext)
rs.MessageBox(msg)
BatchConvertToObj()