Add new artboard with Sketch Plugin - cocoa

I'm trying to build my first Sketch Plugin that starts by adding a new Artboard to the page. Sketch plugins use JSTalk, and in the Bohemian Coding documentation it states that Artboards are a type of layer, so one would think you could use addLayerOfType to insert a new artboard.
This is what I'm doing to try and create a new Artboard, using the JS Syntax:
var page = doc.currentPage()
var artboard = page.addLayerOfType("artboard")
However if I log() the output of artboard I get (null). I've also tried it with Cocoa syntax:
var page = [doc currentPage]
var artboard = [page addLayerOfType:"artboard"]
No luck. Anyone know how I can do this?

Referencing the MSPage documentation, it look like you need to use the addLayer method.
artboards
Returns a readonly array of all artboards on the page. If you want to
add a new artboard to a page, use the addLayer method.
addLayer
Adds an MSLayer to the page. For example, if you want to add an
800x600 artboard to the current page, you'd do this:
var artboard = [MSArtboardGroup new]
var frame = [artboard frame]
[frame setX:0]
[frame setY:0]
[frame setWidth:800]
[frame setHeight:600]
[[doc currentPage] addLayer:artboard]

Related

How dynamically increase or decrease the number of split view's of a view controller in Mac

I have try to find out programatically add the number of split's of a view controller as per our requirement based upon situation. For example initially we have set a 3 split's view to the view controller page and after some operations we want increase the another split in that view controller. As like that we can able to modify the number of split's count dynamically is my requirement. Please suggest any idea. Thanks in advance.
NSSplitViewController has three methods for manipulating with the NSSplitViewItem array.
AddSplitViewItem
RemoveSplitViewItem
InsertSplitViewItem
Example:
MySplitViewController = new MySplitViewController(); // a NSSplitViewController subclass
var splitViewItem = new NSSplitViewItem();
splitViewItem.ViewController = new RandomViewControllerController();
MySplitViewController.AddSplitViewItem(splitViewItem);
var splitViewItem2 = new NSSplitViewItem();
splitViewItem2.ViewController = new RandomViewControllerController();
MySplitViewController.AddSplitViewItem(splitViewItem2);
PresentViewControllerAsModalWindow(MySplitViewController);
Re: https://developer.apple.com/reference/appkit/nssplitviewcontroller

Getting page dimensions

On navigating to a new page, how do I get the dimensions of the page - the client/layout area only - exclude the action bar if present.
Will I get the same notification when the device orientation changes?
Thanks.
Every view in NativeScript has a method call getMeasuredHeight() as well as getMeasuredWidth(). You can get the page dimensions like this:
var pageHeight, pageWidth;
pageHeight = page.getMeasuredHeight()- page.actionBar.getMeasuredHeight();
pageWidth = page.getMeasuredWidth()- page.actionBar.getMeasuredWidth();

How to resize a sublayer in view with in Swift?

I have a session with AVfoundation to record a video and take phootos, and this session is necessary add to a view to show this. I add this with this code:
var previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer.layerWithSession(self.session) as AVCaptureVideoPreviewLayer
previewLayer.frame = self.imagePreview.bounds
self.imagePreview.layer.addSublayer(previewLayer)
imagePreviw is the UIView.
This is adding correctly, but the session camera only show in a part of the view, how can I show this in all view?
I add picture to show the problem and that I want:
I think the frame is correct but I think you should set the videoGravity like this:
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

Animate Button size, then revert to null

