0
$\begingroup$

In a previous version of blender I had script that applied a bevel to a curve, but now cannot get it to work in 2.92. or above. I want to apply the bevel to an object referenced by the variable curveOB1 and have tried the following.

bpy.data.objects[curveOB1.name].select_set(True)
bpy.context.object.data.bevel_mode = 'OBJECT'
bpy.context.object.data.bevel_object = bpy.data.objects['BezCirc-001']

Everything else in my script works but the above, seems to do nothing and no errors. As an alternative I have aslo tried bpy.ops.object.select_pattern(pattern=curveOB1.name) in place of the first line.

The old code was:

bpy.context.scene.objects.active = curveOB1
bpy.context.object.data.bevel_object = bpy.data.objects['BezCirc-001']

This gives an error on the first line.

If I use the object data properties manually it works fine.

Any help would be appreciated.

John

$\endgroup$

1 Answer 1

2
$\begingroup$

See this answer for details of how to set active object since 2.8x.

For your example the following should work;

bpy.context.view_layer.objects.active = curveOB1
bpy.context.object.data.bevel_mode = 'OBJECT'
bpy.context.object.data.bevel_object = bpy.data.objects['BezCirc-001']
$\endgroup$
2
  • $\begingroup$ Thanks that worked a treat. Why does bpy.data.objects[curveOB1.name].select_set(True) or bpy.ops.object.select_pattern(pattern=curveOB1.name) not work when they also apprear to select the object and allow it to be manipulated. As in bpy.ops.object.select_pattern(pattern=curveOB1.name) bpy.ops.transform.translate(value=(displaceX, 0, 0)) $\endgroup$
    – John
    Jan 5, 2023 at 10:07
  • $\begingroup$ From my understanding operators depend on context which implies they are best utilized in scripts which establish the correct context is active before executing them. The poll() method is used to prevent operators being executed in invalid scenarios. Typically operators are executed through UI interaction. So while it might be possible to change the selection state for objects using an operator in a particular context, other operators might not be available. $\endgroup$ Jan 5, 2023 at 19:29

You must log in to answer this question.

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