custom property values not setting correctly via code #73879

Closed
opened 2020-02-16 13:04:54 +01:00 by Jorge del Valle · 9 comments

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: Quadro K4000/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 353.62

Blender Version
Broken: version: 2.82 (sub 7), branch: master, commit date: 2020-02-12 16:20, hash: blender/blender@77d23b0bd7
Worked: (optional)

Short description of error
When I create a custom property via Python, the min and max setting values seem to get applied, but have no effect. For instance, in the image below you can see how a custom property has been created with min-max values of 0-100...
image.png

yet I can click and drag the property in the 3D Viewport to a value outside of the set limits.
image.png

Also, I'm setting use_soft_limits to True in my code, but they appear disabled in the properties panel:
image.png

Exact steps for others to reproduce the error
To reproduce the issue, run the code below which will create an Empty object with a custom property (custom_prop). Then test click-dragging the custom propery value outside of the limits set by the code. Also, note how soft limits are disabled, despite being supposedly enabled by the code.

import bpy

# Create object
bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0))

# Set object to variable
obj = bpy.context.active_object

# Create custom propery for object
obj['custom_prop'] = 0

# Create empty dictionary for IDproperty settings
obj['_RNA_UI'] = {}

# Add property settings
obj['_RNA_UI']['custom_prop'] = {
    'data_path' : 'object',
    'min': 0.0,
    'max': 100.0,
    'value' : 0.0,
    'default' : 0.0,
    'use_soft_limits' : True,
    'soft_min' : 0.0,
    'soft_max' : 100.0,
    'is_overridable_library' : False,
    'description' : 'Custom description'
}
**System Information** Operating system: Windows-10-10.0.18362-SP0 64 Bits Graphics card: Quadro K4000/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 353.62 **Blender Version** Broken: version: 2.82 (sub 7), branch: master, commit date: 2020-02-12 16:20, hash: `blender/blender@77d23b0bd7` Worked: (optional) **Short description of error** When I create a custom property via Python, the min and max setting values seem to get applied, but have no effect. For instance, in the image below you can see how a custom property has been created with min-max values of 0-100... ![image.png](https://archive.blender.org/developer/F8343012/image.png) yet I can click and drag the property in the 3D Viewport to a value outside of the set limits. ![image.png](https://archive.blender.org/developer/F8343016/image.png) Also, I'm setting use_soft_limits to True in my code, but they appear disabled in the properties panel: ![image.png](https://archive.blender.org/developer/F8343018/image.png) **Exact steps for others to reproduce the error** To reproduce the issue, run the code below which will create an Empty object with a custom property (custom_prop). Then test click-dragging the custom propery value outside of the limits set by the code. Also, note how soft limits are disabled, despite being supposedly enabled by the code. ``` import bpy # Create object bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0)) # Set object to variable obj = bpy.context.active_object # Create custom propery for object obj['custom_prop'] = 0 # Create empty dictionary for IDproperty settings obj['_RNA_UI'] = {} # Add property settings obj['_RNA_UI']['custom_prop'] = { 'data_path' : 'object', 'min': 0.0, 'max': 100.0, 'value' : 0.0, 'default' : 0.0, 'use_soft_limits' : True, 'soft_min' : 0.0, 'soft_max' : 100.0, 'is_overridable_library' : False, 'description' : 'Custom description' } ```

Added subscriber: @JorgeV-2

Added subscriber: @JorgeV-2

I've just realised that the soft limit values are what determine the custom property limits in when click-dragging in the 3D Viewport. However, the issue still stands in that enabling soft limits via Python doesn't seem to work. So you will still be able to overshoot (or undershoot) limit values, evne if you've specified you want soft limits in the code.

I've just realised that the soft limit values are what determine the custom property limits in when click-dragging in the 3D Viewport. However, the issue still stands in that enabling soft limits via Python doesn't seem to work. So you will still be able to overshoot (or undershoot) limit values, evne if you've specified you want soft limits in the code.

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Changed status from 'Needs Triage' to: 'Resolved'

Changed status from 'Needs Triage' to: 'Resolved'
Campbell Barton self-assigned this 2020-02-17 05:32:50 +01:00

This is dealing with internals which don't have an publicly exposed Python API.

The problem is caused by an int/float type mismatch.

This is dealing with internals which don't have an publicly exposed Python API. The problem is caused by an int/float type mismatch.

Changed status from 'Resolved' to: 'Archived'

Changed status from 'Resolved' to: 'Archived'

You are right. The issue was being caused by the line:

obj['custom_prop'] = 0

Setting it that way made the variable type an integer, and I hadn't realised that. The issue has been fixed now by changing the code to:

obj['custom_prop'] = 0.0

Amazing what a difference a decimal point and a zero to the right can make.

Thank you!

You are right. The issue was being caused by the line: ``` obj['custom_prop'] = 0 ``` Setting it that way made the variable type an integer, and I hadn't realised that. The issue has been fixed now by changing the code to: ``` obj['custom_prop'] = 0.0 ``` Amazing what a difference a decimal point and a zero to the right can make. Thank you!

Added subscriber: @Astronet-4

Added subscriber: @Astronet-4

This problem still persists actually in 2.93. even if the property is a float or an int it still overshoots the min and max value
In my case when I manually edit the property, even without changing anything once I click "ok" then everything works fine again. but creating the property via script always has this issue

This problem still persists actually in 2.93. even if the property is a float or an int it still overshoots the min and max value In my case when I manually edit the property, even without changing anything once I click "ok" then everything works fine again. but creating the property via script always has this issue
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#73879
No description provided.