Coder Social home page Coder Social logo

Comments (6)

nichenqin avatar nichenqin commented on September 18, 2024 1

@everdrone try this:

copy.frame().setX_(300);
copy.frame().setY_(300);
copy.frame().setHeight_(300);
copy.frame().setWidth_(300);

from sketchapi.

mathieudutour avatar mathieudutour commented on September 18, 2024

be careful, new sketch.Rectangle() doesn't do what you expect. What you want is

var Rectangle = sketch.Rectangle
var rect = new Rectangle(0, 0, 100, 200)

from sketchapi.

everdrone avatar everdrone commented on September 18, 2024

still crashing

here is the code:

var sketch = context.api();

var document = sketch.selectedDocument;
var selection = document.selectedLayers;
var page = document.selectedPage;

if (selection.isEmpty) {
  sketch.message('empty');
} else {
  var original = selection.nativeLayers[0];
  var copy = original.duplicate();
  
  var Rectangle = sketch.Rectangle;
  var rect = new Rectangle(0, 0, 100, 200);
  copy.frame = rect;
}

ran from sketch-dev-tools' playground

from sketchapi.

mathieudutour avatar mathieudutour commented on September 18, 2024

you are mixing wrapped objects and native objects. copy is a native sketch layer so its frame expects a CGRect: copy.frame = rect.asCGRect();

This selection is a bit messy since there is no way to access a wrapped object from it :/ Hopefully it will be easier with the new API: https://github.com/BohemianCoding/SketchAPI/blob/feature/15747/docs/Selection.md

from sketchapi.

everdrone avatar everdrone commented on September 18, 2024

still crashing.

All i want to achieve is duplicate the selected layer and translate/resize it.

is there an easy way to do it with the current API?

from sketchapi.

everdrone avatar everdrone commented on September 18, 2024

it works! thanks @nichenqin

from sketchapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.