<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) {
	var localType = 0
	
	if (type == nil) { localType = exportableType(layer) }
	else {
		localType = type
	}
	
	if (localType == 1) {
		return getPlaceImage(layer)
	}
	else if (localType == 2 || localType == 3) {
		return getPlaceRect(layer)
	}
	else if (localType == 5) {
		return getPlaceRect(layer)
	}
	else {
		log("ERROR: Unsupported type for position")
		return nil
	}
}


	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()]
}










var getPlace = function(layer, isImage) {
	if (layer == nil) { return [100, 100, 0, 0] }
	if (TypeInventory.isArtboardType(layer)) { return getAbsolutePlaceRect(layer) }

	var currentPage = currentDocument.currentPage()
	var parentValues = nil

	if (userDefaults.myRelativeGroup == 1 && (StatisticsInventory.getStatus() == Status.generateID() || StatisticsInventory.getStatus() == Status.replicateID())) {
		// TODO: Check if the parent can be... hard to say here. It can be rect with shadow and this rect is exportable but group is image
		parentValues = getAbsolutePlaceImage([layer parentGroup])
	}
	else {
		parentValues = getAbsolutePlaceArtboard(TypeInventory.findParentArtboard(layer))
		// parentValues = getAbsolutePlaceRect(TypeInventory.findParentArtboard(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

Actually, we should get position after we know all states of the
element -> we can decide does it exportable with image or not only at
this point.

todo: clean some unused positions?? or not (they’re used for comparison
between two states)

<DFF> @@ -7,28 +7,36 @@
 
 
 
+// // returns width, height, x, y
+// function getPosition(layer, type) {
+// 	var localType = 0
+//
+// 	if (type == nil) { localType = exportableType(layer) }
+// 	else {
+// 		localType = type
+// 	}
+//
+// 	if (localType == 1) {
+// 		return getPlaceImage(layer)
+// 	}
+// 	else if (localType == 2 || localType == 3) {
+// 		return getPlaceRect(layer)
+// 	}
+// 	else if (localType == 5) {
+// 		return getPlaceRect(layer)
+// 	}
+// 	else {
+// 		log("ERROR: Unsupported type for position")
+// 		return nil
+// 	}
+// }
+
+
+
 // returns width, height, x, y
-function getPosition(layer, type) {
-	var localType = 0
-	
-	if (type == nil) { localType = exportableType(layer) }
-	else {
-		localType = type
-	}
-	
-	if (localType == 1) {
-		return getPlaceImage(layer)
-	}
-	else if (localType == 2 || localType == 3) {
-		return getPlaceRect(layer)
-	}
-	else if (localType == 5) {
-		return getPlaceRect(layer)
-	}
-	else {
-		log("ERROR: Unsupported type for position")
-		return nil
-	}
+function getPosition(layer, isStillExportable) {
+	if (isStillExportable) { return getPlaceRect(layer) }
+	return getPlaceImage(layer)
 }
 
 

Fixed getPosition