2
$\begingroup$

I'm trying to enter dimensions of an object. I'm using the code below. It does not recognize the variables XX or YY and get the error: Key "XX" not found Any clues??

import bpy
from bpy.props import FloatProperty
from bpy.props import IntProperty
from bpy.types import Operator
import os

#create variables 
bpy.types.Scene.XX=FloatProperty(name="XX", default=10.0, description="Enter XX") #XX
XX = bpy.context.scene['XX']
#print (XX) 

bpy.types.Scene.YY=FloatProperty(name="YY",default=4, description="Enter YY") #YY
YY = bpy.context.scene['YY']
#print (YY) 
#Draw the panel buttons for user inputs
class CustomPanel(bpy.types.Panel):
    bl_label = "Wall"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    def draw(self, context):
        layout = self.layout
        row = layout.row()
        row.label(text="Dimensions:")
        Wall_layout=self.layout.column(align=True)
        Wall_layout.prop(context.scene, 'XX') #XX
        Wall_layout.prop(context.scene, 'YY') #YY

def register():
    bpy.utils.register_class(CustomPanel)

def unregister():
    bpy.utils.unregister_class(CustomPanel)

if __name__ == "__main__":
    register()
$\endgroup$
  • 1
    $\begingroup$ you should access it like this : scene.XX $\endgroup$ – Chebhou May 3 '15 at 23:27
1
$\begingroup$

You have defined a RNA property, it will be available on any instance of this class( all scenes will have this property ) , to access this property use the following line :

XX = context.scene.XX
# in the UI
row.prop(context.scene, 'XX')

you can also define an ID property which will be available only on this scene :

context.scene['XX'] = 10.0
print(context.scene['XX'])
#in UI
row.prop(context.scene, '["XX"]')

To learn more about this Topic refer to this DOC page : RNA properties versus ID properties

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks, this works with the addition of: XX=bpy.context.scene.XX $\endgroup$ – Steven Schell May 4 '15 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.