3
$\begingroup$

I have an obj created from Qubicle Constructor. I am able to import this into Blender just fine. The workflow I want is modeling in Qubicle and animation in Blender. I then try and make changes to my model and export again and then import again into blender but I get suplicate objects in my blender scene.

Example, on the first import I may have a mesh called "Calf_Left", after re-import I get "Calf_Left.001". Is there a way to get this worklow to not create duplicate meshes and instead just replace whats there if if finds one with the same name?

$\endgroup$

2 Answers 2

4
$\begingroup$

You could import your externally created models into separate .blend files and link them into a master .blend file containing the scene instead of directly importing them. This way the linked files can be refreshed.

The basic idea:

enter image description here

I uploaded a working sample here

WARNING: The script should not be started from your scene file it first deletes all content. You would need to invoke it from command line see: Put the following command in a batch file conv.bat

"C:\Program Files\Blender Foundation\Blender\blender.exe"  --background --python batch_convert.py
pause

Save the python script in batch_convert.py

import os
import bpy

# put the location to the folder where the objs are located here in this fashion
path_to_obj_dir = os.path.join('C:\\', 'OBJ')

# get list of all files in directory
file_list = os.listdir(path_to_obj_dir)

# get a list of files ending in 'obj'
obj_list = [item for item in file_list if item[-3:] == 'obj']

# loop through the strings in obj_list 
for item in obj_list:
    # select all object
    bpy.ops.object.select_all(action='SELECT')
    # delete selected
    bpy.ops.object.delete(use_global=True)
    # import obj
    path_to_import = os.path.join(path_to_obj_dir, item)
    bpy.ops.import_scene.obj(filepath = path_to_import)
    # rename
    for obj in bpy.context.selected_objects:
        obj.name = item[:-4]
        print(dir(obj))


    # write blend
    path_to_export = os.path.join(path_to_obj_dir, item[:-4] + ".blend")
    print(path_to_export)
    bpy.ops.wm.save_as_mainfile(filepath=path_to_export, check_existing=False )

After exporting an .obj you would only run the batch file and the linked .blend files will be updated.

Related:

$\endgroup$
4
  • 1
    $\begingroup$ I think the OP wants to re-import the models as changes are made to them with an external program (so linking from a .blend won't work, as the models are being edited would still have to be manually imported and re linked). Unless I'm missing something, that is. $\endgroup$
    – gandalf3
    May 27, 2014 at 9:12
  • $\begingroup$ What I mean is an alternative to re-importing by re-creating dependend files, Qubicle is able to export to Obj, so the linked files could be re-created like this: blender.stackexchange.com/questions/5064/… after each edit. $\endgroup$
    – stacker
    May 27, 2014 at 9:48
  • 1
    $\begingroup$ @stacker sorry, those suggestions do not work. Linking can only link blender files as gandalf3 mentioned and while I was able to execute the script you linked to and was able to make it run, subsequent executions of that script do just the same as any other import....it creates duplicate meshes. $\endgroup$
    – Marc
    May 28, 2014 at 4:04
  • $\begingroup$ It partially worked. What I wanted, obj2.blend was updated with obj2.obj per your screenshot using your download provided and simply editing the sphere and exporting it to replace the existing sphere.obj. THANKS! However, in the scene.blend file the sphere was no longer visible for some reason. Which would be nice if that's fixed but all my scenes for this particular project only have one source obj. ;-) $\endgroup$
    – Marc
    Jun 8, 2014 at 4:46
0
$\begingroup$

Since you're want to replace the object you are revising, one object is to delete the object you're going to replace before you import the revised version. Or, if for some reason you want to keep the older version, you could rename calf to calf.001 before you reimport.

$\endgroup$
1
  • 1
    $\begingroup$ Deleting would not work as then I would loose any bone to mesh parenting for animations. I could try the renaming, I doubt that would work as well as I assume Blender is using some GUID underneath to track its hierarchy and referencing. $\endgroup$
    – Marc
    May 27, 2014 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .