3
$\begingroup$

I create some small my own primitives. Is possible import it from blender file?

For example in blender file my1.blend I have object caled "my1". I prefer working on small files with one object in one file and next join it together and put location/scale in specyfic way.

I need import this object into my current blender project (other than my1, for example all.blend) in specyfic x,y,z location, and scaling to 1.5 factor. My object have some modyficators, materials etc.

I need only read object, materials, color etc. No scenes, lights etc.

$\endgroup$

3 Answers 3

1
$\begingroup$

You'll want to look at bpy.data.libraries.load(), which allows you to open a Blendfile and select which datablocks (objects, meshes, materials, etc.) you want to append or link. The API documentation also has examples.

$\endgroup$
1
$\begingroup$

In case the API documentation linked by dr. Sybren isn't enough, I have another example of using bpy.data.libraries.load() at http://web.purplefrog.com/~thoth/blender/python-cookbook/link-external-data-blocks.html

Here is a copy of it:

import bpy


def library_get(name, data_blocks, libpath=None):
    """ Since it is possible for a .blend file to have several objects 
with the same name linked from different files, this routine lets us 
hunt down the right one. """
    for x in data_blocks:
        if x.name == name and x.library is not None:
            if libpath is None or libpath == x.library.filepath:
                return x
    return None


def addGroupToScene(grp, scn):
    for obj in grp.objects:
        scn.objects.link(obj)

#
#

fname = "//cube.blend"

print(fname)
with bpy.data.libraries.load(fname, link=True) as (src, dst):
    # src has many properties, each of which is a list of name strings.
    # dst is how we specify what we want to link from the library file.

    # let's link the "dazed" scene
    dst.scenes = ["dazed"]
    # and the "omnitile" object
    dst.objects = ["omnitile"]
    # and an object group
    dst.groups = ["frog"]

    # and just to be fancy, let's count up how many linkable things there are
    for dbt in dir(src):
        name_list = getattr(src, dbt)
        print("%s[%d]" % (dbt, len(name_list)))

# just because we linked an object doesn't mean that object is in any of our scenes.
omnitile = library_get("omnitile", bpy.data.objects)

scn = bpy.context.scene
try:
    scn.objects.link(omnitile)
    # now it is.
except:
    pass

# link all the objects from group "frogs" to the current scene
addGroupToScene(library_get("frogs", bpy.data.groups), scn)
$\endgroup$
0
$\begingroup$

I think you need

https://docs.blender.org/api/blender_python_api_current/bpy.ops.wm.html?highlight=bpy%20ops%20wm#bpy.ops.wm.link

It will take some time to get all the params right. Then scale/Move your object as usual from python.

$\endgroup$
1

You must log in to answer this question.

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