2
$\begingroup$

I am trying for the first time to have a look at some python API.

So my goal would be to create a bevel modifier with the custom curve that I create:

  point_init(&profile->path[0], 1.0f, 0.0f, 0, HD_VECT, HD_VECT);
  point_init(&profile->path[1], 1.0f, 0.25f, 0, HD_VECT, HD_VECT);
  point_init(&profile->path[2], 0.75f, 0.25f, 0, HD_VECT, HD_VECT);
  point_init(&profile->path[10], 0.0f, 1.0f, 0, HD_VECT, HD_VECT);

So I can use use_custom_profile

The API doc: https://docs.blender.org/api/current/bpy.types.BevelModifier.html?highlight=b

I don't understand is this:

custom_profile The path for the custom profile

Type: CurveProfile, (readonly)

Does this mean that it's not possible to give CurveProfile the points I want?

Thanks :)

$\endgroup$
3
  • 1
    $\begingroup$ Not sure the C code is that useful here. Can add points to the bevel modifier custom profile (on context object) via C.object.modifiers['Bevel'].custom_profile.points.add(x, y) $\endgroup$
    – batFINGER
    Feb 28, 2020 at 9:30
  • $\begingroup$ Hi, thanks unfortunately I think there is no way of doing this "yet", as when I manually change a point nothing is displayed in the consol: bpy.ops.text.run_script() bpy.ops.object.modifier_add(type='BEVEL') bpy.context.object.modifiers["Bevel"].use_custom_profile = True nothing $\endgroup$
    – RaFF
    Feb 29, 2020 at 9:27
  • 1
    $\begingroup$ Hey, after trying, you were right ! I can add points, the only problem is now I cannot control the order of the points. Thank you so much @batFINGER, you can write the answer. How did you know the answer ? Because I searched everywhere $\endgroup$
    – RaFF
    Feb 29, 2020 at 10:12

1 Answer 1

4
$\begingroup$

Add the modifier adjust settings

enter image description here

When using a custom profile, 2 points are created at (1, 0) and (0, 0). Add points between these.

When finished adding points update the profile.

import bpy


pts = (
    (0.4, 0.7),
    (0.6, 0.3) 
    )
context = bpy.context
ob = context.object
bm = ob.modifiers.new(
        name="Bevo",
        type='BEVEL',
        )
bm.use_custom_profile = True

bm.segments = 4
bm.width = 0.4

points = bm.custom_profile.points

for p in pts:
    pt = points.add(*p)
    pt.handle_type_1 = 'AUTO' 
    pt.handle_type_2 = 'AUTO'
    pt.select = True

bm.custom_profile.update() 

To work out new features, recommend using the python console and auto complete. The API is pretty consistent. This is akin to adding fcurve keyframe points, or bezier curve points.

>>> bm = C.object.modifiers.new(name="Foo", type='BEVEL')
>>> bm.custom_profile.points.
                             add(
                             as_bytes(
                             bl_rna

Yes also found the ordering tricky, without testing it appears the first and last points could be indices 0, 1

$\endgroup$
2
  • $\begingroup$ Thanks for the tips, yeah, the order it is strange if I set up one of my point to y=0.24 it is the second last as the second last point. but if y=0.25 it is become the 4rth last.. But I will do mo research but thanks a lot $\endgroup$
    – RaFF
    Feb 29, 2020 at 10:52
  • $\begingroup$ Awesome tips. Always indeed helpful! $\endgroup$
    – Derekcbr
    Nov 14, 2021 at 0:40

You must log in to answer this question.

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