"AttributeError: Writing to ID classes in this context is not allowed"

I have an external app that should sync with blender by Scene.frame_current.
I was thinking to use something like Python threading.Timer (or dummy_threading.Timer) to change frame_current repeatedly from script, but it’s a potentially problematic solution. I’ve also tried to change Scene.frame_current from “draw” method of a new class derived from bpy.types.Panel somehow like that:


class SomeNewPanel( bpy.types.Panel ):
    bl_label = "Yet another panel"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "physics"

    def draw( self, context ):
        layout = self.layout
        scene = bpy.context.scene
        SyncCurrentFrame()

def SyncCurrentFrame():
    newFrame = GetNewFrameNumber()
    if( newFrame ):
        bpy.data.scenes.get( "Scene" ).frame_current = newFrame

and got “AttributeError: Writing to ID classes in this context is not allowed: Scene, Scene datablock, error setting Scene.frame_current”, though it worked perfectly from blender Python console.
Then I’ve run out of ideas, could anyone suggest anything, please? I suppose, I don’t understand something important about whole that new Blender context concept so long as there’s almost no documentation

my explanation was a bit messy, but the major point is that callbacks for some custom property update cannot be used, and SyncCurrentFrame() should be called repeatedly while this script is running

The context will always be invalid for the external app. I don’t think you will be able to change the frame from an external app.

But try this line instead.

bpy.data.scenes[0].frame_current = newFrame

External app doesn’t know anything about blender, python script executed within blender simply fetching some data from that app as XMLRPC client. This is a bit weird but this part is working just fine.

>> bpy.data.scenes[0].frame_current = newFrame
Still “Writing to ID classes in this context is not allowed: Scene, Scene datablock, error setting Scene.frame_current”, unfortunately

strange, this work for me.

import bpy

def GetNewFrameNumber() :
    return 10

def SyncCurrentFrame():
    newFrame = GetNewFrameNumber()
    if( newFrame ):
        bpy.data.scenes[0].frame_current = newFrame
        # or this to use the current scene :
        #bpy.context.scene.frame_current = newFrame


SyncCurrentFrame()

Yes, SyncCurrentFrame() call works outside SomeNewPanel.draw method. But this way it is only called once while I need it to be called repeatedly.
The only way I could find to do that is to put it to “draw” method of something, or as a callback for update of some property that is changing constantly =)
Does anyone know such property?)

Because this is working fine:



def SyncCurrentFrame( self, context ):
    newFrame = GetNewFrameNumber()
    if( newFrame ):
        bpy.data.scenes[0].frame_current = newFrame
        # or this to use the current scene :
        #bpy.context.scene.frame_current = newFrame

...
...

screen = bpy.types.Scene
StringProperty = bpy.props.StringProperty
screen.someString = StringProperty( name="some str", default="str", description = "str", update = SyncCurrentFrame )

But screen.someString has to be changed manually

you cannot change a propr inside a panel cause it is out of context

only way is when it is assign to a button!

otherwise use a global var !

salutations

could you write a simple example, please?
i’m afraid I don’t quite understand what do you mean exactly

don’t see any pop up window here !
any example for that?

only an operator that seems to work with some events!

can you explain how you can make it works!

i did not see this oen before so not certain

in script we can see the modal command !

does it show a pop up window but when
do you have to play with the frame number ?

seems that now we are geginning to ahve some events here !
event.type
any good doc on this on wiki ?

what are the different events we have access now ?

cannot access wiki for 2.58 now !
anything wrong with this API page for scripting

Thanks happy 2.5

The get and set functions will be work.

1 Like