y1 = rectangle.GeometricBounds(0)
x1 = rectangle.GeometricBounds(1)
y2 = rectangle.GeometricBounds(2)
x2 = rectangle.GeometricBounds(3)
so if you want the width of the rectangle :
my_width = x2 - x1
I am getting a "Type mismatch" on the line: "myWidth = myX2 - myX1".
Can someone tell me why? Here is the code:
Dim myInDesign As InDesign.Application
Set myInDesign = CreateObject("InDesign.Application.2.0")
Set myDocument = myInDesign.ActiveDocument
If myInDesign.Selection.Count > 0 Then
Set mySelection = myInDesign.Selection
Select Case TypeName(mySelection.Item(1))
Case "Rectangle"
Set myFrame = mySelection.Item(1)
myY1 = myFrame.GeometricBounds(0)
myX1 = myFrame.GeometricBounds(1)
myY2 = myFrame.GeometricBounds(2)
myX2 = myFrame.GeometricBounds(3)
myStrokeWeight = myFrame.StrokeWeight
MsgBox myStrokeWeight
myWidth = myX2 - myX1
myHeight = myY2 - myY1
MsgBox "Width = " & myWidth & vbCrLf & _
"Height = " & myHeight & vbCrLf & _
"Stroke weight = " & myStrokeWeight
End
Case "TextFrame"
MsgBox "Found Text Frame."
End
Case Else
MsgBox "Must have Rectangle or Text Frame selected."
End
End Select
Else
MsgBox "Must have Rectangle or Text Frame selected."
End
End If
Cheers,
Dennis
You can't actually use the form:
myY1 = myFrame.GeometricBounds(0)
...yet (what that gives you is the full GeometricBounds array). Instead, do this:
myBounds = myFrame.GeometricBounds
myY1 = myBounds(0)
myX1 = myBounds(1)
myY2 = myBounds(2)
myX2 = myBounds(3)
Also, if you want to consider the stroke weight in your calculation, use VisibleBounds rather than GeometricBounds. (I'm not sure what you're doing with the myStrokeWeight variable, so I thought I'd mention it.)
Thanks,
Ole
And thanks for the tip on VisibleBounds rather than GeometricBounds.
Might mention we bought your book "Real World InDesign" last week and think it's great.
Thanks again,
Dennis