marcisme / sketch-preview

Sketch plugin to preview mockups in Skala Preview
MIT License
610 stars 37 forks source link

Only exports artboard to Skala. #3

Closed jelias closed 10 years ago

jelias commented 10 years ago

I was testing the plugin today, and found that even when I have slices named Preview the plugin still exports the entire artboard to Skala Preview.

marcisme commented 10 years ago

Are you using your fork or mine? I think your branch has the artboard check first, which will behave this way if an artboard is selected.

jelias commented 10 years ago

No I downloaded the most recent version (v 0.2) 20 minutes before creating the issue.

marcisme commented 10 years ago

I pushed up a test document that works on my system. Can you try to reproduce with that?

Also what locale is your system? One of the changes I made was to use the Cocoa APIs for string comparison, so I could have screwed that up.

marcisme commented 10 years ago

Is this an artboard with a Preview slice within it? I've only tested a Preview slice that's not in an artboard, so that could also be the problem.

jelias commented 10 years ago

Yeah it was an artboard with Preview slice inside.

So then I made a new document, no artboards, made a beautiful rectangle, and made a preview slice. Worked perfectly. Guess previewing selected layers is out.

marcisme commented 10 years ago

I added an artboard with its own Preview slice to the test document, but that one works for me too. Is that a reasonable approximation of what you were doing? Or are you trying to be able to select a layer within an Artboard and preview just that layer?

jelias commented 10 years ago

Or are you trying to be able to select a layer within an Artboard and preview just that layer?

Bingo. I was just playing with the plugin and wanted to see if you could preview only a certain layer within an artboard. Like if you were making a logo and wanted to preview it, but only the logo, no backgrounds, nothing else.

marcisme commented 10 years ago

I don't see anything that looks like current selection or layer. However there is an isSelected property on MSLayer, so it might be possible to iterate on the layers for the current artboard and find the one where that property is true. Assuming that works, I can think of a couple issues.

  1. Positioning. If the selected layer doesn't fill the whole screen, when it gets written out to an image file and opened, it's probably not going to be in the right place. There may be enough information available to work around this, but I'm not sure how complicated it would be.
  2. The more common case will probably be that the user has just changed something on a particular layer, leaving it selected, and they will want to see the full artboard preview. It would probably make sense to have separate commands for previewing of the current artboard vs the selected layer. That introduces the complexity of avoiding duplication between the two plugins. I think the most recent version of Cocoa Script has a basic @import directive that would facilitate this, but I don't think Sketch is on that version yet, and I don't know if something similar is possible with older versions.
bomberstudios commented 10 years ago

I don't see anything that looks like current selection or layer. However there is an isSelected property on MSLayer, so it might be possible to iterate on the layers for the current artboard and find the one where that property is true.

Maybe I'm just being thick here, but what about selection?

It's an NSArray of the selected layers, and you can easily iterate through it by either using JavaScript style for...loops:

for (var i=0; i < [selection length] ; i++) {
  var item = selection[i]
}

or by using Obj-C style iterators:

var iterator = [selection objectEnumerator]
while (item = iterator.nextObject()) {
  // do something with item
}
marcisme commented 10 years ago

@bomberstudios I think you're correct. Thanks for pointing that out. I also see from your plugins that #import would solve my duplication concerns. Lots of good stuff in there, I'm going to have to study what you've done.

@jelias What do you think about positioning? I assume you'd want the layer to show up wherever it'd be in the full screen mockup.

bomberstudios commented 10 years ago

@marcisme feel free to browse my code and take what you need : )