How to assign IntProperty

i got this from code snippet and does not look it works anymore!

bpy.types.Scene.edgeInt1 = IntProperty(
name=“Integer”,
description=“Enter an integer”,
default = 2,
min = -4,
max=10,
subtype=‘UNSIGNED’)

#bpy.context.scene.[‘MyInt’] = 22

so how do you assign or re assign a new value to an integer propertie after doing some calculations ?

i know how to do it for float number but cannot do it for integer propertie!

Thanks happy 2.5

I ran this in the console:



>>> bpy.types.Scene.edgeInt1 = bpy.props.IntProperty(
... name="Integer",
... description="Enter an integer",
... default = 2,
... min = -4,
... max=10,
... subtype='UNSIGNED')

>>> bpy.context.scene.edgeInt1
2

>>> bpy.context.scene.edgeInt1 = 3
>>> bpy.context.scene.edgeInt1
3


it strikes me you’ve got the names mixed up:

use:


bpy.context.scene.edgeInt1 = 22

then you’ll see that the property’s value is 10 :stuck_out_tongue:

EDIT: aaah ilent beat me to it

not working !
i testes several ways t do it and not working

ok so here is the script i tried this ?
there is on mistake or more which i cannnot find why it is doing theses errors!


 
 
import bpy
from bpy.props import *
from mathutils import *
from math import *
 
 
 
 
bpy.types.Scene.vertInt1 = IntProperty(
 name="Integer",
 description="Enter an integer",
 default = 2,
 min = -4,
 max=10,
 subtype='UNSIGNED')
 
print ('Propertie vertInt1 =',bpy.context.scene.vertInt1 )   # Print data value of the Integer propertie
 
bpy.types.Scene.edgeInt1 = IntProperty(
 name="Integer",
 description="Enter an integer",
 default = 2,
 min = -4,
 max=10,
 subtype='UNSIGNED')
 
 
 
#bpy.context.scene.['edgeInt1'] = 22
 
bpy.context.scene.edgeInt1 = 3
#py.context.scene.edgeInt1
 
print ('Propertie edgeInt1 =',bpy.context.scene.edgeInt1 )   # Print data value of the Integer propertie
 
bpy.types.Scene.faceInt1 = IntProperty(
 name="Integer",
 description="Enter an integer",
 default = 2,
 min = -4,
 max=10,
 subtype='UNSIGNED')
 
 
 
 
print ('Propertie faceInt1 =',bpy.context.scene.faceInt1 )   # Print data value of the Integer propertie
 
############
 
object=bpy.context.active_object
print ('Active object =  =',object )
myMesh = object.data
print ('data  =',myMesh )
print (' myMesh.faces =',myMesh.faces)
print ()
#face1=bpy
 
 
 
##########
 
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_menu0,last_menu1, last_menu2,last_menu3,last_menu4,check1        # Access global Var to find the last operation
 
  layout = self.layout
  scene = context.scene
 
  object=bpy.context.active_object
  print ('Active object =  =',object )
  myMesh = object.data
  vert_count = bpy.context.active_object.data.vertices
  edge_count = bpy.context.active_object.data.edges
  face_count = bpy.context.active_object.data.faces
 
# ['MyInt'] = 17
 
 
  print ('vert_count =', len(vert_count) )
# bpy.context.scene.featureminlat
#  bpy.context.scene.['vertInt1']= len(vert_count)
#  bpy.scene.vertInt1= len(vert_count)
  bpy.context.scene.edgeInt1= len(vert_count)
#  bpy.context.scene['vertInt1']= len(vert_count)
#  bpy.context.scene['edgeInt1']=  len(edge_count)
#  bpy.context.scene['faceInt1']=  len(face_count)
 
  col = layout.column()
  st1=' Object Name = ' +object.name
  col.label(st1, 'LAMP_DATA')
 
  col.separator()
  col.prop(scene, "vertInt1", text = "Vert Count")
  col.prop(scene, "edgeInt1", text = "Edge Count")
  col.prop(scene, "faceInt1", text = "Face Count")
 
 
 
##########
 
 
 
class OBJECT_OT_CustomButton1(bpy.types.Operator):
 bl_idname = "OBJECT_OT_CustomButton1"
 bl_label = "Execute  Erase all lamps in Scene"
 __doc__ = "Simple Custom Button"
 
 def invoke(self, context, event):
             # when the button is press it prints this to the  Console
  print ()
  print("  )))))))))))))))))     Custom Button1  ))))))))))))))  ")
  print ()
 
 
  return{'FINISHED'}    
 
##################
 
 
 
 
 
 
 
 
 
 

see error on line 101 for interger assingmet
still not working there may be because of the scene label but not certain tried different things and still error !

Thanks for any help
and happy 2.5

property (not propertie, use ‘ie’ for multiple ‘properties’ )
seems to work now.


vertInt1 = len(vert_count)

import bpy
from bpy.props import *
from mathutils import *
from math import *

#Declare some scene properties
bpy.types.Scene.vertInt1 = IntProperty(
    name="Integer", description="Enter an integer",
    default = 2, min = -4, max=10, subtype='UNSIGNED')
 
bpy.types.Scene.edgeInt1 = IntProperty(
    name="Integer", description="Enter an integer",
    default = 2, min = -4, max=10, subtype='UNSIGNED')
 
bpy.types.Scene.faceInt1 = IntProperty(
    name="Integer", description="Enter an integer",
    default = 2, min = -4, max=10, subtype='UNSIGNED')

#Initialize scene property with a value
bpy.context.scene.edgeInt1 = 3

#print data values
print('Property vertInt1 =', bpy.context.scene.vertInt1)
print('Property edgeInt1 =', bpy.context.scene.edgeInt1)
print('Property faceInt1 =', bpy.context.scene.faceInt1)

##########
object=bpy.context.active_object
print('Active object =  =',object)
myMesh = object.data
print('data  =',myMesh)
print(' myMesh.faces =',myMesh.faces,'
')
##########

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 = "TOOL_PROPS"  
    bl_show_header=True  
  
    def draw(self, context):
 
        global last_menu0,last_menu1, last_menu2,last_menu3,last_menu4,check1        
        # Access global Var to find the last operation
 
        layout = self.layout
        scene = context.scene
 
        object=bpy.context.active_object
        print('Active object =  =',object)
        myMesh = object.data
        vert_count = bpy.context.active_object.data.vertices
        edge_count = bpy.context.active_object.data.edges
        face_count = bpy.context.active_object.data.faces
  
        print('vert_count =', len(vert_count))
#       bpy.context.scene.featureminlat
#       bpy.context.scene.['vertInt1']= len(vert_count)
#       bpy.scene.vertInt1= len(vert_count)
        vertInt1 = len(vert_count)
#       bpy.context.scene['vertInt1']= len(vert_count)
#       bpy.context.scene['edgeInt1']=  len(edge_count)
#       bpy.context.scene['faceInt1']=  len(face_count)
 
        col = layout.column()
        st1=' Object Name = ' +object.name
        col.label(st1, 'LAMP_DATA')
    
        col.separator()
        col.prop(scene, "vertInt1", text = "Vert Count")
        col.prop(scene, "edgeInt1", text = "Edge Count")
        col.prop(scene, "faceInt1", text = "Face Count")
  
##########
  
 
class OBJECT_OT_CustomButton1(bpy.types.Operator):
    bl_idname = "OBJECT_OT_CustomButton1"
    bl_label = "Execute  Erase all lamps in Scene"
    __doc__ = "Simple Custom Button"
 
    def invoke(self, context, event):
             # when the button is press it prints this to the  Console
        print()
        print("  )))))))))))))))))     Custom Button1  ))))))))))))))  ")
        print()
        return{'FINISHED'}

ok so you use only

vertInt1 = len(vert_count)

instead of

bpy.context.scene.vertInt1= len(vert_count)

but this is working with float propertie!

why is it not working with integer propertie?
anything special we need to know here about integer !

and is it samethng with let say string may be?

now i 'v seen another example inside the draw function where it was using the self value instead!
so there seems to be more then one way to access theses properties !

Thanks happy 2.5

i’m not sure i understand the question, or the problem.
dig deeper
http://www.blender.org/documentation/250PythonDoc/bpy.types.FloatProperty.html

actually, i dont think my answer was incorrect. if you do a


vertInt1 = len(vert_count)
print(type(vertInt1))

you’ll see that all we did was overwrite that complete variable with an int. we need to do something else, sorry. bbl

will post later.

]ok here is revised sript with values shown in panel for vert edge face
but it does not look like the value are being assign to the properties
by using this vertInt1 = len(vert_count)

any idea why it is not transfered to the integer property?


import bpy
from bpy.props import *
from mathutils import *
from math import *
#Declare some scene properties
bpy.types.Scene.vertInt1 = IntProperty(
name="Integer", description="Enter an integer",
default = 2, min = -4, max=10, subtype='UNSIGNED')
 
bpy.types.Scene.edgeInt1 = IntProperty(
name="Integer", description="Enter an integer",
default = 2, min = -4, max=10, subtype='UNSIGNED')
#print ('Propertie edgeInt1 =',bpy.context.scene.edgeInt1 ) # Print data value of the Integer propertie
 
