Sunday, July 3, 2022

#1 2021-12-21 05:25:09 pm

David Brown
Member
Registered: 2021-04-24
Posts: 6

I need an NSPointArray

I am working with NSBezierPaths. Many of its methods require an NSPointArray as one of the parameters. The documentation describes it as "A C-style array containing up to three NSPoint data types." The documentation is sparse. Evidently I have been unable to create an NSPointArray because all my attempts to use one cause both Script Debugger and Script Editor to crash. For example, the following code results in a crash due to the setAssociatedPoints: method.

[AppleScript]set theImage to NSImage's alloc's initWithSize:{500, 500}
    theImage's lockFocus()
    set thePath to NSBezierPath's bezierPath()
    thePath's moveToPoint:{0, 0}
    thePath's lineToPoint:{50, 50}
    set thePoint to current application's NSMakePoint(50, 125)
    set theArray to current application's NSArray's alloc's initWithArray:{thePoint}
    thePath's setAssociatedPoints:theArray atIndex:1
    thePath's stroke()
    theImage's unlockFocus()
[/AppleScript]

I have tried a number of variations to create theArray, including using a mutable array. I have also tried using NSValue to place the point in the array, but the code still caused Script Debugger to crash.

[applescript]set theImage to NSImage's alloc's initWithSize:{500, 500}
    theImage's lockFocus()
    set thePath to NSBezierPath's bezierPath()
    thePath's moveToPoint:{0, 0}
    thePath's lineToPoint:{50, 50}
    set thePoint to current application's NSMakePoint(50, 125)
    set theArray to current application's NSMutableArray's alloc's init()
    theArray's addObject:(current application's NSValue's valueWithPoint:thePoint)
    thePath's setAssociatedPoints:theArray atIndex:1
    thePath's stroke()
    theImage's unlockFocus()[/AppleScript]

I would appreciate any assistance.

Offline

 

#2 2021-12-21 07:14:02 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6779

Re: I need an NSPointArray

It can't be done --- ASObjC doesn't support pointers like NSPointArray.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2021-12-21 07:50:30 pm

David Brown
Member
Registered: 2021-04-24
Posts: 6

Re: I need an NSPointArray

Shane - thank you for another quick response. I was wondering if you were going to tell me that NSPointArrays are not supported.

I have learned an enormous amount from your Book and the many clear examples you have posted. You have my gratitude.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)