loosing prop ?

if you defined a float prop properties

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

then if you assign an int to this var

thisprop=222

then if you try to print the float propertie then it looks like you lost the flot properties it does not exist anymore ??

is this normal or shold it simply gives a warning instead?

can someone explain what happening here?

thanks for any help
happy 2.5

Is this within a class?

Then use the ‘self’ notation:


class something(bpy.types.Operator):
    bl_idname = "something.somewhere"
    bl_label = "Doing it, doing it..."
    
    name = bpy.props.StringProperty()
    
    def execute(self, context):
        print("Name:", self.name)
        return {'FINISHED'}

Whereas if your doing the more global variation, then:


bpy.types.Scene.STR_name = StringProperty(name="STR_name", default="")
...
layout.prop(context.scene, "STR_name", text="Name")
...
print("Name:",context.scene.STR_name)
...
# Also I think
bpy.context.scene.STR_name

EDIT:

BTW, what your code seems to do is create a new variable local to the place it was called (e.g. function block), so no error is seen or known because the scope is deifferent.

no this was in the console
seems that before it was changing the propertie type but now it cancels it and it disappears
which is strange !

i’m trying to modify and old script and better understand to modify the old script to update it to the latest built
but not working yet see other thread for propertie update
hope i can make this old sript works again it is about file and path prop
but seems that scene string does not ahve these atributes anymore

so not certain how to bring it back!

thanks


>>> bpy.types.Scene.thisProp =bpy.props.FloatProperty(name="somename", default=1.3)
>>> print(bpy.context.scene.thisProp)
1.2999999523162842

yes this will work

then try to assign an int to it

it will be lost !

salutations

Had no problems there…


>>> bpy.types.Scene.thisProp =bpy.props.FloatProperty(name="somename", default=1.3)
>>> n=int(3)
>>> bpy.context.scene.thisProp=n
>>> print(bpy.context.scene.thisProp)
3.0

But I would have typecast it when assigning it:


>>> bpy.context.scene.thisProp=float(n)

would like to better understand the difference between prop and scene prop

how can you assign a scene propr to a prop?

thanks
happy 2.5

This module defines properties to extend blenders internal data, the result of these functions is used to assign properties to classes registered with blender and can’t be used directly.

http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.props.html

when you define prop in an operator class
it can be used to define buttons so it can be directly use!
but not available outside the class !

but if you define a sceneproperties then it is available everywhere?

so not certain what you mean with

assign properties to classes registered with blender and can’t be used directly?

also youc an define a float propr and or a scene float properties
sow what is the difference apart of scope ?

thanks

i just found an old file with another type of propertie

dont know if it is still usefull

Object properties

bpy.types.Object.MyInt2 = IntProperty(name=‘int2’,default=0)

have you seen this one ?

what is this not a prop or a scene property?

i made a special little script to test all of these
i’ll upload it when i get enough data

salutations

then if you try to print the float propertie then it looks like you lost the flot properties it does not exist anymore?

That is true, it is the nature of assignment.


thisProp =bpy.props.FloatProperty(name="somename", default=1.3)
thisProp = 22
thisProp = bpy.data.objects["Cube"]
thisProp = "I am no longer an INT or Object, I am a string!"

so when you assign it will change the value but also the type of var

so if you assign an int to a float then it becomes an int prop or a simple integer number?

another point of view

if you define a float var like x1=float(2.43)
x1 should be define like a float not an integer var!

but then if you assign an int to it
it means this float var becomes an int var?

so got to be carefull i guess

thanks

Python scripting is mutable because of the way it’s variables are stored, like most interpreted languages.

You answered your own question, the scope is the difference.

Try running this from a script window:


import bpy
bpy.ops.object.duplicate(linked=True)
bpy.ops.transform.translate(value=(3,0,0))
bpy.context.space_data.pivot_point = 'CURSOR'
bpy.ops.transform.rotate(value=(0.7855,), axis=(0.0, 0.0, 1.0))

The error refers to being executed in the wrong context, it can’t see the attribute in it’s scope.

To get it to work, you must provide access to the correct scope…

nice to see the error
you have the working codes for thsi example with proper scope!

but this mutable things is not like in old program like basci or fortran
where you var were defined at the beginning like real or int complex
and it would stay like tht for the whole program

python is more evolved i guess but can trap you more often ! LOL

but what about the difference between prop and scene properties
and what about this object thing if still valid?

are prop like defined locally may be

one thing i think prop are for the tool pro panel by default only i think
so easy to use when doing an operator for the tool pro panel may be using add mesh menu

and i guess if you have other panel you need to go through with scene properties?

or am i missing something here?

mind you for the string property
prop can be defined for [‘FILE_PATH’, ‘DIR_PATH’, ‘FILENAME’, ‘NONE’]
but the scene properties cannot it’s only a string may be

and you can assign to a scene property a prop

if you avhe a chance look at my other thread for old prop
it will clarify things i guess with that example i tkink

happy 2.5