properties specs ?

seems there was some changes to how to deal with properties

here is sample script



 
 
 
import bpy,bmesh
from bpy.props import *
from mathutils import *
from math import *
 
from mathutils import Matrix, Vector
 
bpy.types.Scene.vecFloat1 = FloatVectorProperty(    # Myfloat is the name of the Float variable = Scene property
 name="Direction Vector",         # Name printed in button
 description="Enter a Vector",        # Tip tool
 default = (1.0,2.0,3.0),
 subtype='DIRECTION',
 unit='LENGTH',
 min = -100,
 max = 100)
 
 
print ()
print (' Vector float')
print ()
 
# Property  Class
print ()
print ('Property  Class  Vector float    %%%%%%%%%%')
print ()
print ('vecFloat1 =',bpy.types.Scene.vecFloat1)    #  Print Class of the property
 
# Property value
print ()
print ('Property value  Vector float      %%%%%%%%%%')
print ()
print ('Propertie vecFloat1 =',bpy.context.scene.vecFloat1) #  Print data value of the property
 
 
# Property assign
print ()
print ('Property assign  Vector float   %%%%%%%%%%  ')
print ()
bpy.context.scene['vecFloat1'] = (2,4,6)       #  assign a value to the property
# Value
print ()
print ('Property Value  Vector float    %%%%%%%%%% ')
print ()
val1=bpy.context.scene.vecFloat1         # get a value to the property
 
print ('vecFloat1 value propr =',val1)
print ()
 
 



how do you print
the property class
the property value
assign a value

for instance if i assing a vecfloat to a var
and print it it prints the class not the value!

point1=bpy.context.scene[‘vecFloat1’]
print (‘Propertie vecFloat1 =’,bpy.context.scene.vecFloat1 )

how can i print the value ?

thanks

proper way to use is as followes:

>>> bpy.context.scene['vecFloat1'] = 123
>>> bpy.context.scene['vecFloat1']
123

>>> bpy.types.Scene.vecFloatProp = bpy.props.FloatProperty()
>>> bpy.context.scene.vecFloatProp = 1.2
>>> bpy.context.scene.vecFloatProp
1.2000000476837158

the float prop seems to work well
only thing is that if i use the SKIP save
i still get some old value as default not certain where it is coming from!

and the vecfloat one is a vector not a single float
i have one working in one simple panel
but in the other script one it is crashing for whatever reason
i’ll do some testing tomorrow may be i’ll see why !
when i print the vector one it looks like the class more then the value!

i check latest API and saw some new prop for mesh
any example on what it is and how to use this?
any good doc on these?

thanks

only thing is that if i use the SKIP save
i still get some old value as default not certain where it is coming from!

Did you test with restarting blender? 'cause it caches property values somehow. Register a new prop, set a value, unregister, register with same name -> it should still have the previously set value.

and the vecfloat one is a vector not a single float

Did anyone claim something else? It’s an array of floats, as the name implies.

when i print the vector one it looks like the class more then the value!

What is that supposed to mean? Looks ok here:

>>> bpy.types.Scene.floatvec = bpy.props.FloatVectorProperty(options={'SKIP_SAVE'})
>>> C.scene.floatvec
bpy.data.scenes['Scene'].floatvec

>>> C.scene.floatvec[
                     0]
                     1]
                     2]
>>> C.scene.floatvec[:]
(0.0, 0.0, 0.0)

>>> type(C.scene.floatvec)
<class 'bpy_prop_array'>

saw some new prop for mesh

Where?

1 -
i found the error in my panel

i had

point1=bpy.context.scene[‘vecFloat1’]

and change it for
point1=bpy.context.scene.vecFloat1

and now it works fine

2 - new prop

how about this one
http://www.blender.org/documentation/blender_python_api_2_68_2/bpy.types.MeshFloatProperty.html?highlight=float%20prop#bpy.types.MeshFloatProperty.value

3 -

prop in general
i had this in my notes 2 years ago and was trying to redo it in first post

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

Property value
print (‘Propertie MyFloat1 =’,bpy.context.scene.MyFloat1 ) # Print data value of the property

Property assign
bpy.context.scene[‘MyFloat1’] = 22.6 # assign a value to the property

Value
val1=bpy.context.scene.ang11 # get a value from the property

but may be this has change over time

thanks

i added a new intvect
and in panel i get a square with a circle in center

i wanted to select an axis for a vector
like (0,0,1)
)may be there is a better way !

how does this works?

thanks

  1. Always make sure you access properties the right way, ob[‘prop’] for object properties and ob.prop for global properties.

  2. Those aren’t new properties (it’s nowhere related to bpy.props), those are basically methods to acess custom data layers, so a port of the bmesh module’s custom data layers abilities to the standard API.

