GeertWille / sketch-to-xcode-assets-catalog

Export assets for iOS directly from Sketch into Xcodes assets catalog
GNU General Public License v3.0
221 stars 17 forks source link

Exporting slice layers yield empty images #13

Closed cmyk closed 9 years ago

cmyk commented 9 years ago

The plugin doesn't export slice layers correctly. The images are blank. A normal sketch export, exports the same slice layers correctly.

The plugin only seems to work on group/object exports. I can send you a little sample file, if you want.

GeertWille commented 9 years ago

Yes please attach an example sketch file :smiley: I still need to update this plugin... Hopefully I can find some time in the near future.

cmyk commented 9 years ago

Hi Geert,

here it is (attached a zip to this email, but not sure, you'll get it). We actually fixed your script for the other issue I reported. https://github.com/GeertWille/sketch-to-xcode-assets-catalog/issues/14

Cheers Philipp

--- main.js
+++ (clipboard)
@@ -106,6 +106,8 @@
             jsonPath     = '',
             lineBuffer   = [];

+//        com.geertwille.general.alert("Path"+cutSliceName);
+
         // Find out our extension to save image with
         if (fileType == "j_") {
             imageExtension = ".jpg";
@@ -132,12 +134,13 @@

         // Loop over all the factors and save the lines to a lineBuffer
array
         for (var i = 0; i < this.factors.length; i++) {
+ var fileName = sliceName.trim().substring(sliceName.lastIndexOf('/')+1);
             var name         = this.factors[i].folder,
             scale            = this.factors[i].scale,
             suffix           = this.factors[i].suffix,
             version          = this.copyLayerWithFactor(slice, scale),
-            relativeFileName = cutSliceName + suffix + imageExtension,
-            absoluteFileName = this.baseDir + "/" +
this.defaultAssetFolder + "/" + cutSliceName + ".imageset/" + cutSliceName
+ suffix + imageExtension;
+            relativeFileName = fileName + suffix + imageExtension,
+            absoluteFileName = this.baseDir + "/" +
this.defaultAssetFolder + "/" + cutSliceName + ".imageset/" + fileName +
suffix + imageExtension;

             [doc saveArtboardOrSlice:version toFile:absoluteFileName];
cmyk commented 9 years ago

I cannot attach sample files here. Where should I send them to? It's quite simple: If you have a folder with graphics in it (group) and then create a slice for exporting those graphics and that slice is in the same folder (and has only export group contents checked), the script hides the layers in that folder. If you just comment line 46 in main.js: //this.hideLayers(root, layer); it's exporting the folder's contents all right. But this of course breaks other things. ;)

screen shot 2015-08-19 at 14 58 48 screen shot 2015-08-19 at 14 58 43

Gurpartap commented 9 years ago

Basically need something like this.hideLayersExceptFromGroup(root, layer, currentGroup); instead of this.hideLayers(root, layer);.

Currently just getting rid of this.hideLayers(root, layer); means it'll include everything in exported asset (i.e. layers from outside the group).

Gurpartap commented 9 years ago

@cmyk Here you go:

if (target.className() == "MSSliceLayer" && currentLayer == [target parentGroup]) {
    continue;
}

Insert this below var currentLayer = [[root layers] objectAtIndex:k]; in hideLayers function. If all goes well, I'll make a pull request for this. Let me know.

cmyk commented 9 years ago

@Gurpartap Great, it works! Thx!