[Bf-python] blender python script error

Bassam Kurdali bassam at urchn.org
Thu Nov 7 19:46:09 CET 2013


Some helpful hints that I found useful when learning the api, first few
are from context menu on buttons:
1- right click on a button -> copy data path; gives you the path of the
property based from the datablock it is on, in the copy/paste buffer.
2- right click on a button -> edit source! crib code from blender's UI
itself. (opens in a text editor, you have to browse it to find the file)
3- autocompletion in the py console in blender FTW; lets you explore
almost anything.
4- help - > py api reference; while everything is not perfectly
documented, it is mostly the case, and searchable.
5- outliner-> Datablocks: allows you to brows the data structure in
blender almost exactly as it is in the api.
6- knowing blender helps as you are already familiar with the concepts,
the py api mostly exposes the same stuff you are used to dealing with.

Finally context is a bit of a tricky thing, it passes the same types of
data you get from bpy.data, but this is telling you 'what is my current
state' rather than everything in the file; it is used by operators,
panels, and maybe your own functions. Most easily understood in terms of
tools i.e. : User makes a selection in a viewport(changes context),
Operator runs(for instance, deletes the selection) using that
context,User gets desired result(those vertices are deleted)

>From Python they are cumbersome, I tend to avoid them if I can, or use
them sparingly.
Hope that helped!

On Thu, 2013-11-07 at 19:31 +0100, Brecht Van Lommel wrote:
> For the specific question you are asking, this is probably the page to read:
> http://www.blender.org/documentation/blender_python_api_2_69_1/info_quickstart.html
> 
> bpy.context.scene is the active scene, while bpy.data.scenes['Scene']
> is the scene named 'Scene'. They can be the same, it depends which
> scene the user has selected.
> 
> On Thu, Nov 7, 2013 at 6:53 PM, Cook, Rich <cook47 at llnl.gov> wrote:
> > Thanks, that's helpful.
> > I have been having an issue with the documentation.  It's very hard to
> > explore.  There doesn't appear to be an API reference that actually
> > enumerates and describes all the various functions.  For example,
> > http://www.blender.org/documentation/blender_python_api_2_69_1/info_api_reference.html
> > seems like a good introduction, but I am having trouble understanding the
> > relationship and definition of the various concepts, such as contexts,
> > objects, etc.
> >
> > For example, what is the difference between bpy.context.scene and
> > bpy.data.scenes['Scene'] ?
> > Are they pointing to the same object?  I don't even know where to look for
> > the answer!  Do I need to just practice and keep asking for specifics until
> > it all dawns on me, or is there a really good book or reference to all this?
> >
> > My goal in the end is to do this, all in python:
> >
> > Set up camera, lights, and a camera path.  Import a mesh to view, and
> > animate the scene, swapping out meshes at regular intervals to let the mesh
> > evolve while zooming in, adjusting lights and properties, etc., to capture
> > the best appearance.
> >
> > Thanks!
> >
> > On Nov 7, 2013, at 9:01 AM, Bassam Kurdali <bassam at urchn.org> wrote:
> >
> > Try
> >
> > bpy.context.scene.frame_set()
> >
> > Operators rely on context so it can get hard to satisfy them (you could also
> > try making a timeline window visible). You can override context by paying an
> > optional dict to the operator but I've found this tricky to get right in
> > practice.
> > Oh, and welcome to this blender thing,
> > Bassam
> >
> > "Cook, Rich" <cook47 at llnl.gov> wrote:
> >
> > Hi, I'm new to this here blender thingie.  I was trying some code out to
> > import a few meshes from a science run, and am getting an error I cannot get
> > past.  I was going to import the timesteps as separate meshes, then set
> > keyframes on visibility for each mesh at different timesteps in order to
> > "animate" them.  Per
> > http://blenderscripting.blogspot.de/2011/07/scripted-keyframing-of-hide-hide-render.html
> >
> > I am getting the following error:
> >
> >>>> bpy.ops.anim.change_frame(frame = 5)
> > Traceback (most recent call last):
> >   File "<blender_console>", line 1, in <module>
> >   File
> > "/Volumes/MacProHD/cook47-stuff/Programs/graphics/Blender/blender.app/Contents/MacOS/2.68/scripts/modules/bpy/ops.py",
> > line 188, in __call__
> >     ret = op_call(self.idname_py(), None, kw)
> > RuntimeError: Operator bpy.ops.anim.change_frame.poll() Expected an
> > timeline/animation area to be active
> >
> > I do have a timeline visible in the GUI.  I'm not sure what blender is
> > trying to tell me.
> >
> > I'm probably going to change approaches and just load one mesh at a time,
> > set up the scene, render, and move to the next, etc.  However, my technical
> > curiosity has the best of me here.  I'd like to understand why I cannot set
> > a timestep here.
> >
> > Thanks!
> >
> > <span class="Apple-style-span" style="border-collapse: separate;
> > -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing:
> > 0px; color: rgb(0, 0, 0); font-family: Monaco; font-size: 13px; font
> >
> >
> > --
> > ✐Richard Cook
> > ✇ Lawrence Livermore National Laboratory
> > Bldg-453 Rm-4024, Mail Stop L-557
> > 7000 East Avenue,  Livermore, CA, 94550, USA
> > ☎ (office) (925) 423-9605
> > ☎ (fax) (925) 423-6961
> > ---
> > Information Management & Graphics Grp., Services & Development Div.,
> > Integrated Computing & Communications Dept.
> > (opinions expressed herein are mine and not those of LLNL)
> >
> >
> >
> >
> > _______________________________________________
> > 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