Adobe 27510753 Scripting Guide - Page 26
VBScript, Set myInDesign = CreateObjectInDesign.Application.CS2
UPC - 718659445294
View all Adobe 27510753 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 26 highlights
18 Scripting Basics Adobe InDesign CS2 Scripting Guide VBScript Rem Calculate the geometric center of a selected page item Rem Assumes you have a single page item selected. Set myInDesign = CreateObject("InDesign.Application.CS2") Set mySelection = myInDesign.Selection.Item(1) myCenterPoint = myCalculateCenterPoint(mySelection) MsgBox "x center: " & myCenterPoint(0) & vbCr & "y center: " & myCenterPoint(1) Function myCalculateCenterPoint(myObject) myBounds = myObject.GeometricBounds myX1 = myBounds(1) myY1 = myBounds(0) myX2 = myBounds(3) myY2 = myBounds(2) myXCenter = myX1 + ((myX2 - myX1) / 2) myYCenter = myY1 + ((myY2 - myY1) / 2) myCalculateCenterPoint = Array(myXCenter, myYCenter) End Function JavaScript with(app){ var mySelection = selection[0]; var myCenterPoint = myCalculateCenterPoint(mySelection); var myString = "x center: " + myCenterPoint[0] + "\n" + "y center: " + myCenterPoint[1]; alert(myString); } function myCalculateCenterPoint(myObject){ var myGeometricBounds = myObject.geometricBounds; var myX1 = myGeometricBounds[1]; var myY1 = myGeometricBounds[0]; var myX2 = myGeometricBounds[3]; var myY2 = myGeometricBounds[2]; var myXCenter = myX1 + ((myX2 - myX1)/2); var myYCenter = myY1 + ((myY2 - myY1)/2); return [myXCenter, myYCenter]; }