[Bf-python] Ask for: link/append/import returns object(s) instance(s)

Pierrick Koch pierrick.koch at gmail.com
Wed May 25 09:14:40 CEST 2011


Thanks,

would it be possible that the bpy.ops.wm.collada_import method could select
all imported objects ?
for instance if I have a car plus 4 wheels in the file "atrv257.dae", and I
do:
#
bpy.ops.wm.collada_import(filepath="/home/pierrick/atrv257.dae")
print(bpy.context.selected_objects)
#
the output is only:
[bpy.data.objects["Wheel_1"]]

and I would expect to have something like:
bpy.ops.wm.link_append(directory="/home/pierrick/atrv.blend/Object/",
link=False, files=[{'name': 'ATRV'}, {'name': 'Wheel.4'}, {'name':
'Wheel.3'}, {'name': 'Wheel.2'}, {'name': 'Wheel.1'}])
print(bpy.context.selected_objects)
[bpy.data.objects["ATRV.001"], bpy.data.objects["Wheel.4"],
bpy.data.objects["Wheel.3"], bpy.data.objects["Wheel.2"],
bpy.data.objects["Wheel.1"]]


It would be usefull to have something like "autoselect=True" that we can
find in bpy.ops.wm.link_append.

Cheers,

On Tue, May 24, 2011 at 10:25 PM, Campbell Barton <ideasman42 at gmail.com>wrote:

