1
$\begingroup$

I am trying to add custom properties to bones. I can understand what normal type properties does like Float,Integer,and Boolean but I don't know what "Python type" custom properties does.

I can execute python script there like driver expression does? I can't find a good explanation for "Python type" custom properties. What it does in general?

If you know what it does, please tell me how to use it and give me an example.

I can finally make a Python type custom property. I've made this Python type property

Type = Python
Property Name = Python
Value = bpy.context.scene.frame_set(50)

And when I pushed "OK" to make it, python command "bpy.context.scene.frame_set(50)"is executed and current frame is set as 50, and after that this Python property has "NONE" Value. Its text field is now emptied and grayed out and I can't touch it anymore. I still don't know how to use Python type custom property. It's just one-time python script launcher?

enter image description here

$\endgroup$
5
  • $\begingroup$ Have you seen this page in the Blender Manual? docs.blender.org/manual/en/latest/files/custom_properties.html It mentions Python about halfway down the page and also at the bottom of it. It also has a link to the Python API at the bottom. Maybe the example in the API can help you. $\endgroup$
    – curious_1
    Jul 7 at 7:16
  • $\begingroup$ I've already read it and it says nothing about how to use and how to set it up. Can you make a Python type custom properties? I am trying to make it but it is changed to to other types always. I don't know how. $\endgroup$
    – Yokomizo
    Jul 7 at 11:01
  • $\begingroup$ API doesn't tell me how to use Python type property and that we can have custom color properties when we set it up as type = Float Array Subtype = Linear Color or Gamma-Corrected Color...... $\endgroup$
    – Yokomizo
    Jul 7 at 11:24
  • $\begingroup$ Hello, could you elaborate on what you call a python "type" property ? All python properties are type properties by definition. The code snippet you posted doesn't seem like it should execute. What are you trying to do ? $\endgroup$
    – Gorgious
    Jul 7 at 12:07
  • $\begingroup$ I added a picture. that's the custom property I am talking about. Python type custom property, which I don't know how to use. $\endgroup$
    – Yokomizo
    Jul 7 at 12:32

2 Answers 2

1
$\begingroup$

The manual says:

Edit a Python data type directly, used for unsupported data types.

So it seems they are meant for storing any kind of data that is not "supported". You can indeed set the properties to be a Python dictionary for example:

enter image description here

And it does show up as Python property:

enter image description here

It can also link to all sorts of Blender data like objects or materials or any other kinds of data blocks:

enter image description here

However it appears it cannot be anything:

enter image description here

So maybe it's not complete yet and it might get to be more defined in the future versions.

$\endgroup$
8
  • $\begingroup$ seems like it's way over my head. I though it can be used like other properties type, but right now there is no manual to handle python type.. thank you for your comment anyway. $\endgroup$
    – Yokomizo
    Jul 11 at 6:02
  • $\begingroup$ What do you mean "no manual to handle"? You just use them with Python when you need to store something attached to something else and when data type doesn't match any other type, it gets called "Python". It's common to use custom properties from scripts for all kinds of stuff, it's just that I don't think anybody cares a lot about what type of custom property they are. Property types are useful, because they can be treated differently, for example Float Array, Linear Color subtype will have color input with color picker popping up if you click it in the UI. $\endgroup$ Jul 11 at 6:36
  • $\begingroup$ I should have said "tutorial." I don't understand "the time when you need to store something attached to something else and when data type doesn't match any other type". If you don't care give me an example please. $\endgroup$
    – Yokomizo
    Jul 11 at 13:59
  • $\begingroup$ If I am writing some sort of add-on and for example I want to save some list of materials per scene, let's say I have them on the active object and want to save them with current scene for next time I open the file because my add-on needs to remember them for some reason, I will just do C.scene["my_custom_material_list_for_later"] = C.object.data.materials. I never have to see, or set, or even be aware of the type of the custom property. I care when I want to use custom properties to control something, maybe use attribute in a shader and have custom color property available from the Sidebar. $\endgroup$ Jul 11 at 14:52
  • $\begingroup$ Like this That's convenient to use manually, without Python, because I can set color per object but use the same shader and I can conveniently access that in the 3d viewport. So that's where having custom properties is awesome and having different types makes a difference. I don't care about types when using Python because as long as they work, they mostly get set automatically, unless of course I would want to create them for the user to use. $\endgroup$ Jul 11 at 14:59
1
$\begingroup$

Custom properties type Python will execute any Python command in its Value that can be executed by the PYTHON INTERACTIVE CONSOLE.

enter image description here

enter image description here

I think It is used by addons that defines custom property using the PropertyGroup class and register it to any data type e.g. bpy.types.Scene

Since bpy.context.scene.frame_set(50) and PointerProperty(type=XX_PG_custom_properties) are internal python API.

import bpy
from bpy.types import PropertyGroup
from bpy.props import *


class XX_PG_custom_properties(PropertyGroup):
    
    name : StringProperty(default='Test')
    
    
def register():
    bpy.utils.register_class(XX_PG_custom_properties)
    
    bpy.types.Scene.custom = PointerProperty(type=XX_PG_custom_properties)
    

def unregister():
    bpy.utils.unregister_class(XX_PG_custom_properties)
    
    del bpy.types.Scene.custom
    

if __name__ == '__main__':
    register()

enter image description here

$\endgroup$
2
  • $\begingroup$ OK, it will execute apparently, but it is not really meant for that as far as I understand. $\endgroup$ Jul 10 at 12:23
  • $\begingroup$ I don't know how to use add-on related things but it sheds some light. thank you. $\endgroup$
    – Yokomizo
    Jul 11 at 6:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .