2
$\begingroup$

I have a lot of these curves in different shapes. Finding the most convex points along the axes by eye is not an option, you need absolute precision.

Maybe someone can suggest a script that would select the most distant point on any axis. Or maybe there is already a built-in command in Blender to do the same thing.

If it would be easier to do the task with Mesh rather than Grease Pencil - you could convert curves to Mesh as well, no problem.

enter image description here

$\endgroup$

1 Answer 1

5
$\begingroup$

In Edit Mode deselect everything and press ⬆ ShiftF4 to switch to Python Console, then paste the below oneliner:

axis=0; C.area.type = 'VIEW_3D'; max((p for s in C.editable_gpencil_strokes for p in s.points), key=lambda p:abs(p.co[axis])).select = True;

(using inline formatting on purpose because it's a long line)

After pasting and pressing ↩ Enter the view should switch back to Viewport 3D and the furthest point on chosen axis (axis=0 for $x$, axis=1 for $y$, axis=2 for $z$) should be selected:

$\endgroup$
5
  • $\begingroup$ Argh I'll never understand nested for loops syntax $\endgroup$
    – Gorgious
    Commented Jul 1, 2023 at 15:22
  • $\begingroup$ @Gorgious it seems like it should be reversed to resemble the ordering in a human language, but it's simple when you think in terms of normal loops: for s in C.editable_gpencil_strokes: for p in s.points: - this is how you would normally loop, and you put it in the same order to the comprehension/generator, just without the colons, and at the very start you add the evaluated result for each step (here just p). $\endgroup$ Commented Jul 1, 2023 at 15:31
  • 2
    $\begingroup$ Hehe thanks for the explanation. Every time I think I understand but when I stumble upon having to do it from scratch a few months later I always get it wrong. Maybe with this method it'll stick :p $\endgroup$
    – Gorgious
    Commented Jul 1, 2023 at 19:59
  • $\begingroup$ +1 ... but .. is this compression over clarity? Not my area. I defer to your greater experience. Is there a more readable way of expressing this, though? (A bit rich, from me, I used to script Perl quite a lot) $\endgroup$
    – Robin Betts
    Commented Jul 2, 2023 at 6:18
  • 1
    $\begingroup$ @RobinBetts it is "compression over clarity", just because it's a shift+f4 technique, could write an operator, or if OP wants to select in all gpencil objects, layers, frames, could loop through them, but for now OP hasn't commented. $\endgroup$ Commented Jul 2, 2023 at 7:31

You must log in to answer this question.

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