yes but how do you acces it from inside a function?
i tried to ways and not working in this script not certain why !
cause i’m certain i did this before and it work ok!
or may be it’s a new bug !
i’ll re do some testing again and see what happen here!
with the long one
bpy.context.scene[‘MyCkeckbox1’] = False
get this error
File “lightsetupricky3.py”, line 463, in eraserobjects1
RuntimeError: Writing to ID classes in this context is not allowed: Scene, Scen
datablock, error setting Scene.MyCkeckbox1
this is same line then i have in the main which seems ok there
but no inside this function!
First, is MyCkeckbox1 really spelled correctly? Notice the k instead of an h.
Now, I think, if you want to access your property, you should do this :
bpy.context.scene.MyCkeckbox1 = False
And when you do this for the first time:
bpy.context.scene['MyCkeckbox1'] = False
I don’t think you are initializing it to false. I think you should do this when you define your property instead, if you want it to initialize to false :
bpy.types.Scene.MyCkeckbox1 = BoolProperty(
name=“Boolean”,
description=“True or False?”,
default=False)
The first line MyCkeckbox1=False does not give any error but does not reset the Flag!
In the case where the name MyCkeckbox1 would not exist, you would anyway create a new Bool variable. This is why it does not complain.
ok did a new little script to see what’ happenign with checkbox!
here it is with a in tool pro panel
###########
import bpy
from bpy.props import *
from mathutils import *
from math import *
# Ckeck Box Properties
bpy.types.Scene.MyCheckbox1 = BoolProperty(
name="Boolean",
description="True or False?")
#bpy.context.scene['MyCheckbox1'] = False
bpy.context.scene.MyCheckbox1 = False
# From code snippet PDF
#bpy.types.Scene.MyBool = BoolProperty(
#name="Boolean",
#description="True or False?")
#bpy.context.scene.['MyBool'] = True
print ()
print (' checkbox main ************** = ',bpy.context.scene['MyCheckbox1'])
print ()
bpy.context.scene.MyCheckbox1 = True
print (' checkbox main ************** = ',bpy.context.scene['MyCheckbox1'])
print ()
bpy.context.scene.MyCheckbox1 = False
print (' checkbox main ************** = ',bpy.context.scene['MyCheckbox1'])
print ()
class Panellightsetup1(bpy.types.Panel): # This is the panel
'''Panel'''
bl_label = "Light setup Panel" # Header Panel's name
bl_space_type = "VIEW_3D" # in 3D view
# bl_region_type = "TOOLS" # in tool shelf
bl_region_type = "TOOL_PROPS"
bl_show_header=True
# http://www.blender.org/documentation/250PythonDoc/bpy.types.Panel.html#bpy.types.Panel
def draw(self, context):
global last_menu1 # Access global Var to find the last operation
layout = self.layout
scene = context.scene
col = layout.column()
col.label(' Testing Checkbox', 'LAMP_DATA')
col.prop(scene, "MyCheckbox1", text = "Erase all Lamps in Scene ")
if scene.MyCheckbox1: #
col.label(' In if test Checkbox = True', 'LAMP_DATA')
print ()
print (' checkbox if test draw ************** = ',bpy.context.scene['MyCheckbox1'])
print (' Check Button =',scene.MyCheckbox1)
str1=str(bpy.context.scene['MyCheckbox1'])
print ('string=',str1)
# scene.MyCheckbox1=False # not working
bpy.context.scene.MyCheckbox1 = False
print (' endif test ************** = ',bpy.context.scene['MyCheckbox1'])
# col.label(' Value Checkbox =', str1)
# elif scene.MyCheckbox1=False:
elif scene.MyCheckbox1==0:
col.label(' In if test Checkbox = False', 'LAMP_DATA')
print (' checkbox if test draw ************** = ',bpy.context.scene['MyCheckbox1'])
###########
can you explain why i cannot change the value inside panel?
i an do it outside of it in main part !
I opened in Blender the Text Editor and copy paste there the above code (tip: you can horizontally scroll the text editor with middle mouse!) and clicked on Run Script. The checkbox showed in the Tool Shelf and when I clicked it to check I could see the error in the python terminal (the terminal external to blender in windows): RuntimeError: Writing to ID classes in this context is not allowed: Scene, Scene datablock, error setting Scene.MyCheckbox1
It says you can’t assign a value to the bool property in a panel. You are in the draw function that draws the panel, perhaps changing that value would force to enter again the draw function creating a forever loop or something like that so they placed restrictions. Whatever it be is not permitted.
But I don’t understand what you are trying. If you want to answer to the user checking the checkbox doing some task and then unchecking the checkbox to the user be able to check again, then you need a button and not a checkbox. A checkbox is the user the only one that must check or uncheck and then the program acts accordingly.
but you can change other properties like float or integer ect. i think if i remember well.
i mean it’s the idea of Scene properties to be available anywhere with greater scope then global variables
but your saying that in the case of checkbox it is not allowed to change it inside panel of even a function!
cause i did try it also in a function and it does not work also!
my idea was to check the check box in GUI then execute a function for calculations ect…
then uncheck the checkbox at the end of the function so in GUI it is back to false
like doing the function only ounce instead of several times!
Hum but looks like it cannot be done that way!
now is there a way to use an operator with checkbox may be and how ?
or i can use a normal button with operator to do that except it does not look like a checkbox!
but can add label word like execute or run in button to ececute only ounce the calculations or changes on objects in scene !
I think that this was possible in earlyer version (2.55 and before) but now it seems to be a restriction intentionnaly placed there.
Why I say that? I had a very simple script that I published on the upload tracker that did something similar and a developer said :
“… it looks curious how you mingle functionality and layout stuff in one function.”
This script is stucked in the state of evaluation to go to contrib tracker since before christmas. since then, 2.56 has been released and now the script gives me the same error as you said. And I met it in another more recent script.
So it seems that it is no more possible to access a property inside a draw function. I think this has been intentionally put there for avoiding contributer to put fuctionnality into a draw function. For better design. If it’s not the case, than it may be a bug that the dev should know.
@Everyone
Now that this is said, we need to know (and this will be useful for RickyBlender as well as everyone) how to execute code for every redraw of a window. This is why some functionality code is put into a draw function(for it to occur at every redraw).
Is there a better way to make code exectuted at every redraw than to put the code inside a panel draw function(or a header draw function cause it’s the same)?
You can do that with a global bool variable and then check the status of the bool property and the bool global this way: if bool property is true or bool global is true then do something (just now you must be doing: if bool property is true then do something)
Rombout : I’m far to be expert, but perhaps you can do that on one checkbox (and the other of course), that will call a function (you must define that function of course)
value = BoolProperty(name=“Value”, update=bool_property_update)
You cannot set values in a draw function. What warnotte posted is correct. You want to use an update function. In the update function for the first property, set the value for the second property.