Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here





     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)
End Sub

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


RE: Polylines


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..


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

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..


           Paul @ basepointdesignzltd..

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close