<NME> get-place.cocoascript
<BEF> // types:
// -1 - unsupported
// 1  - group, image, shape
// 2  - rectangle
// 3  - oval
// 4  - text layer


// returns width, height, x, y
function getPosition(layer, type, isStillExportable) {
	if (layer == nil) { return nil }

	if (type == nil) { type = TypeInventory.getObjectType(layer) }
	if (isStillExportable == nil) { if (showLog) { log("Warning: isStillExportable is unknown") } }

	if (isStillExportable && (type == 2 || type == 3)) { return getPlace(layer, false) }
	return getPlace(layer, true)
}





var normaliseLayer = function(layer) {
	var currentPage = currentDocument.currentPage()

  var existingRotation = [layer rotation]
  [layer setRotation: 0]

	var layer_copy = [layer duplicate]
	[layer_copy removeFromParent]
	[currentPage addLayers: [layer_copy]]

	var frame = [layer_copy frame]
	[frame setX: [[layer absoluteRect] x]]
	[frame setY: [[layer absoluteRect] y]]

	[layer_copy setRotation: 0]
	[[[layer_copy style] contextSettings] setOpacity:(1.0)]
	[layer_copy setIsVisible:true]

  [layer setRotation: existingRotation]
	return layer_copy
}


var getAbsolutePlaceImage = function(layer) {
	if (layer == nil) { return [100, 100, 0, 0] }
	var normalisedLayer = normaliseLayer(layer)
	var temp = MSSliceTrimming.trimmedRectForLayerAncestry(MSImmutableLayerAncestry.ancestryWithMSLayer(normalisedLayer))
	var values = [temp.size.width, temp.size.height, temp.origin.x, temp.origin.y]

	[normalisedLayer removeFromParent]
	return values
}


var getAbsolutePlaceRect = function(layer) {
	if (layer == nil) { return nil }
	if (TypeInventory.isPageType([layer className])) { return [0,0,0,0] }

	var normalisedRect = normaliseLayer(layer)
	var values = [[[normalisedRect frame] width], [[normalisedRect frame] height], [[normalisedRect absoluteRect] x], [[normalisedRect absoluteRect] y]]

	[normalisedRect removeFromParent]
	return values
}


var getAbsolutePlaceArtboard = function(artboard) {
		// log("?inside " + [artboard className] + " " + [artboard name])
		// log(TypeInventory.isArtboardType(artboard))
		if (artboard == nil) { return nil }

		return [[[artboard frame] width], [[artboard frame] height], artboard.rulerBase().x.integerValue(), artboard.rulerBase().y.integerValue()]
}











// support

var getY = function(layer, parentLayer) {
	var parentY = [[parentLayer absoluteRect] y]
	return [[layer absoluteRect] y]
}

var getX = function(layer, parentLayer) {
	var parentX = [[parentLayer absoluteRect] x]
	return [[layer absoluteRect] x]
}

var getHeight = function(layer) {


	var layerValues = (isImage) ? getAbsolutePlaceImage(layer) : getAbsolutePlaceRect(layer)
	var resultValues = [layerValues[0], layerValues[1], layerValues[2] - parentValues[2], layerValues[3] - parentValues[3]]

	return resultValues
}

<MSG> Fixed getPosition

1) Normalized position
2) Improved output

<DFF> @@ -84,17 +84,18 @@ var getPlaceRect = function(layer, axisLayer) {
 
 
 
-
 // support
 
 var getY = function(layer, parentLayer) {
 	var parentY = [[parentLayer absoluteRect] y]
-	return [[layer absoluteRect] y]
+	var layerY = [[layer absoluteRect] y]
+	return -(parentY - layerY)
 }
 
 var getX = function(layer, parentLayer) {
 	var parentX = [[parentLayer absoluteRect] x]
-	return [[layer absoluteRect] x]
+	var layerX = [[layer absoluteRect] x]
+	return -(parentX - layerX)
 }
 
 var getHeight = function(layer) {

Fixed getPosition