Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Polylines

Status
Not open for further replies.

TTops

MIS
Sep 13, 2004
70
US
Hello,

I'm runngin AutoCAD 2006 and have built an application with VBA. I've got the following code in my application in an attempt to create a six sided shape programmatically:

Private Sub cmdTest_Click()
Dim Points(5) As Double
Dim PLine As AcadLWPolyline
Dim SelectionSet As AcadSelectionSet

Points(0) = 20: Points(1) = 20: Points(2) = 20
Points(3) = 20: Points(4) = 20

Set AcadPolyline = ThisDrawing.ModelSpace.AddLightWeightPolyline(Points)
ZoomAll

End Sub

All I get is a straight line. What am I missing here? Any help is greatly appreciated.



Thanks,
T-Tops
 
Hi,

Your points array is wrong. What you need is a 3 point array point for each vertex of the polyline.
For example the code below is for a rectangular polyline.
With any coordinate entry, VB requires at least 2 points in the array for each end point or start point etc - Point(0) refers to the X coordinate, Point(1) refers to the Y coordinate and Point(2) refers to the Z coordinate of each point and then Point(3) will refer to the X of the next point and so on. So make sure you point array is in multiples of either 2 or 3, so for a rectangle, you'll need an array of 12 in total - which is 0 to 11). 5 as you have will confuse the program..

Code:
Dim Points(0 to 11) As Double 'Declare the variable..
Points(0) = 0: Points(1) = 0: Points(2) = 0 'Start point..
Points(3) = 20: Points(4) = 0: Points(5) = 0 '2nd point..
Points(6) = 20: Points(7) = 20: Points(8) = 0 '3rd point..
Points(9) = 0: Points(10) = 0: Points(11) = 0 'End point..

Set PLine = ThisDrawing.ModelSpace.AddLightWeightPolyline(Points)
Pline.Closed = True
ZoomAll

Some may debate whether you need the final point again, if you're going to Closed = True the polyline..

Also, note your line that creates the polyline itself, you need to set the variable name as the object not the object itself..

I hope i explained it ok, give me a shout if you need any more info..




Cheers,

Paul @ basepointdesignzltd..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top