Error 451 on get coordinates code

Error 451 on get coordinates code

Anonymous
Not applicable
1,542 Views
2 Replies
Message 1 of 3

Error 451 on get coordinates code

Anonymous
Not applicable

The following code is supposed to loop through each line in the drawing and get the startpoint x, y and z values but instead I error 451. I copied this code from something else that works so I am at a loss here.

 

Sub Get_Points()

     

     Dim ent As AcadEntity
     Dim name As String
     Dim x As Double
     Dim y As Double
     Dim z As Double

     For Each ent In ThisDrawing.ModelSpace

          If TypeOf ent Is AcadLine Then
               name = ent.Handle
               x = ent.StartPoint(0)
               y = ent.StartPoint(1)
               z = ent.StartPoint(1)
          End If

     Next

End Sub

0 Likes
Accepted solutions (1)
1,543 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

I suppose you are using 64-bit AutoCAD, 2014 or later (thus 64-bit VBA).

 

Your code should have been worked in earlier 32-bit VBA.

 

Minor change would fix the error:

 

Sub Get_Points()

     Dim ent As AcadEntity
     Dim line As AcadLine
     
     Dim name As String
     Dim x As Double
     Dim y As Double
     Dim z As Double

     For Each ent In ThisDrawing.ModelSpace

          If TypeOf ent Is AcadLine Then
               name = ent.Handle
               Set line = ent
               x = line.StartPoint(0)
               y = line.StartPoint(1)
               z = line.StartPoint(1)
          End If

     Next

End Sub

Hope this helps

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

Just to point out a little typo:

 

 z = line.StartPoint(2)
0 Likes