Extracting point coordinates while drawing a polyline

Extracting point coordinates while drawing a polyline

Anonymous
Not applicable
1,814 Views
1 Reply
Message 1 of 2

Extracting point coordinates while drawing a polyline

Anonymous
Not applicable

Hello Guys,

 

I have a code which can extract the x,y,z coordinate of a point to excel when I click on it in Autocad2016. However I would like to draw polylines from point to point while I am extracting their coordinates into my excel sheet. When I click on the polyline feature and then run the macro below I get an error. I want to draw the polyline so I can keep a check on which node I have already extracted info from.

 

Please see my code below

 

Sub Example_GetPoint()

'Connect to the AutoCAD application and drawing
Dim AcadApp As AcadApplication
Set AcadApp = GetObject(, "AutoCAD.Application")
Dim ThisDrawing As AcadDocument
Set ThisDrawing = AcadApp.ActiveDocument


Sheets("reflines").Select
    ' This example returns a point entered by the user.

    Dim returnPnt As Variant

Dim j As Integer
Dim i As Integer


    For i = 0 To 9
    returnPnt = ThisDrawing.Utility.GetPoint
    'MsgBox "The WCS of the point is: " & returnPnt(0) & ", " & returnPnt(1) & ", " & returnPnt(2), , "GetPoint Example"
ActiveCell.Offset(i, 0) = returnPnt(0)
ActiveCell.Offset(i, 1) = returnPnt(1)
ActiveCell.Offset(i, 2) = returnPnt(2)
    Next I

 

Thanks in advance, hope anyone can help me

 

 

 

0 Likes
1,815 Views
1 Reply
Reply (1)
Message 2 of 2

Ed__Jobe
Mentor
Mentor

With vba, you're not going to be able to work interactively with the PLINE command. You have two choices. Collect the points first, then use the AddPolyline method to create the pline from the points you stored. The other method is to let the user select an existing pline, and then get the coordinates from the Coordinates collection. There's a code sample in the ActiveX reference for the AcadPolyline.Coordinates property.

 

If you choose the first option, try using the optional 'point' argument of the GetPoint method, using the previous point specified. This will cause a rubberband to connect to the previous point, helping the user to see what they are drawing.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes