Accessing the vertices of an offset line

Accessing the vertices of an offset line

grenee
Observer Observer
367 Views
3 Replies
Message 1 of 4

Accessing the vertices of an offset line

grenee
Observer
Observer

Good day. 

I am trying to access the vertices of an offset line. There is no success after intense tries. Can anyone help please?

Here is the code.

The problem is at line 30. 

The message is : Object required : Runtime error 424

 

 

 

 

 

 

Private Sub CommandButton10_Click()

Dim Coord1(1) As Double
Dim Coord2(1) As Double
Dim LineObj As AcadLine

Coord1(0) = Me.TextBox1: Coord1(1) = Me.TextBox6
Coord2(0) = Me.TextBox5: Coord2(1) = Me.TextBox4

DrawlineGivenTwoVertices Coord1, Coord2, LineObj


Dim OffsetLinePoints As Variant
Dim OffsetLine As Variant
     OffsetLinePoints = LineObj.Offset(20)
     Set OffsetLine = OffsetLinePoints(0)
     
     OffsetLine.Color = acGreen
     
     OffsetLine.Update
     
     Dim NumVertices As Integer
        Dim ReturnedObj() As Double
      
        Dim vertex1(1) As Double
        Dim Vertex2(1) As Double
      
        
              ReturnedObj = OffsetLinePoints.Coordinates
       
              vertex1(0) = ReturnedObj(0)
              vertex1(1) = ReturnedObj(1)
                  
           
              NumVertices = UBound(ReturnedObj)
                   
              Vertex2(0) = ReturnedObj(NumVertices)
              Vertex2(1) = ReturnedObj(NumVertices)
              
       Dim StraightPline As AcadLWPolyline
      DrawPlineGiven2Vertices vertex1, Vertex2, StraightPline
End Sub

 

 

*Moderator edit* changed programming language to Visual Basic.

0 Likes
368 Views
3 Replies
Replies (3)
Message 2 of 4

Ed__Jobe
Mentor
Mentor

You have several problems that would be evident if you did some debugging. Set a breakpoint near the beginning of the code, e.g. line 7. Then start debugging with F5. When the execution stops at line 7, examine the status of variables in the Locals Window (View>Locals Window). If their value is what you expect, hit F8 and examine the next set of variables. Keep doing this until you find a problem.

 

In your case, here are some problems to look for:\

  1. Line 14, 15: The offset method doesn't return points. It returns an array of entities.
  2. Line 23: ReturnedObj should be a variant because it needs to accept an array from the Coordinates method.
  3. Lin3 29. A Line object doesn't have a Coordinates method, just StartPoint and EndPoint properties. Each of those hold a two-element Double array for x and y.
  4. Line 35: A line always has only 2 vertices.
  5. Line 41: You will want to delete OffsetLine since you are replacing it with a pline.

 

 
     'Dim NumVertices As Integer    'not applicable
        'Dim ReturnedObj As Variant 'Not needed
      
        'Dim vertex1(1) As Double   'Not needed
        'Dim Vertex2(1) As Double   'Not needed
      
        
              'ReturnedObj = OffsetLinePoints.Coordinates 'invalid call
       
              'vertex1(0) = ReturnedObj(0)
              'vertex1(1) = ReturnedObj(1)
                  
           
              'NumVertices = UBound(ReturnedObj)
                   
              'Vertex2(0) = ReturnedObj(NumVertices)
              'Vertex2(1) = ReturnedObj(NumVertices)
              
       Dim StraightPline As AcadLWPolyline
      DrawPlineGiven2Vertices OffsetLine.StartPoint, OffsetLine.EndPoint, StraightPline
      OffsetLine.Delete

 

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
Message 3 of 4

grenee
Observer
Observer

Thanks for the assistance, Ed. Jobe.

But there still appears to be a problem with getting the "offsetLine" created.

 

This is my new code. But it still does not work. Can you see an error in it?

The error message is at line 21. The message highlights: .Startpoint. 

The message is: Type mismatched. Arrary user-defined type expected

 

 
Private Sub CommandButton10_Click()

Dim Coord1(1) As Double
Dim Coord2(1) As Double
Dim LineObj As AcadLine

Coord1(0) = Me.TextBox1: Coord1(1) = Me.TextBox6
Coord2(0) = Me.TextBox5: Coord2(1) = Me.TextBox4

DrawlineGivenTwoVertices Coord1, Coord2, LineObj


Dim OffsetLinePoints As Variant
Dim OffsetLine As Variant
     OffsetLinePoints = LineObj.Offset(20)
     Set OffsetLine = OffsetLinePoints(0)
     
              
       Dim StraightPline As AcadLWPolyline
      DrawPlineGiven2Vertices OffsetLine.StartPoint, OffsetLine.Endpoint, StraightPline
      
      OffsetLine.Delete
End Sub

 

 

0 Likes
Message 4 of 4

Ed__Jobe
Mentor
Mentor

StartPoint, EndPoint are 3D array of double. You either have to convert them to the data type your custom function requires or change your custom function to take point arrays.

 


Type: Variant (three-element array of doubles)

A 3D coordinate representing the start point of the object.


 

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