I am an experienced Python user but just started Blender a few months ago. I'm looking into making some automations and scripts in Python in Blender 3.4.0 and I am somewhat stuck on this problem. To summarise, I have two (freshly created) objects in my scene, namely "BezierCurve" and "BezierCurve.001". I have constructed a Python loop which goes through each object and subdivide them into 5 segments. Unfortunately, when running the script below, the "BezierCurve" object gets subdivided by 5, as instructed, but "BezierCurve.001" gets divided 20 odd times. I am scratching my head on this one.
Here's the code:
import bpy # Deselect all objects def deselect_all(): bpy.ops.object.select_all(action='DESELECT') objList = ["BezierCurve","BezierCurve.001"] def resampleCurve(obj, n): # Deselect all deselect_all() # Select Object obj bpy.data.objects[obj].select_set(True) # Enter Edit mode: bpy.ops.object.mode_set(mode='EDIT') bpy.ops.curve.subdivide(number_cuts=int(n - 1)) # Enter Object mode: bpy.ops.object.mode_set(mode='OBJECT') # Deselect Object obj bpy.data.objects[obj].select_set(False) def resampleCurveAll(objList,res): deselect_all() for obj in objList: resampleCurve(obj, res) resampleCurveAll(objList,res = 5)
What am I missing? Maybe this is a newbie question. Any help (or pointers) on this would be appreciated.