Change Line and Trace to PolyLine with user defined thickness

Ease of Use


Version tested with


Submitted by:



This routine will change all lines and traces to a polyline with a thickness. 


This routine was developed due to the newer versions of Autocad will print a very thin line which is almost invisble. When the drawings are exported or embedded in another file, the line thickness is 0. This routine will correct the line thickness problem. 


instructions for use


Option Explicit Sub CommandButton1_Click() Dim entry As AcadObject Dim MyLine As AcadLine Dim MyTrace As AcadTrace Dim MyPoly As AcadPolyline Dim MyThick As Double Dim MyLineType As ACAD_LTYPE Dim MyPoints(0 To 5) As Double Dim CordPoints If TextBox1.Text > vbNullString Then MyThick = TextBox1.Text Else MyThick = 0.003 '<- default thickness if none is entered End If For Each entry In ThisDrawing.ModelSpace If TypeOf entry Is AcadLine Then Set MyLine = entry MyLineType = MyLine.Linetype MyPoints(0) = MyLine.EndPoint(0) MyPoints(1) = MyLine.EndPoint(1) MyPoints(2) = 0 MyPoints(3) = MyLine.StartPoint(0) MyPoints(4) = MyLine.StartPoint(1) MyPoints(5) = 0 Set MyPoly = ThisDrawing.ModelSpace.AddPolyline(MyPoints) MyPoly.ConstantWidth = MyThick MyPoly.Linetype = MyLineType MyPoly.Update MyLine.Delete ElseIf TypeOf entry Is AcadTrace Then Set MyTrace = entry CordPoints = MyTrace.Coordinate(0) MyPoints(0) = CordPoints(0) MyPoints(1) = CordPoints(1) MyPoints(2) = CordPoints(2) CordPoints = MyTrace.Coordinate(3) MyPoints(3) = CordPoints(0) MyPoints(4) = CordPoints(1) MyPoints(5) = CordPoints(2) Set MyPoly = ThisDrawing.ModelSpace.AddPolyline(MyPoints) MyPoly.ConstantWidth = MyThick MyPoly.Update MyTrace.Delete End If Next entry Set entry = Nothing Set MyTrace = Nothing Set MyPoly = Nothing Set MyLine = Nothing Unload Me End Sub

How to use:

  1. Open Autocad
  2. Open an existing drawing for testing
  3. Pick -> Tools -> Macro -> Visual Basic Editor
  4. In the window that pops up at the top Pick -> Insert -> UserForm
  5. On this userForm insert a command button (commandbutton1 should be the name) and a textbox (textbox1 should be the name) Add a label, and change the caption to read "Enter Line Thickness".
  6. Double click the form to open the code window. In this window paste the code posted above.
  7. Pick Tools -> AutocadProject Properties In the dialog box type a name for this project.
  8. Save it

Test the code:

  1. Load the project, and go to the VB editor pick the user form and press F5. The userform will appear. If a new thickness is not entered the default is 0.003. Pick the command button. All lines and traces have been changed to polylines with the thickness specified. The speed will be determined by the amount of data changed.

Sample File:

sample.ZIP 106.3KB 

Approved by mdmackillop

This entry has been viewed 98 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express