> eek, mixing blender versions like this sounds, painful!
>
> Committed feature so the datablocks are accessible within the list now.
> r36869.
>
> --- from the docs.
> # the loaded objects can be accessed from 'data_to' outside of the context
> # since loading the data replaces the strings for the datablocks or None
> # if the datablock could not be loaded.
> with bpy.data.libraries.load(filepath) as (data_from, data_to):
>    data_to.meshes = data_from.meshes
> # now operate directly on the loaded data
> for mesh in data_to.meshes:
>    if mesh is not None:
>        print(mesh.name)
>
>
> On Tue, May 24, 2011 at 2:51 PM, Pierrick Koch <pierrick.koch at gmail.com>
> wrote:
> > Thanks,
> > Actually, I'm already using bpy.data.libraries.load(filepath) to generate
> a
> > dictionary of my object (thanks to Blender 2.57) [1],
> > and then, I use the dictionary in Blender 2.56 (since some code I'm using
> is
> > Python3.1 no 3.2, but this is going to be fixed)
> > The probleme with bpy.data.libraries.load(filepath) when used like:
> > ####
> > filepath = '/usr/local/share/data/morse/components/robots/atrv.blend'
> > with bpy.data.libraries.load(filepath) as (src, dest):
> >   for obj in src.objects:
> >     tmp = obj
> >     suffix = 1 # we need to do that in case there is already an object
> with
> > the same name
> >     while tmp in bpy.data.objects.keys():
> >       tmp='%s%03d' % (obj, suffix)
> >       suffix = suffix + 1
> >     dest.objects[tmp] = src.objects[obj]
> > for obj in dest.objects:
> >   bpy.context.scene.objects.link(bpy.data.objects[obj])
> > ####
> > ...is that we loose the parent relationship, so I had to do something
> like:
> > `bpy.ops.object.constraints_clear()`
> > which I'm not sure is the right method to get back that relation, but it
> > works.
> > [1]
> https://github.com/pierriko/morse/blob/master/src/morse/builder/generator.py#L41
> >
> >
> > Cheers!
> >
> > On Tue, May 24, 2011 at 9:05 PM, Campbell Barton <ideasman42 at gmail.com>
> > wrote:
> >>
> >> Take a look at:
> >> bpy.data.libraries.load(...)
> >>
> >> Examples in docs:
> >>
> >>
> http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.BlendDataLibraries.html#bpy.types.BlendDataLibraries.load
> >>
> >> This is intended to be used from python rather then the operator since
> >> it gives a way to inspect whats in the blend and select the data
> >> blocks to add.
> >>
> >> Now you come to mention it, it doesn't give you a list of loaded
> >> datablocks which would be useful.
> >>
> >> On Tue, May 24, 2011 at 11:27 AM, Martin Poirier <theeth at yahoo.com>
> wrote:
> >> >
> >> > The link and append operators set the selection to the objects that
> were
> >> > added. (the active object isn't changed though, careful with that.)
> >> >
> >> > A complete solution (a low level api call) should return all the added
> >> > datablocks (dependencies and all, not just top level objects) so you
> can
> >> > detect all new items.
> >> >
> >> > Martin
> >> >
> >> > --- On Tue, 5/24/11, Pierrick Koch <pierrick.koch at gmail.com> wrote:
> >> >
> >> > From: Pierrick Koch <pierrick.koch at gmail.com>
> >> > Subject: [Bf-python] Ask for: link/append/import returns object(s)
> >> > instance(s)
> >> > To: robotics at blender.org, bf-python at blender.org
> >> > Received: Tuesday, May 24, 2011, 12:52 AM
> >> >
> >> > Hi everyone,
> >> > I am looking for a Python method to link/append/import objects in
> >> > Blender that would give me back some info about what has been appended
> (in
> >> > the best case a list of the imported objects instances)...
> >> > For instance: let say that in a .blend file I have a car made of the
> >> > main structure which contain 4 wheels.
> >> > Code:
> >> > bpy.ops.wm.link_append(directory="/home/pierrick/atrv.blend/Object",
> >> > link=False,
> >> >   files=[{'name': 'ATRV'}, {'name': 'Wheel.4'}, {'name': 'Wheel.3'},
> >> > {'name': 'Wheel.2'}, {'name': 'Wheel.1'}])
> >> > if there was already an object called ATRV, my car will be renamed
> >> > ATRV.001,
> >> > it would be nice to get an instance of the objects, to avoid pasing by
> >> > bpy.data.object
> >> > Same with collada: it would be amazing if:
> >> > Code:
> >> > bpy.ops.wm.collada_import(filepath="/home/pierrick/atrv.dae")
> >> > could return something like:
> >> > Code:
> >> > you_just_imported = {
> >> >   'ATRV': [
> >> >     'Wheel1',
> >> >     'Wheel2',
> >> >     'Wheel3',
> >> >     'Wheel4'
> >> >   ]
> >> > }
> >> >
> >> > Where the string are the real-name of the object in the Blender
> >> > instance.
> >> > With .001 if there was already another object with the same name in
> the
> >> > scene.
> >> > ...
> >> > In fact, I'm working on Robotics
> >> > http://wiki.blender.org/index.php/Robotics:Contents
> >> >
> >> >
> https://github.com/pierriko/morse/blob/master/src/morse/builder/morsebuilder.py#L61
> >> >
> >> >
> https://github.com/pierriko/morse/blob/master/examples/morse/scenarii/ros_example.py
> >> > http://www.openrobots.org/wiki/morse
> >> > ...
> >> > Any idea? shall I open an issue for that?
> >> > Cheers,
> >> > Pierrick
> >> > = This message is cross-posted
> >> > on http://www.blender.org/forum/viewtopic.php?t=20112 =
> >> > -----Inline Attachment Follows-----
> >> >
> >> > _______________________________________________
> >> > Bf-python mailing list
> >> > Bf-python at blender.org
> >> > http://lists.blender.org/mailman/listinfo/bf-python
> >> >
> >> > _______________________________________________
> >> > Bf-python mailing list
> >> > Bf-python at blender.org
> >> > http://lists.blender.org/mailman/listinfo/bf-python
> >> >
> >>
> >>
> >>
> >> --
> >> - Campbell
> >> _______________________________________________
> >> Bf-python mailing list
> >> Bf-python at blender.org
> >> http://lists.blender.org/mailman/listinfo/bf-python
> >
> >
> >
> > --
> > Pierrick Koch
> > Ingénieur GREYC/CNRS, Hanoi
> > +841675357334 [UTC+7]
> > linkedin.com/in/pierriko
> >
> > _______________________________________________
> > Bf-python mailing list
> > Bf-python at blender.org
> > http://lists.blender.org/mailman/listinfo/bf-python
> >
> >
>
>
>
> --
> - Campbell
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>



-- 
Pierrick Koch
Ingénieur GREYC <https://www.greyc.fr>/CNRS <http://www.cnrs.fr>, Hanoi
+841675357334 [UTC+7]
*linkedin.com/in/pierriko* <http://linkedin.com/in/pierriko>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20110525/d3e9535d/attachment.html>


More information about the Bf-python mailing list