1

I am just starting to learn how to work with NS-classes. Right now I am trying to figure out how it is possible to index through and access certain parts of a NSBezierPath.

In the snippet below there is a circular path that has 12 nodes and 4 segments. I would like to be able to know how to index and cycle through each of those nodes/segments and apply thickness/color. I can tell the parts in the code that make up the segments but I don't know how to access them.

Simply put, as an example, I would like to be able to: - select a path - select it's 3rd segment - give it some thickness - color it blue

I been looking at the AppKit documentation and it seems the codes below are what I need but I honestly have no idea of how to apply them.

func element(at index: Int) -> NSBezierPath.ElementType

func element(at index: Int, 
associatedPoints points: NSPointArray?) -> NSBezierPath.ElementType

https://developer.apple.com/documentation/appkit/nsbezierpath/1520751-element?changes=_5

I would greatly appreciate any help and examples to better understanding how to work with these methods and apply them.

SNIPPET:

for path in layer.paths:
    bp = path.bezierPath
    bp.setLineWidth_(5)
    NSColor.blueColor().set()
    bp.stroke()
    print bp

PRINTS OUT THIS:

Path <0x60400553f0e0>
  Bounds: {{157, 0}, {286, 286}}
  Control point bounds: {{157, 0}, {286, 286}}
    300.000000 0.000000 moveto
    379.000000 0.000000 443.000000 64.000000 443.000000 143.000000 curveto
    443.000000 222.000000 380.000000 286.000000 300.000000 286.000000 curveto
    221.000000 286.000000 157.000000 222.000000 157.000000 143.000000 curveto
    157.000000 64.000000 221.000000 0.000000 300.000000 0.000000 curveto
    closepath
    300.000000 0.000000 moveto
NewbCake
  • 433
  • 2
  • 7
  • 22
  • 1
    While you have some access to the individual segments of a Bezier path, you can't set the drawing properties for just a segment. The drawing properties are a combination of the `NSBezierPath` properties (i.e. `lineWidth`) and the current graphic context (i.e. `fillColor`). The path then draws in its entirety using those properties. If you want to draw a single segment, you'll need to create a new `NSBezierPath` object with just that segment and render seperately. – James Bucanek Jul 01 '18 at 01:57

0 Answers0