Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import os
- from bpy.props import(StringProperty,
- PointerProperty,
- )
- from bpy.types import(Panel,
- Operator,
- AddonPreferences,
- PropertyGroup,
- )
- class MySettings(PropertyGroup):
- path = StringProperty(
- name="",
- description ="Path to Directory",
- default ="",
- maxlen=1024,
- subtype='DIR_PATH')
- class WMImporterPanel(Panel):
- bl_idname = "OBJECT_PT_WMImporter"
- bl_category = "WorldMachine Importer"
- bl_label = "WM Importer"
- bl_space_type = 'VIEW_3D'
- bl_region_type = 'TOOLS'
- bl_context = 'objectmode'
- def draw(self, context):
- layout = self.layout
- col = layout.column(align=True)
- scn = context.scene
- #Selecting Directory/Folder path
- col.label(text="Directory of Files")
- col.separator()
- dirpath = col.prop(scn.my_tool, "path", text="")
- #Button to perform import of meshes
- col.separator()
- col.operator("wmimport.importmeshes", text = "Import Meshes")
- class OBJECT_OT_ImportButton(Operator):
- bl_idname = "wmimport.importmeshes"
- bl_label ="Import Meshes"
- def execute(self,context):
- scn = context.scene
- dirpath = scn.my_tool.path
- #print(dirpath)
- file_list = os.listdir(dirpath)
- obj_list = [item for item in file_list if item[-3:] == 'obj']
- #for file in obj_list:
- # print (file)
- # Detect Naming Convention
- # Need Help
- # I want to pull the first file and rip the format from it.
- # Files come in the format of <filename>_x000_y000.obj
- # I want to use the filename to name each object imported, so if I called it Island
- # the object in blender will be called something like Island(X,Y)
- # where X = number following x in filename, and Y likewise.
- for item in obj_list:
- #Detect Location
- # Need Help
- #I want to get the X and Y value in the filename, so I can use that to
- #increment the object in corrosponding directions.
- fullpath = os.path.join(dirpath,item)
- bpy.ops.import_scene.obj(filepath=fullpath, axis_forward='Y', axis_up='Z')
- # Should I assign this obj to a variable?
- # newObj = bpy.ops.import_scene.obj(filepath=fullpath, axis_forward='Y', axis_up='Z')
- return{'FINISHED'}
- def register():
- bpy.utils.register_module(__name__)
- bpy.types.Scene.my_tool = PointerProperty(type=MySettings)
- def unregister():
- bpy.utils.unregister_module(__name__)
- del bpy.types.Scene.my_tool
- if __name__ == "__main__":
- register()
- def get_nameXY(item):
- name_set = item.split('_') #splits the string at every '_', returns a list
- x = name_set[1][1:] #gets the second value in the list starting at the second character
- y = name_set[2][1:-4] #gets the third value in the list starting at the second character and omitting the last four characters
- name = name_set[0] + '(' + x + ',' + y + ')' #combine the first value with x and y
- return name, float(x), float(y) #return the name with x and y as floats
- for item in obj_list:
- #Detect Location
- name, x, y = get_nameXY(item)
- for obj in bpy.data.objects:
- obj.select = False #deselect all objects so imported object will be the only one selected
- fullpath = os.path.join(dirpath,item)
- bpy.ops.import_scene.obj(filepath=fullpath, axis_forward='Y', axis_up='Z')
- new_obj = bpy.context.selected_objects[0] # get object from list of selected
- new_obj.name = name #set the new name
- new_obj.location = (x,y,0)#set the location
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement