calculation error with tuple >

dim1=craterlist1[index1][3]
print (’ size =’,dim1)

the last list is the size which may be an integer or real number

when doing the divison i get the following error

size = 87
Traceback (most recent call last):
File “moonfeatures2.py”, line 408, in execute
TypeError: unsupported operand type(s) for /: ‘int’ and ‘tuple’

how can i correct this ?

Thanks happy 2.5

how about giving a more complete code snippet. i dont see a division.
the error is : TypeError: unsupported operand type(s) for /: ‘int’ and ‘tuple’

meaning that you are probably doing something like:
>>> mytup = (1, 4)
>>> 1/mytup

where you want to
>>> 1/mytup[1]
0.25

difficult to say without seeing more. give us something we can run, including a very basic division. you’ll probably figure it out that way. simplify the problem to understand it.

sorry so many problems with forum since yesterday!
hope it’s corrected soon!

ok i have a list like this

craterlist1=[]

craterlist1.append ([ ‘Aristarchus’,23.7, 47.4, 40 ])
craterlist1.append ([ ‘Aristoteles’,50.2, 17.4, 87 ])
craterlist1.append ([ ‘Archimede’,29.7, 4.0, 83 ])

  • 100 more

then i got a float properties

i transfert one value from the list [i] to a float properties like size in Kilometer which happen to be an integer but it is transfered to a float propertie

then i have another propertie float for the size or diameter

and need to divide the size / diam to get a value

dim1=craterlist1[index1][3]
print (’ size =’,dim1)

deg1=dim1/bpy.types.Scene.arcsdeg
print (’ degrees =’,deg1)

it’s the division that get some error with tuple!

sorry the script is too long to load up here i can try to PM may be or uplaod on MSN!

but the thing is that i don’t have any tuple !
only list and properties

thanks happy 2.5

do a

>>> print(bpy.types.Scene.arcsdeg.__class__)

what ever it is, it isn’t an int.

for example:


>>> toop = (True,False)
>>> print(toop.__class__)
<class 'tuple'>

or
>>> toop = (True, False)
>>>type(toop)
<class 'tuple'>

show the declaration of arcsdeg

ok i get this
crater name = Aristoteles
@@@@@@@@@@@@@@@@@@@@ <class ‘tuple’>

seems to be a tuple!

but this is a scene propertie type float!

bpy.types.Scene.arcsdeg
how can it be a tuple ?

Float Numbers Properties

bpy.types.Scene.arcsdeg = FloatProperty( # Myfloat is the name of the Float variable = Scene property
name=“Arc Deg”, # Name printed in button
description=“Enter a float”, # Tip tool
attr= “test”,
default = 1738.0,
min = -5000,
max = 5000)

$$$$$$$$$$$
@@@@@@@@@@@@@@@@@@@@ (<built-in function FloatProperty>, {‘attr’: ‘arcsdeg’, ’
in’: -5000, ‘default’: 1738.0, ‘max’: 5000, ‘name’: ‘Arc Deg’, ‘description’: ’
nter a float’})
size = 87
Traceback (most recent call last):
File “moonfeatures2.py”, line 552, in execute
TypeError: unsupported operand type(s) for /: ‘int’ and ‘tuple’

note size = dim1 here

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

how do i convert this int to a float may that’s it
but as i said i transfered this int form the list to a float propertie
seem to be a mixe up here ?

happy 2.5

i’m thinking arcsdeg is a tuple, but you are storing/using a float in one of it’s elements


bpy.types.Scene.arcsdeg = FloatProperty(name="Arc Deg",
                                        description="Enter a float",
                                        attr= "test",
                                        default = 1738.0,
                                        min = -5000,
                                        max = 5000)

so

bpy.types.Scene.arcsdeg[3] 

will prove to be a float. but i’m probably wrong. read this instead:
http://www.chickenblender.com/tuts25/gui_props_discussion.php

very strange!

what does this do
bpy.types.Scene.arcsdeg[3]

is it assigning or getting value ?

and what are the convert formula in python to convert from let say int to float?
or what page is it on python doc !

may be it is this conversion that is done when i assign it to the float propertie !

and why is a float propertie class defined as a tuple ?
may be internaly it is !

Thanks

converting from int to float and back is called ‘typecasting’ (= any datatype to any other compatible datatype). dig around in that link above, it explains how to use FloatProperty ( a blender api specific data type )


&gt;&gt;&gt; dir(bpy.props)
['BoolProperty', 'BoolVectorProperty', 'CollectionProperty', 'EnumProperty', 'FloatProperty', 'FloatVectorProperty', 'IntProperty', 'IntVectorProperty', 'PointerProperty', 'RemoveProperty', 'StringProperty', '__doc__', '__name__', '__package__']

and do a


&gt;&gt;&gt; help(bpy.props.FloatProperty)

ok i found the error

this gives the propertie value
bpy.context.scene.arcsdeg

but i used this instead which gives ?
bpy.types.Scene.arcsdeg

i copied this from and old script and it had error in it !

i guess it 's part of the leaning curve!

Thanks very much anyway


 
import bpy
from bpy.props import *
from mathutils import *
from math import *
 
craterlist1=[]
 
craterlist1.append ([ 'Aristarchus',23.7, 47.4,  40 ])
craterlist1.append ([ 'Aristoteles',50.2, 17.4,  87 ])
craterlist1.append ([ 'Archimede',29.7, 4.0,  83 ])
craterlist1.append ([ 'Archimede',29.7, 4.0,  83 ])
 
 
 
 
bpy.types.Scene.moonrad = FloatProperty(       # Myfloat is the name of the Float variable = Scene property
 name="Moon Radius  Km",           # Name printed in button
 description="Enter a float",         # Tip tool
# attr= "test",
 default = 1738.0,
 min = -5000,
 max = 5000)
 
 
print (' Propertie Moon Radius  Km =',bpy.context.scene.moonrad) # Print data value of the propertie
 
 
 
# Float Numbers Properties
 
bpy.types.Scene.arcsdeg = FloatProperty(       # Myfloat is the name of the Float variable = Scene property
 name="Arc Deg",             # Name printed in button
 description="Enter a float",         # Tip tool
# attr= "test",
 default = 1738.0,
 min = -5000,
 max = 5000)
 
bpy.context.scene['arcsdeg'] = 1.0*(pi/180)*bpy.context.scene.moonrad
 
print (' Propertie Moon Arc Deg =',bpy.context.scene.arcsdeg)  # Print data value of the propertie
 
 
 
last_menu1=1
last_menu2=1
last_menu2=3
 
 
 
dim1=craterlist1[0][3]
 
print ('dim1=',dim1)
print(' @@@@@@@@@@@@@@@@@@@@',bpy.types.Scene.arcsdeg.__class__)
print(' @@@@@@@@@@@@@@@@@@@@',bpy.types.Scene.arcsdeg)
 
print (' size  Dim1=',dim1)
 
deg1=dim1/bpy.types.Scene.arcsdeg
#  deg1=dim1/bpy.types.Scene.arcsdeg
print (' degrees =',deg1)
 
 
 
 
 
 
 

here is a short version with the error

if you run it you’ll see same error!

but when you define a propertie as float i mean how can it be a tuple?

Thanks happy 2.5

&gt;&gt;&gt; myProp = bpy.props.FloatProperty(name="NIII", description="Lancelot", default=2.0, min=0.0, max=12.0)
&gt;&gt;&gt; myProp[1]
{'default': 2.0, 'max': 12.0, 'description': 'Lancelot', 'name': 'NIII', 'min': 0.0}

&gt;&gt;&gt; myProp[1].     (hit ctrl+space)
clear(  copy(  fromkeys(  get(  items(  keys(  pop(  popitem(  setdefault(  update(  values(

&gt;&gt;&gt; myProp[1].get('default')
2.0

i really dont know :slight_smile:
this was an interesting read : http://blenderartists.org/forum/showthread.php?t=207251&p=1775340&viewfull=1#post1775340

You are confusing two different things: the definition of the property, and a particular value of the property.

The property is defined by constructing an object using one of the functions in bpy.props, e.g. bpy.props.FloatProperty. You attach this object to a class, e.g. bpy.types.Scene, by setting it as the value of a custom attribute of that class. Then in an instance of that class, e.g. bpy.context.scene, Blender will attach a custom attribute of the same name to hold the actual value of the property.

did not use these propr things but like to learn more about theses?!

so what is the difference bewteen them

bpy.types.Scene.moonrad = FloatProperty( and myProp = bpy.props.FloatProperty(name
i mean are they same thing all properties?
and where do you use one or the other ?

and are these prop use only with class operator may be !

Thanks happy 2.5

If you don’t understand the difference between classes, instances and attributes, perhaps you need to go through a Python tutorial.