After I wrote the previous script, I tried to create a button to add a robot, from one of the pre-build robots I have access to, to a scene.
I experimented a bit with the link_append function to try adding multiple objects at once so any parent/child links would be maintained, but I couldn't find how to do this with link_append. After a suggestion by Pipeline, I created a new .blend file with the whole robot added to a single group and then I tried to append this group. This worked, and I noticed that now blender appended the different objects with parent/child links maintained. It imported the different objects, but it also imported the object as one large group which created duplicate meshes. So the only thing left was to unlink this group.
The code for this script is almost the same as my previous script, so I won't explain the whole script. You can find the script here and here. You can find the .blend file containing the rx130 robot in a single group here, notice that I didn't create this robot and that it is licensed through the LGPL license.
Below is the execute function that is called when a user presses the "Add rx130" button.
def execute(self, context):
'''
Function to process a click on the "import Object" button
'''
bpy.ops.wm.link_append(directory="YOUR_DIRECTORY\\rx130.blend\\Group\\", link=False, filename="RX130") #append rx130 from blend file
bpy.data.scenes['Scene'].objects.unlink(bpy.data.objects['RX130'])
return{'FINISHED'}
- The 5th line appends the group that contains all the meshes and armatures from the rx130 robot. Change "YOUR_DIRECTORY" to the directory where you downloaded the rx130.blend file.
- The 6th line unlinks the duplicate group object.
I hope you like the script, and if anyone knows how to append/link objects with maintaining the parent/child links and without the needing of a group, contact me please. Or If you can explain why appending a group creates a duplicate object, I'm eager to know.
When appending try adding this:
ReplyDeleteinstance_groups=False