Last active
November 3, 2015 23:20
-
-
Save isonno/62a8b1ef6ca854e85a58 to your computer and use it in GitHub Desktop.
Sample DS code for creating a vector mask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Code sample for creating a rectangular vector mask | |
// around the target paint layer. J. Peterson | |
// | |
function getLayerBounds() | |
{ | |
var p = new Promise(function(resolve, reject) | |
{ | |
_spaces.ps.descriptor.get({_ref:[{"_ref":"property","_property":"bounds"}, | |
{"_ref":"layer", | |
"_enum":"ordinal", | |
"_value":"targetEnum"}]}, {}, | |
function(err, desc) { | |
if (err) | |
reject(err) | |
else | |
resolve(desc.bounds); | |
}); | |
}); | |
return p; | |
} | |
//function dbgBounds(b) {console.log("b.left:" + b.left._value);} | |
//getLayerBounds().then(dbgBounds); | |
function promisePlay( action, reference ) | |
{ | |
return new Promise(function(resolve, reject) { | |
_spaces.ps.descriptor.play(action, reference, {}, | |
function (err) | |
{ | |
if (err) | |
reject(err); | |
else | |
resolve(err); | |
} ); | |
}); | |
} | |
function makeBoundsWorkPath(bounds) | |
{ | |
return promisePlay("set", {"null":{"_ref":[{"_ref":"path", | |
"_property":"workPath"}]}, | |
"to":{"_obj":"rectangle", "_value":bounds}} ); | |
} | |
function makeVectorMaskFromWorkPath() | |
{ | |
var maskRef = {"_ref":[{"_ref":"path","_enum":"path", "_value":"vectorMask"}]}; | |
var pathRef = {"_ref":[{"_ref":"path","_enum":"ordinal","_value":"targetEnum"}]}; | |
return promisePlay("make", {"null":{"_ref":[{"_ref":"path"}]}, | |
"at":maskRef, "using":pathRef} ); | |
} | |
function deleteWorkPath() | |
{ | |
return promisePlay("delete", {"null":{"_ref":[{"_ref":"path", "_property":"workPath"}]}} ); | |
} | |
function createBoundsMask() | |
{ | |
getLayerBounds().then(makeBoundsWorkPath) | |
.then(makeVectorMaskFromWorkPath) | |
.then(deleteWorkPath) | |
.catch(function (err) { console.log("Failed!:" + err); }); | |
} |
Update for new descriptor.get()
API
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cleaned up
createBoundsMask()