Using VBA to draw a line using selected points

Using VBA to draw a line using selected points

Anonymous
Not applicable
8,901 Views
2 Replies
Message 1 of 3

Using VBA to draw a line using selected points

Anonymous
Not applicable

I'm brand new at VBA in AutoCAD and I'm having difficulties finding information on how to do this very basic task.

 

I would like to draw a line using user picked points.  I have that working but because of the way it's programmed it's looking for both points before it draws the line meaning you can not see the line until the command is finished, unlike the native AutoCAD "line" command where you can see where the line will be before you've selected the finish point.

 

Is there a way to use VBA to draw a line that will look like the native "line" command, IE: show the line and follow the mouse after clicking the first point?

 

This is my code so far...

 

Private Sub cmdDraw_Click()

Dim Start As Variant
Dim Finish As Variant
Dim Dline As AcadLine

frmDline.hide

Start = ThisDrawing.Utility.GetPoint(, "select point :")
Finish = ThisDrawing.Utility.GetPoint(, "select point :")

Set Dline = ThisDrawing.ModelSpace.AddLine(Start, Finish)

frmDline.show

End Sub

 

Thanks in advance.

0 Likes
8,902 Views
2 Replies
Replies (2)
Message 2 of 3

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

I have disabled the form-hide/show to get it work for me in the sample

And look to the second .GetPoint ==> there I have changed the first parameter to your base-point, so you get the drag-line shown.

 

Public Sub createLine()
    Dim Start As Variant
    Dim Finish As Variant
    Dim Dline As AcadLine
    'frmDline.hide
    Start = ThisDrawing.Utility.GetPoint(, "select point :")
    Finish = ThisDrawing.Utility.GetPoint(Start, "select point :")
    Set Dline = ThisDrawing.ModelSpace.AddLine(Start, Finish)
    'frmDline.show
End Sub

 HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 3 of 3

Anonymous
Not applicable

Thanks for the amazingly quick reply.

 

That worked but if I don't have the form.hide/show I get an error stating the AutoCAD main window is invisible.  I added the form.hide/show based on someone else that  had that problem.

0 Likes