bpy.types.Scene.faceInt1 = IntProperty(
name="Integer", description="Enter an integer",
default = 2, min = -4, max=10, subtype='UNSIGNED')
#Initialize scene property with a value
bpy.context.scene.edgeInt1 = 3
 
 
#print data values
print('Property vertInt1 =', bpy.context.scene.vertInt1)
print('Property edgeInt1 =', bpy.context.scene.edgeInt1)
print('Property faceInt1 =', bpy.context.scene.faceInt1)
print ()
 
##########
object=bpy.context.active_object
print('Active object = =',object)
myMesh = object.data
print('data =',myMesh)
print(' myMesh.faces =',myMesh.faces,'
')
##########
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 = "TOOL_PROPS" 
bl_show_header=True 
 
def draw(self, context):
 
global last_menu0,last_menu1, last_menu2,last_menu3,last_menu4,check1 
# Access global Var to find the last operation
 
layout = self.layout
scene = context.scene
 
object=bpy.context.active_object
print('Active object = =',object)
myMesh = object.data
vert_count = bpy.context.active_object.data.vertices
edge_count = bpy.context.active_object.data.edges
face_count = bpy.context.active_object.data.faces
 
print('vert_count =', len(vert_count))
print('edge_count =', len(edge_count))
print('face_count =', len(face_count))
# bpy.context.scene.featureminlat
# bpy.context.scene.['vertInt1']= len(vert_count)
# bpy.scene.vertInt1= len(vert_count)
vertInt1 = len(vert_count)
edgeInt1 = len(edge_count)
faceInt1 = len(face_count)
# bpy.context.scene['vertInt1']= len(vert_count)
# bpy.context.scene['edgeInt1']= len(edge_count)
# bpy.context.scene['faceInt1']= len(face_count)
 
col = layout.column()
st1=' Object Name = ' +object.name
col.label(st1, 'LAMP_DATA')
 
col.separator()
col.prop(scene, "vertInt1", text = "Vert Count")
col.prop(scene, "edgeInt1", text = "Edge Count")
col.prop(scene, "faceInt1", text = "Face Count")
 
##########
 
 
class OBJECT_OT_CustomButton1(bpy.types.Operator):
bl_idname = "OBJECT_OT_CustomButton1"
bl_label = "Execute Erase all lamps in Scene"
__doc__ = "Simple Custom Button"
 
def invoke(self, context, event):
# when the button is press it prints this to the Console
print()
print(" ))))))))))))))))) Custom Button1 )))))))))))))) ")
print()
return{'FINISHED'}
 
 
 
[/CODE
 
look at values in panel buttons
not having the right values from int  property!
 
 
looks like integer are more difficult to deal with then float ones!
 
Thanks and happy 2.5

i suspect this might a bug somewhere in there with integer property!

This properties are defined at scene level and shoul be available everywhere!

let me know if you find a bug here !

happy 2.5

nope. i made a big mistake


vertInt1 = len(vert_count)
edgeInt1 = len(edge_count)
faceInt1 = len(face_count)

turns vertInt1, etc into Ints, they are not IntProperties anymore at that point.

let me get this straight, depending on some crater choice, you want to set the default parameter of the FloatProperty slider… or IntProperty…

i’ll keep the property definitions short, as to keep the suggestion generic.

>>> thisProp = bpy.props.FloatProperty(name="somename", default=1.3)
>>> thisProp
(<built-in function FloatProperty>, {'default': 1.3, 'name': 'somename'})
>>> thisProp[0]
<built-in function FloatProperty>
>>> thisProp[1]
{'default': 1.3, 'name': 'somename'}

>>> type(thisProp[1])
<class 'dict'>

>>> thisProp[1]['default']
1.3

ok, now lets say we want to assign a different value to default


>>> thisProp[1]['default'] = 2.0
>>> thisProp
(<built-in function FloatProperty>, {'default': 2.0, 'name': 'somename'})

wait you are using prop here i’m not using theses
i use the scene properties!

whjat’s the differences with scene prop?

i see the properties structure is like a dictionnary !
interesting to know that and i take note of this fact

and supposed same thing for and integer property!

i’ll try this in the intefer property for the panel and see if this work or not!

thanks

maybe you can correct the spelling in your thread title to (so other people can find it):
How to assign IntProperty

change title should be good now!

still what is the difference between prop and scene property?

i did another little test and if i change the property value it is like the default value does not exit anymore!
it takes the last value assign !

see code


import bpy
from bpy.props import *
from mathutils import *
from math import *
 
print (' Prop')
 
thisProp = bpy.props.FloatProperty(name="somename", default=1.3)
print ('Propertie thisProp =',thisProp  )   # Print data value of the Integer propertie
print ()
thisProp  =222
print ('Propertie thisProp =',thisProp  )   # Print data value of the Integer propertie
 
 
 
 
 
print (' Scene Float Property')
# Declare some scene properties
print ()
 
bpy.types.Scene.MyFloat1 = FloatProperty(     # Myfloat is the name of the Float variable = Scene property
 name="Float",         # Name printed in button
 description="Enter a float",  #  Tip tool
 default = 33.33,
 min = -100,
 max = 10000)
 
print ('Propertie MyFloat1 =',bpy.context.scene.MyFloat1 )   # Print data value of the Integer propertie
bpy.context.scene.MyFloat1=1777
 
print ('Propertie MyFloat1 =',bpy.context.scene.MyFloat1 )   # Print data value of the Integer propertie
 
print ()
print (' Integer Property')
print ()
bpy.types.Scene.vertInt1 = IntProperty(
 name="Integer", description="Enter an integer",
 default = 2, min = 0, max=10000, subtype='UNSIGNED')
 
print ('Propertie vertInt1 =',bpy.context.scene.vertInt1 )   # Print data value of the Integer propertie
bpy.context.scene.vertInt1=11
print ('Propertie vertInt1 =',bpy.context.scene.vertInt1 )   # Print data value of the Integer propertie
 
 
 
 

for float there are theses commands i had unless this has been changed!

Propertie Class

print (‘MyFloat1 =’,bpy.types.Scene.MyFloat1)
Print Class of the propertie

Propertie valueprint (‘Propertie MyFloat1 =’,bpy.context.scene.MyFloat1 )
Print data value of the propertie

Propertie assign

bpy.context.scene[‘MyFloat1’] = 22.6

so i assumed it was the samething for integer scene property

Thanks happy 2.5

The word, in English, is property, not propertie. :yes:

if you do


1.  thisProp = bpy.props.FloatProperty(name="somename", default=1.3)
2.  thisProp = 222

in line 2 you are assigning a standard python Int data type to the object called thisProp. ( i know i suggested that earler, before it became obvious) i doubt you want to do that. 222 isn’t even a float. if you did a thisProp.class now it would be int.


3.   thisProp[1]['default'] = 222.0
4.   thisProp
(<built-in function FloatProperty>, {'default': 222.0, 'name': 'somename'})

ok i don’t know anymore, how to explain :slight_smile:
http://www.pasteall.org/18477/python

ok. i think http://www.pasteall.org/18477/python does explain things,

ricky, to make your code easier to read do

print('blaa'....'blaaah')          # no spaces

these are the same


bpy.context.scene.MyFloat1=1777
bpy.context.scene.MyFloat[1]['default']=1777  

these are not.


thisProp = bpy.props.FloatProperty(name="somename", default=1.3)

thisProp[1]['default'] = 222        # 222.0
thisProp = 222                          #turns thisProp into an int

so yeah, weird.


>>> thisProp = bpy.props.FloatProperty(name="somename", default=1.3)
>>> thisProp = 222
>>> thisProp
222

>>> type(thisProp)
<class 'int'>

>>> thisProp = bpy.props.FloatProperty(name="somename", default=1.3)
>>> thisProp[1]['default'] = 222
>>> thisProp
(<built-in function FloatProperty>, {'default': 222, 'name': 'somename'})

with the last option you would need to be careful.

i should not have tried to pass an int value to the float value my mistake !

but you have introduce something new which i never really use before in script
this —> thisProp = bpy.props.FloatProperty(

can you clarify this thing!
in my script i try to use only scene property
so what are theses bpy.props.FloatProperty doing ?

is it equivalent to a scene property or another form of property or a new variable type may be ?

cause i did not see or use theses before and was not part of the codesnippet intro PDF file
so not certain what it does or not ?

i’ll try to see if i can understand more form last code snippet
and think about it till tomorrow!

in any case the only thing i’d like is be able to assign a calculated value to an integer property and it’s not working !

i can do it for a float property but not for this integer property !

Thanks happy 2.5

sorry just remember something here

property are defined at scene level and saved to the file
so when you reload it will use the existing defined property from the file
and not re create a new one !

so i guess you need to remove the property before re defining one!

$$$$$$$$$$$$$$$$$$$$

did a quick test here with latest code from pastall

i remove the float assing value

and got these lines instead

print(‘Property MyFloat1 =’,bpy.context.scene.MyFloat1)
#bpy.context.scene.MyFloat1=1777

print(‘Property MyFloat1 =’,bpy.context.scene.MyFloat1,’
‘)
print(’ Integer Property
')

and if you run this the 2 print line for the float value are showing the 1777 value on console
and it’s not even part of the script anymore

Property thisProp = 222 thisProp is now a <class ‘int’>
Scene Float Property
Property MyFloat1 = 1777.0
Property MyFloat1 = 1777.0
Integer Property

don’t undertand why it is still seeing this value !

happy 2.5