<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]]

var getPlaceImage = function(layer, axisLayer, currentPage) {
	
	var baseLayerFrame = [layer absoluteRect]
	var parentArtboard = axisLayer
	if ([axisLayer className] != "MSArtboardGroup") {
		parentArtboard = findParentArtboard(layer)
	}

	var layer_copy = [layer duplicate]
	[layer_copy setRotation: 0]
	if ([[[layer_copy style] contextSettings] opacity] == 0) {
		[[[layer_copy style] contextSettings] setOpacity:(1.0)]
	}
	if (![layer_copy isVisible]) {
		[layer_copy setIsVisible:true]
	}
	[layer_copy removeFromParent]
	[currentPage addLayers: [layer_copy]]

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

	var temp = [MSSliceTrimming trimmedRectForSlice:layer_copy];
	var valueX = temp.origin.x
	var valueX = temp.origin.y
	var valueWidth = temp.size.width
	var valueHeight = temp.size.height
	
	var values = [temp.size.width, temp.size.height, temp.origin.x - [[axisLayer absoluteRect] x], temp.origin.y - [[axisLayer absoluteRect] y]]

	[layer_copy removeFromParent]
	
	return values
}

		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
}

var getWidth = function(layer) {
	return [[layer frame] width]
}

<MSG> Fixed origin point for rotated images

Seems like fixed error for rotated images

<DFF> @@ -36,37 +36,37 @@ function getPlace(layer, axisLayer, currentPage) {
 
 var getPlaceImage = function(layer, axisLayer, currentPage) {
 	
-	var baseLayerFrame = [layer absoluteRect]
 	var parentArtboard = axisLayer
 	if ([axisLayer className] != "MSArtboardGroup") {
 		parentArtboard = findParentArtboard(layer)
 	}
 
+
+	// copy layer and place it to artboard
 	var layer_copy = [layer duplicate]
+	[layer_copy removeFromParent]
+	[currentPage addLayers: [layer_copy]]
+	
+	
+	// normalize layer for export
 	[layer_copy setRotation: 0]
 	if ([[[layer_copy style] contextSettings] opacity] == 0) {
 		[[[layer_copy style] contextSettings] setOpacity:(1.0)]
 	}
-	if (![layer_copy isVisible]) {
-		[layer_copy setIsVisible:true]
-	}
-	[layer_copy removeFromParent]
-	[currentPage addLayers: [layer_copy]]
-
-	var frame = [layer_copy frame]
-	[frame setX: [[layer absoluteRect] x]]
-	[frame setY: [[layer absoluteRect] y]]
-
+	if (![layer_copy isVisible]) { [layer_copy setIsVisible:true] }
+		
+		
+	var values = []
 	var temp = [MSSliceTrimming trimmedRectForSlice:layer_copy];
-	var valueX = temp.origin.x
-	var valueX = temp.origin.y
-	var valueWidth = temp.size.width
-	var valueHeight = temp.size.height
-	
-	var values = [temp.size.width, temp.size.height, temp.origin.x - [[axisLayer absoluteRect] x], temp.origin.y - [[axisLayer absoluteRect] y]]
-
-	[layer_copy removeFromParent]
+	if ([axisLayer className] == "MSArtboardGroup" ) {
+		values = [temp.size.width, temp.size.height, temp.origin.x, temp.origin.y]
+	}
+	else {
+		log("WARNING! UNEXPECTED BEHAVIOUR")
+		values = [temp.size.width, temp.size.height, temp.origin.x, temp.origin.y]
+	}
 	
+	[layer_copy removeFromParent]	
 	return values
 }
 
@@ -117,4 +117,8 @@ var getHeight = function(layer) {
 
 var getWidth = function(layer) {
 	return [[layer frame] width]
-}
\ No newline at end of file
+}
+
+
+
+

Fixed origin point for rotated images