i have an old plugin that used in sketch 71.3
and the code
const rect = layer.absoluteRect().rect()
go wrong by showing
Error: An Obj-C exception occurred.
at [native code] (/)
this is wired
i have an old plugin that used in sketch 71.3
and the code
const rect = layer.absoluteRect().rect()
go wrong by showing
Error: An Obj-C exception occurred.
at [native code] (/)
this is wired
Hey there,
Thanks for the report! We did remove absoluteRect()
on Sketch 97. Here’s a quick workaround a user shared on our forums that might help in this case.
However, you seem to be having this problem with Sketch 71.3. Would you mind sharing more details about your setup? Like macOS version, and confirm that you are using Sketch 71.3 (Which should still have absoluteRect()
in it)
my macOS version is Ventura 13.2.1 (22D68), memeory 16 GB 2667 MHz DDR4, cpu Intel core i7
I believe Sketch versions prior to 93 all have this problem on macOS 13+ where they can’t interact with CGRect
, CGSize
and friends due to an internal change in system frameworks.
One workaround (other than updating your version of Sketch) is to run the following code once as soon as your plugin launches:
__mocha__.loadFrameworkWithName("CoreFoundation")
Very good catch, Dmitry!
Some versions prior Sketch 93, when ran using macOS Ventura, do not include this fix and might have some trouble running some scripts.
The script you shared does work indeed, and this is another way to do it:
Mocha.sharedRuntime().loadFrameworkWithName('CoreFoundation')
a@TChengZ let us know if this helps!
this works fine, rect() function is ok,
but then another problem come to me
var cls = NSClassFromString("SketchModel.MSImmutableLayerAncestry");
var ancestry = cls.alloc().initWithMutableLayer(layer);
var exportRequest = MSExportRequest.exportRequestsFromLayerAncestry_(ancestry).firstObject();
exportRequest.format = 'svg';
var exporter = MSExporter.exporterForRequest_colorSpace_(exportRequest, NSColorSpace.sRGBColorSpace());
console.log('exportSvgString exporter', exporter);
var svgData = exporter.data();
console.log('exportSvgString svgData', svgData);
return String(NSString.alloc().initWithData_encoding(svgData, NSUTF8StringEncoding));
i used to use this code get svgString, but now won’t work,
exporter.data();
get wrong by showing
@[native code]
i seems like another framework bug
I’ve run your code verbatim on a regular Rectangle layer and it seems to work fine. What kind of layer is your layer
and where did it come from?
i log the error layer,but i can’t find it in sketch even using search layer
how can i get the mac os version in sketch plugin
Could it be that this layer is part of an imported library symbol? I’ve seen problems with such layers recently.
Well, due to a bug/limitation in CocoaScript, you can’t call the intended system API to get the current macOS version (namely, NSProcessInfo.processInfo().operatingSystemVersion()
is impossible to call from CocoaScript because it has an incorrect return type declared there).
But depending on your needs you may just grab a textual representation of that version via
let version = NSProcessInfo.processInfo().operatingSystemVersionString()
// "Version 14.0 (Build 23A344)"
yeah, the error layer come from library symbol,unfortunately i still can not find it by searching it,but it occured in some symbol, and all the error layers are shapegroupLayer and named ‘shape_1’,
finally it just happened in some old version sketch like 71.2,i update sketch to 80+, the problem disapear