Posted: Tue May 29, 2012 12:18 pm
Joined: 18 Apr 2012
Posts: 26
Hi everyone
If we move the cursor above a button or something on Blender, we can see a short and simple code in python. For example :
Python : Scene.frame_current()
so what's the meaning of that? does it mean bpy.ops.Scene?
But, i see on API Doc for Blender 2.62.3 there is no attribute/methode 'frame_current' in bpy.ops.Scene.
I hope some explanations and maybe another examples soi can understand it
huge thanks before!
Posted: Tue May 29, 2012 6:58 pm
Joined: 05 Apr 2009
Posts: 699
Scene.frame_current means, all Scene objects got a property called frame_current (it's not a function!)
first scene in current file:
bpy.data.scenes[0]
currently active scene:
bpy.context.scene
accessing frame_current of active scene:
bpy.context.scene.frame_current
But if you see RenderSettins.filepath, it doesn't mean that there is
bpy.context.rendersettings.filepath
You rather need to have a RenderSettings object, thus you need to know where they are stored, e.g.
bpy.context.scene.render.filepath
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Posted: Wed May 30, 2012 10:19 am
Joined: 18 Apr 2012
Posts: 26
I get it, but i have another question ^^
so, how could you know it will be part of 'context'? i mean there are also bpy.data.scenes or bpy.ops.scene.
and how about SpaceView3D.cursor_location? will it be bpy.context also? or bpy.ops.view3d?
and what i read on some sources in internet, that i should in 3D view with active camera if i want to use bpy.ops.view3d. is that right? what does it mean?
sorry, i have a lot of questions.
again, thanks a loooooooooooooooooot!
Posted: Wed May 30, 2012 4:22 pm
Joined: 05 Apr 2009
Posts: 699
properties are located in bpy.data or bpy.context
bpy.ops allows you to access operators (derived classes from bpy.types.Operator), basically Blender-Python functions.
The problem with operators is, that some require a certain context. If you run a script from text editor or type into pyconsole, the context is SpaceConsole or TextEditor or something. But view3d ops require View3D, the most simple way to run in this context is to hit Spacebar in 3d viewport and type the operator name and run it from there.
Example:
if you wrote and registered your own operator with bl_idname "view3d.do_something", it becomes available as bpy.ops.view3d.do_something()
in Spacebar menu, displayed name equals bl_label
_________________
I'm sitting, waiting, wishing, building Blender in superstition...