Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Modified 1 month ago
Viewed 61 times
1
$\begingroup$

I have some code that generates a curve:

import bpy

curve_data = bpy.data.curves.new("SimpleCurve", type='CURVE')
spline = curve_data.splines.new(type='POLY')
spline.points.add(3)
coords = [(0, 0, 0, 1),  (1, 0, 0, 1),  (1, 1, 1, 1), (0, 1, 1, 1)]

for i, co in enumerate(coords):
    spline.points[i].co = co

curve_obj = bpy.data.objects.new("SimpleCurve", curve_data)
bpy.context.collection.objects.link(curve_obj)

This works fine, but when I edit the generated curve, dragging any point causes all points to reset their Z values to zero. What am I doing wrong?

demonstration

$\endgroup$
0

1 Answer 1

1
$\begingroup$

In the generated curve's Object Data Properties > Shape panel, you'll notice it's set to 2D but you need 3D.

enter image description here

By default, Blender generates a 2D curve that is always flattened onto the object's local XY plane, meaning all Z coordinates are set to $0$. If you want the curve to retain depth or exist in 3D space, you need to set its dimensions to '3D'.

curve_data = bpy.data.curves.new("SimpleCurve", type='CURVE')
curve_data.dimensions = '3D'  # add this line
$\endgroup$
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.