Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get width and height of selected Rectangle [VB}

89 views
Skip to first unread message

Dennis Hillen

unread,
May 20, 2003, 7:32:10 PM5/20/03
to
Hi all,
I want to write a script that gets the dimensions of a selected Rectangle or TextFrame and then divide that Rectangle or TextFrame into so many down and so many across. Basically, I want to use the Step And Repeat function, but worked out from a drawn shape, with the user saying how many across and how many down and the amount of gap between them. (Actually, I think it would be a nice function to have as part of the program).
However, I am having trouble finding out how to get the original dimensions, and of course need to know the top left point of the frame to start placing the new frames.
I assume this has to come from the GeometricBounds, but how do you do it?
Appreciate all help.
Dennis

reyman

unread,
May 21, 2003, 3:30:35 AM5/21/03
to

reyman

unread,
May 21, 2003, 3:31:19 AM5/21/03
to
I hope help you

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

Dennis Hillen

unread,
May 21, 2003, 6:00:22 PM5/21/03
to
Thank you Reyman, that's all I needed. So simple when you look at it.
Cheers
Dennis

Dennis Hillen

unread,
May 21, 2003, 8:38:27 PM5/21/03
to
Well, I thought it was simple.

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

Olav Kvern

unread,
May 21, 2003, 9:27:19 PM5/21/03
to
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

Dennis Hillen

unread,
May 22, 2003, 2:15:03 AM5/22/03
to
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

0 new messages