import bpy
import bmesh
from bpy import data as D
from bpy import context as C

f = C.object.data.polygon_layers_float.new("my flop")
f.data[0].value = 1

f.data[0].value # 1.0
f.data[1].value # 0.0

bm = bmesh.new()
bm.from_mesh(C.object.data)
l = bm.faces.layers.float['my flop']

bm.faces[0][l] # 1.0
bm.faces[1][l] # 1.0

  1. Looks bad, should not use square brackets
    bpy.context.scene[‘MyFloat1’] = 22.6 # assign a value to the property
    bpy.context.scene.MyFloat1 = 22.6 # correct

and in panel i get a square with a circle in center

Screeshot please! Sounds like you used some subtype for the property, and those change the representation when added to UI.

1 -
ob[‘prop’] for object properties and ob.prop for global properties
object prop like ID?
adding a propertie to all object may be!

2 - f = C.object.data.polygon_layers_float.new(“my flop”)
what would these layers be ?
and is this available only when using polygon acess method

thanks

for the int vect prop

define like this

bpy.types.Scene.vecintaxis1 =bpy.props.IntVectorProperty(
name=“Direction Vector”, # Name printed in button
description=“Enter a Vector”, # Tip tool
default = (0,1,1),
subtype=‘DIRECTION’,
min = 0,
max = 1)

and it gives this icon in Panel window


thanks

object prop like ID?
adding a propertie to all object may be!

ob[…] = … is ID property yes, but the same is sort of confusing. It adds a custom property to just that object. Registered properties (bpy.props.*) are added to all objects of the type you register it to (e.g. bpy.types.Scene).

what would these layers be ?
and is this available only when using polygon acess method

Well, custom data. Custom data is e.g.

  • UV mapping and vertex color (loop custom data layer)
  • Shape keys, vertex bevel weight and crease (vertex CD layer)
  • edge crease and bevel weight (edge CD layer)
  • texture assignments and freestyle faces (face CD layer)

You can create new layers with primitive types int, string and float. The polygon_layers_* thing let’s you access the face CD layer with standard API, loop/vert/edge acces seems to be missing. You can use bmesh module for that however.

and it gives this icon in Panel window

It’s not an icon, it’s an interactive input field. If you don’t want that, don’t use that subtype

subtype=‘DIRECTION’

1 -this icon drawing how does it work ?

2 - any small example on how to use these polygon layers!

thanks

ok but how do you change the value for this prop in UI?
i mean with a silder button you change the slider but how do you change it here?

thanks

by sending a carrier pidgeon with a letter to the blender devs, they will adjust it.

… of course with your mouse, see user prefs > system how you set the shading directions

did not see any doc on that one
i can see that there is a special menu with RMB not certain !
but don’t see any values from prop on that one
i 'll change it too complicated !

thanks

It requires a default value (vector) which is not zero-length.

import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        layout.prop(context.scene, "p", text="")


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

    bpy.types.Scene.p = bpy.props.FloatVectorProperty(
        subtype='DIRECTION',
        default=(1,0,0)
    )


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)
    del bpy.types.Scene.p


if __name__ == "__main__":
    register()


Use LMB to change direction

1- type
i wanted to select an axis so i used an intvector instead of a float
and it did not realy work but the float seems to work

is there a way to make it work with int vector or another way may be
to select an axis - like 1,0,0 or 0,1,0 or 0,0,1…

2 - del prop
i see here that you added prop and also delete the prop in the unregister
is this a enw ay of dong thigs
what are advantagea or disavntages

i saw another way last month do use prop group instead
thanks

  1. i guess you could use it with another subtype
    bpy.types.Scene.p = bpy.props.IntVectorProperty(
        subtype='XYZ',
        default=(1,0,0),
        min=0,
        max=1
    )

but blender convention for picking axis are enums

  1. you should always delete them in the unregister function. The stored values will persist, just make sure you got the addon enabled that registers and uses the properties so they load with .blend

I guess you are talking about a pointerproperty that points to a bpy.types.PropertyGroup subclass? You should use that instead of cluttering the entire namespace of e.g. bpy.types.Scene, so whenever your addons use a lot of registered props

why do you say
but blender convention for picking axis are enums

i’ll tet the invect

is there an example for this enums
might work better!

tested the invect
and it gives this drawing


deleting props
if you have like 20 props

do you have to delete one by one or is there a quicker way of doing it ?

is it samething with groups?

when you delete it does it means it wont save value to file too?

thanks