Get width and height function

Here's a function that returns the width and height if the object in question has one (e.g. Cells and Tables). I test for geometric bounds first because that's the most likely scenario.

If the properties are unavailable, it returns null.

Main();

function Main() {
	var obj = app.selection[0];
	var W_H = GetWidthAndHeight(obj);
}

function GetWidthAndHeight(obj) {
	var result = null;
	
	if (obj.hasOwnProperty("geometricBounds")) {
		var gb = obj.geometricBounds;
		result = {width: gb[3] - gb[1], height: gb[2] - gb[0]};
	}
	else if (obj.hasOwnProperty("width") && obj.hasOwnProperty("height")) {
		result = {};
		result.width = obj.width;
		result.height = obj.height;
	}
	
	return result;
}

Click here to download the function.