Solved

Blender 2.5x python script to combine objects in scene

Posted on 2010-09-24
4
1,508 Views
Last Modified: 2013-12-21
I am using blender 2.54.

Please write a python script that would place 3d model of simple object such as a box ( named item.blend) on the ground floor of main scene file ( named main.blend) . Main scene can be any simple scene (like a really simple room) that has ground floor.

Please also include the .blend files in your solution. Again these are really simple scenes or you may already have such .blend files.

The script must run from the command line ( Not starting blender UI and typing the script within blender UI).

Please provide solution if you have python programming experience with blender.

This is not a homework project. I am learning 3d programming in the context of blender.

 
0
Comment
Question by:zenguru
  • 4
4 Comments
 
LVL 9

Expert Comment

by:zaghaghi
ID: 33777853
Hi you can use this code:

hope this works.
import bpy

blendfilepath = "/tmp/untitled.blend"
objectname = "Cube"

res = bpy.ops.wm.link_append(directory=blendfilepath + "/Object/",filename=objectname, link=False, instance_groups=False)
if list(res)[0] == 'FINISHED':
    print("Successfully imported!")
else:
    print("There was an error!")

Open in new window

0
 
LVL 9

Accepted Solution

by:
zaghaghi earned 500 total points
ID: 33777922
Also if you have multiple Objects and want to import them, first create a group and add all objects to that group. then in 4th line use name of the created group instead of "Cube" and in 6th line use "/Group/" instead of "/Object/".
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 33777966
For example if i had 3 Objects in "Cubes" group in a.blend then i can use this code
res = bpy.ops.wm.link_append(directory=blendfilepath + "/Group/",filename="Cubes", link=False, instance_groups=False)

Open in new window

0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 33777978
As python API of blender 2.5 is currenly unstable use http://www.blender.org/documentation/250PythonDoc/bpy.ops.wm.html#bpy.ops.wm.link_append for future refs.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question