Skip to content

Instantly share code, notes, and snippets.

@cameronmcefee
Created February 12, 2015 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronmcefee/315e2230202716f6d437 to your computer and use it in GitHub Desktop.
Save cameronmcefee/315e2230202716f6d437 to your computer and use it in GitHub Desktop.
private function getDocumentInfo():Object {
var originalUnits:Units = photoshop.preferences.rulerUnits;
photoshop.preferences.rulerUnits = Units.PIXELS
var info:Object = {
hasOpenDocuments: photoshop.documents.length > 0,
ruler: friendlyUnits(originalUnits)
}
if(info.hasOpenDocuments) {
var doc:Document = photoshop.activeDocument
var ref:ActionReference = new ActionReference()
ref.putEnumerated(photoshop.charIDToTypeID("Dcmn"), photoshop.charIDToTypeID("Ordn"), photoshop.charIDToTypeID("Trgt"))
var desc:ActionDescriptor = photoshop.executeActionGet(ref)
var xOffset:Number = (desc.getInteger(photoshop.stringIDToTypeID("rulerOriginH"))/65536)*-1
var yOffset:Number = (desc.getInteger(photoshop.stringIDToTypeID("rulerOriginV"))/65536)*-1
info.resolution = doc.resolution
info.isSelection = doc.selection.bounds != null
info.existingGuides = getExistingGuides(xOffset, yOffset)
if(info.isSelection){
info.offsetX = parseInt(doc.selection.bounds[0]) + xOffset
info.offsetY = parseInt(doc.selection.bounds[1]) + yOffset
info.width = parseFloat(doc.selection.bounds[2]) - parseFloat(doc.selection.bounds[0])
info.height = parseFloat(doc.selection.bounds[3]) - parseFloat(doc.selection.bounds[1])
} else {
info.offsetX = xOffset+0
info.offsetY = yOffset+0
info.width = parseInt(doc.width.toString())
info.height = parseInt(doc.height.toString())
}
}
photoshop.preferences.rulerUnits = originalUnits
return info
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment