Skip to content

Instantly share code, notes, and snippets.

@isonno
Last active November 3, 2015 23:20
Show Gist options
  • Save isonno/62a8b1ef6ca854e85a58 to your computer and use it in GitHub Desktop.
Save isonno/62a8b1ef6ca854e85a58 to your computer and use it in GitHub Desktop.
Sample DS code for creating a vector mask
//
// 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); });
}
@isonno
Copy link
Author

isonno commented Jul 10, 2015

Cleaned up createBoundsMask()

@isonno
Copy link
Author

isonno commented Nov 3, 2015

Update for new descriptor.get() API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment