[Bf-python] Changing the scene in a script run from the command line

Martin Poirier theeth at yahoo.com
Fri Sep 10 00:21:09 CEST 2010


It's just not a keyword argument, so like this:

bpy.ops.wm.collada_export({"scene":bpy.data.scenes['scene_to_export']}, filepath='output_file.dae')

If you need to specify a context string ("INVOKE_AREA", for example) it goes before the context dict argument.

Martin

--- On Thu, 9/9/10, Tom Haines <thaines at gmail.com> wrote:

> From: Tom Haines <thaines at gmail.com>
> Subject: Re: [Bf-python] Changing the scene in a script run from the command line
> To: "Blender Foundation Python list" <bf-python at blender.org>
> Received: Thursday, September 9, 2010, 6:06 PM
> Martin,
> 
> I had wondered about doing that - it is implied you can,
> but nowhere
> is the how given! However, I just tried that and it didn't
> work - gave
> a
> 
> TypeError: Converting py args to operator properties: :
> keyword "C" unrecognized
> 
> I also tried a lowercase c and context, but no luck either
> way. Thanks
> though - I imagine you are close:-)
> 
> Cheers,
> Tom
> 
> 
> 
> On 9 September 2010 22:48, Martin Poirier <theeth at yahoo.com>
> wrote:
> > Hi,
> >
> > --- On Thu, 9/9/10, Tom Haines <thaines at gmail.com>
> wrote:
> >
> >> Hello all, and especially
> >> ideasman_42, who it was suggested to me
> >> might be the person most likely to be able to help
> me on
> >> irc.
> >> Unfortunately with me being in the UK and him in
> Australia
> >> the time
> >> zones are kinda problematic, hence using the
> mailing list.
> >>
> >> I am exporting a collada file from the command
> line with
> >> Blender 2.5,
> >> specifically by running a .py file using the -P
> option,
> >> with -b to
> >> avoid the gui appearing (Though it also fails if
> the -b
> >> option is
> >> omitted.). This works, but the collada exporter
> exports
> >> entire scenes,
> >> hence I want to set the scene before doing the
> export. My
> >> best effort
> >> consists of:
> >>
> >> bpy.context.screen.scene =
> >> bpy.data.scenes['scene_to_export']
> >>
> bpy.ops.wm.collada_export(filepath='output_file.dae')
> >>
> >> but the first line does not work (I have tried
> other ways,
> >> but they
> >> all fundamentally involve setting the scene of the
> current
> >> screen.).
> >> It fails silently, and neither changes the scene
> value of
> >> the screen
> >> or bpy.context.scene, which is what I really want
> to
> >> change. Looking
> >> at the api the only place I can see where the
> option to set
> >> the scene
> >> is as part of a screen, and whilst that works when
> running
> >> the gui
> >> (i.e. if entered into the console.) when run from
> the
> >> command line it
> >> exports the contents of whatever scene was set
> when the
> >> .blend file
> >> was saved, rather than the desired scene.
> >
> > You should be able to do it like this (assuming I
> don't mess up the syntax):
> >
> >
> bpy.ops.wm.collada_export(C={"scene":bpy.data.scenes['scene_to_export']},
> filepath='output_file.dae')
> >
> > This sets up a custom context for that operator, its
> values will overwrite whatever is in bpy.context.
> >
> > Martin
> >
> >
> > _______________________________________________
> > 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
> 





More information about the Bf-python mailing list