I am trying to create an animation to make it look like a button turns over and the back shows. So what I was trying to do is:
1- Show a button with BackgroundColor x. (The button now has a Width of null, the property ActualWidth does have a value.)
2- Create a double animation that changes the width of the button to zero.
DoubleAnimation widthAnimation = new DoubleAnimation();
widthAnimation.From = this.ActualWidth;
widthAnimation.To = 0;
widthAnimation.SpeedRatio = 3;
widthAnimation.Duration = TimeSpan.FromMilliseconds(800);
3- Change the BackgroundColor of the button.
ColorAnimation colorAnimation = new ColorAnimation();
colorAnimation.From = State ? _xColor : _yColor;
colorAnimation.To = State ? _yColor : _xColor;
colorAnimation.BeginTime = TimeSpan.FromMilliseconds(400);
colorAnimation.Duration = TimeSpan.Zero;
4- Change the width back to it's original value.
widthAnimation.AutoReverse = true;
The problem is when the animation runs twice the animation reads this.ActualWidth while animating, which causes it to fail to the original width. How can I solve this? I would like to set the Width back to null again, but it seems impossible to me.
You'd better use xaml style and template to "declare" what you want and let WPF/Silverlight take care of all.
If you try to do the same thing by code you can do it but you need to know what the framework does behind the scenes.
Basically you can set
- Style to define the values of some properties of the control
- DataTemplate to define the visual representation of the control's content
- ControlTemplate to define the appearance of the control
Each of those can have Triggers
- Property Triggers
to set properties or starts actions, such as an animation
when a property value changes or when an event is raised;
EventTriggers and Storyboards
to start a set of actions based on the occurrence of an event
If you like to learn about XAML Style and Template,
take a look at http://msdn.microsoft.com/en-us/library/ms745683.aspx
Spend a day to learn and save many hours (or days) of try and error and frustration!
To go right to the point, in your case I think you should use a Storyboard.
See http://msdn.microsoft.com/en-us/library/ms742868.aspx
where you can find also the code equivalent of XAML examples
I came to the idea to targetting the MaxWidth instead of the actual Width. I now use a KeyFrameCollection which sets the MaxWidth to int.MaxValue at the start (so also at the end when using autoreverse).
It will work fine untill there will be phones with a resolution bigger than the max int value.
The code:
DoubleAnimationUsingKeyFrames widthAnimation = new DoubleAnimationUsingKeyFrames();
widthAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame()
{
KeyTime = TimeSpan.Zero,
Value = int.MaxValue,
});
widthAnimation.KeyFrames.Add(new LinearDoubleKeyFrame()
{
KeyTime = TimeSpan.FromMilliseconds(1),
Value = ActualWidth,
});
widthAnimation.KeyFrames.Add(new LinearDoubleKeyFrame()
{
KeyTime = TimeSpan.FromMilliseconds(400),
Value = 0,
});
widthAnimation.Duration = TimeSpan.FromMilliseconds(400);
widthAnimation.AutoReverse = true;

ActionScript 2 loadClip depth

When I use:
loader = new MovieClipLoader();
_root.createEmptyMovieClip("level1",getNextHighestDepth());
_root.level1.createEmptyMovieClip("image",getNextHighestDepth());
loader.loadClip("http://someimage.jpg",_root.level1.image);
...it works and the image shows up.
But when I use:
loader = new MovieClipLoader();
_root.createEmptyMovieClip("level1",getNextHighestDepth());
_root.level1.createEmptyMovieClip("level2",getNextHighestDepth());
_root.level1.level2.createEmptyMovieClip("image",getNextHighestDepth());
loader.loadClip("http://someimage.jpg",_root.level1.level2.image);
...the image doesn't show up. Can anyone tell me why? How can I make this work?
the depth you are supplying is going to be '1'. is that what you are expecting?
each movie clip has it's own set of depths, so the nextHighestDepth() of the newly create 'image' mc, will be 1. it should not prevent loading the image though.
As gthmb says, you should call getNextHighestDepth() on the same MovieClip as you do the createEmptyMovieClip() on. So your code example should be more like:
loader = new MovieClipLoader();
_root.createEmptyMovieClip("level1",_root.getNextHighestDepth());
_root.level1.createEmptyMovieClip("level2",_root.level1.getNextHighestDepth());
_root.level1.level2.createEmptyMovieClip("image",_root.level1.level2.getNextHighestDepth());
loader.loadClip("http://someimage.jpg",_root.level1.level2.image);
Also, I would recommend storing references to the created MovieClips, so you won't have to use the full path in each occurrence in the code, something in the lines of this:
loader = new MovieClipLoader();
var level1:MovieClip = _root.createEmptyMovieClip("level1",_root.getNextHighestDepth());
var level2:MovieClip = level1.createEmptyMovieClip("level2",level1.getNextHighestDepth());
var image:MovieClip = level2.createEmptyMovieClip("image",level2.getNextHighestDepth());
loader.loadClip("http://someimage.jpg",image);

Resources