Incorrect position of bezier point handle when set via Python #40978

Closed
opened 2014-07-07 13:37:39 +02:00 by Miro Horváth · 11 comments

Blender Version
2.71

Running the code below I expect to get curve as on the left picture, but I'm getting the result from right picture. No matter what coordinates I set to "p2.handle_left" I always get same numbers for X,Y(7.91548 in case of the code below) and Z is always 0 even if I use coords like 4,1,100.

handles.jpg

import bpy

curve = bpy.data.curves.new("TEST",'CURVE')

spline = curve.splines.new('BEZIER')
p1 = spline.bezier_points[0]

p1.co = 0,0,0  
p1.handle_left_type = "ALIGNED"
p1.handle_right_type = "ALIGNED"
p1.handle_right = 4,1,0

spline.bezier_points.add()
p2 = spline.bezier_points[1]
p2.co = 5,5,0
p2.handle_left_type = "ALIGNED"
p2.handle_right_type = "ALIGNED"
p2.handle_left = 4,1,0

object = bpy.data.objects.new("TEST", curve)
bpy.context.scene.objects.link(object)    

Blender Version 2.71 Running the code below I expect to get curve as on the left picture, but I'm getting the result from right picture. No matter what coordinates I set to "p2.handle_left" I always get same numbers for X,Y(7.91548 in case of the code below) and Z is always 0 even if I use coords like 4,1,100. ![handles.jpg](https://archive.blender.org/developer/F96958/handles.jpg) ``` import bpy curve = bpy.data.curves.new("TEST",'CURVE') spline = curve.splines.new('BEZIER') p1 = spline.bezier_points[0] p1.co = 0,0,0 p1.handle_left_type = "ALIGNED" p1.handle_right_type = "ALIGNED" p1.handle_right = 4,1,0 spline.bezier_points.add() p2 = spline.bezier_points[1] p2.co = 5,5,0 p2.handle_left_type = "ALIGNED" p2.handle_right_type = "ALIGNED" p2.handle_left = 4,1,0 object = bpy.data.objects.new("TEST", curve) bpy.context.scene.objects.link(object) ```
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @MiroHorvath

Added subscriber: @MiroHorvath
Member

Added subscriber: @JoshuaLeung

Added subscriber: @JoshuaLeung
Member

When investigating a bug for the keyframes ui, I came across a similar problem. The bug is basically rooted in limitations in the handle recalculation code (calchandleNurb_intern()), specifically, in how it handles aligned handles recalculation.The problem is that when you've got both handles selected, it can't really figure out what to do, so it either treats it as only the first (left) handle being selected, or it gives up entirely. The workaround the keyframes UI uses now is that when editing the second handle, we ensure that only the second handle is selected when we set the value.

When investigating a bug for the keyframes ui, I came across a similar problem. The bug is basically rooted in limitations in the handle recalculation code (calchandleNurb_intern()), specifically, in how it handles aligned handles recalculation.The problem is that when you've got both handles selected, it can't really figure out what to do, so it either treats it as *only* the first (left) handle being selected, or it gives up entirely. The workaround the keyframes UI uses now is that when editing the second handle, we ensure that only the second handle is selected when we set the value.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Bastien Montagne self-assigned this 2014-07-07 14:16:55 +02:00

In other words, this will work:

import bpy
curve = bpy.data.curves.new("TEST",'CURVE')
spline = curve.splines.new('BEZIER')
p1 = spline.bezier_points[0]
p1.co = 0,0,0
p1.handle_left_type = "ALIGNED"
p1.handle_right_type = "ALIGNED"
p1.handle_right = 4,1,0
spline.bezier_points.add()
p2 = spline.bezier_points[1]
p2.co = 5,5,0
p2.handle_left_type = "ALIGNED"
p2.handle_right_type = "ALIGNED"
p2.select_right_handle = False
p2.select_left_handle = True
p2.handle_left = 4,1,0
object = bpy.data.objects.new("TEST", curve)
bpy.context.scene.objects.link(object)

This is not really a bug, more like an internal limitation, closing.

In other words, this will work: ``` import bpy ``` ``` curve = bpy.data.curves.new("TEST",'CURVE') ``` ``` spline = curve.splines.new('BEZIER') p1 = spline.bezier_points[0] ``` ``` p1.co = 0,0,0 p1.handle_left_type = "ALIGNED" p1.handle_right_type = "ALIGNED" p1.handle_right = 4,1,0 ``` ``` spline.bezier_points.add() p2 = spline.bezier_points[1] p2.co = 5,5,0 p2.handle_left_type = "ALIGNED" p2.handle_right_type = "ALIGNED" p2.select_right_handle = False p2.select_left_handle = True p2.handle_left = 4,1,0 ``` ``` object = bpy.data.objects.new("TEST", curve) bpy.context.scene.objects.link(object) ``` This is not really a bug, more like an internal limitation, closing.
Author

Thnx for the quick reply aligorith,

yup you're right adding p2.select_left_handle = True really does the trick.

Cheers

Thnx for the quick reply aligorith, yup you're right adding p2.select_left_handle = True really does the trick. Cheers
Member

Added subscriber: @LukasTonne

Added subscriber: @LukasTonne
Member

Ok, @JoshuaLeung's explanation is totally correct. However, in a case like this the calculation order should be nicely resolvable, because only one of the handle sides is set at a time, i.e. the other side would be expected to follow it. This additional ordering information gets lost because everything uses the same generic function ...

Ok, @JoshuaLeung's explanation is totally correct. However, in a case like this the calculation order should be nicely resolvable, because only one of the handle sides is set at a time, i.e. the other side would be expected to follow it. This additional ordering information gets lost because everything uses the same generic function ...
Member

Added subscriber: @mont29

Added subscriber: @mont29
Member

Oops, @mont29 answered in the meantime: This solution is doing just that, only that it requires modifying selection to force the calculation order. This should not actually be necessary, but could be integrated into the rna call.

Oops, @mont29 answered in the meantime: This solution is doing just that, only that it requires modifying selection to force the calculation order. This should not actually be necessary, but could be integrated into the rna call.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 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#40978
No description provided.