🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #20202

Re: Question about polygons

#20202
From: Olav Kvern
Date: Mon, 05 Aug 2002 19:01
72 lines
3570 bytes
Reinhard-- 

To draw any any regular equilateral polygon, you can use InDesign's polygon drawing capabilities (like using the Polygon tool). 

Here's an example that draws a hexagon. 

Dim myInDesign As InDesign.Application 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
myInDesign.PolygonPreferences.NumSides = 6 
myInDesign.PolygonPreferences.InsetPercentage = 0 
Set myDocument = myInDesign.Documents.Add 
Set myPage = myDocument.Pages.Item(1) 
Set myPolygon = myPage.Polygons.Add 
myPolygon.GeometricBounds = Array("6p", "6p", "24p", "24p") 
 

But you can see the problem--the polygon is distorted. Most of the time, the geometric bounds of a regular, equilateral polygon cannot be contained by a square. You could calculate the correct rectangular area of the polygon, but I think it's easier to use a general purpose routine I wrote to draw polygons point-by-point: 

Private Sub myDrawPolygonButton_Click() 
Dim myInDesign As InDesign.Application 
Dim myPage As InDesign.Page 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
Set myDocument = myInDesign.ActiveDocument 
myDocument.ViewPreferences.HorzMeasurementUnits = idMSPoints 
myDocument.ViewPreferences.VertMeasurementUnits = idMSPoints 
Set myPage = myDocument.Pages.Item(1) 
Rem Draw four equilateral polygons 
myDrawPolygon 78, 3, 0, 0, myPage 
myDrawPolygon 72, 6, 0, 0, myPage 
myDrawPolygon 66, 12, 0, 0, myPage 
myDrawPolygon 60, 24, 0, 0, myPage 
End Sub 
Rem Misc. utility functions follow 
Private Sub myDrawPolygon(myRadius, myNumberOfSides, myXCenter, myYCenter, myPage) 
Dim myAngle As Double 
myAngleIncrement = 360 / myNumberOfSides 
Set myPolygon = myPage.Lines.Add 
Set myPath = myPolygon.Paths.Item(1) 
For myCounter = 1 To myNumberOfSides + 1 
����If myCounter <= 2 Then 
��������Set myPathPoint = myPath.PathPoints.Item(myCounter) 
����Else 
��������Set myPathPoint = myPath.PathPoints.Add 
����End If 
����myAngle = myAngleIncrement * (myCounter - 1) 
����myX = myXCenter + (myCosine(myAngle) * myRadius) 
����myY = myYCenter - (mySine(myAngle) * myRadius) 
����myPathPoint.Anchor = Array(myX, myY) 
Next 
myPath.PathType = idClosed 
End Sub 
Function myRadians(myAngle As Double) 
pi = 3.14159265358979 
myRadians = myAngle * (pi / 180) 
End Function 
Function myDegrees(myAngle As Double) 
pi = 3.14159265358979 
myDegrees = myAngle * (180 / pi) 
End Function 
Function myCosine(myAngle As Double) 
myCosine = Cos(myRadians(myAngle)) 
End Function 
Function mySine(myAngle As Double) 
mySine = Sin(myRadians(myAngle)) 
End Function 
 

Does that make sense? Don't worry about your English--it's far better than my German! 

Thanks, 

Ole
Technical Details
Message-ID: <efa02f9.0@WebX.aaQKaf7vad4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-06!sn-xit-04!supernews.com!newsfeed.gamma.ru!Gamma.RU!colt.net!diablo.netcom.net.uk!netcom.net.uk!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <efa02f9.-1@WebX.aaQKaf7vad4>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f939a,326e7b55e86de689
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2002-08-05 12:09:59 PST
From: "Olav Kvern" <okvern@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-06!sn-xit-04!supernews.com!newsfeed.gamma.ru!Gamma.RU!colt.net!diablo.netcom.net.uk!netcom.net.uk!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Question about polygons
Message-ID: <efa02f9.0@WebX.aaQKaf7vad4>
Date: Mon, 5 Aug 2002 12:01:56 -0700
References: <efa02f9.-1@WebX.aaQKaf7vad4>
Lines: 79
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit