Feature Line Get2dDistanceBetweenPoints Method?

Feature Line Get2dDistanceBetweenPoints Method?

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

Feature Line Get2dDistanceBetweenPoints Method?

Anonymous
Not applicable

Hello all,

 

I'm currently trying to write a simple VBA script to find the distance between two points on a feature line. Can someone help me understand how the "Get2dDistanceBetweenPoints" method actually works? I can select a feature line, specify the first and second points, then get a runtime error 438: "Object doesn't support this property or method."

 

I'm not great at coding but trying to help out my company automating some tasks we do repetitively. Any help would be greatly appreciated.

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

norman.yuan
Mentor
Mentor
Accepted solution

Firstly, this forum is mainly for plain AutoCAD VBA. For Civil3D specific question, you might want to post in this forum

 

Anyway, in order for anyone to answer your question, you should post your code that shows how you get the feature line. That is, how does your code to make sure it is AeccLandFeatureLine before calling its Get2dDistanceBetweenPoints() method? The error you got implies that you either not add reference to AeccXLand type library, or you did not convert picked (with AcadUtility.GetEntity()) entity object into AeccLandFeatureLine object before calling Get2dDistanceBetweenPoints().

 

Following code works for me:

 

Option Explicit

Public Sub GetFeatureLineDistance()
    
    Dim ent As AcadEntity
    Dim pt As Variant
    Dim pt1 As Variant
    Dim pt2 As Variant
    Dim dist As Double
    Dim fLine As AeccLandFeatureLine
    
    On Error Resume Next
    ThisDrawing.Utility.GetEntity ent, pt, vbCr & "Select a feature line:"
    If ent Is Nothing Then
        ThisDrawing.Utility.Prompt vbCr & "*Cancel*"
        Exit Sub
    End If
    
    If TypeOf ent Is AeccLandFeatureLine Then
        ent.Highlight True
        pt1 = ThisDrawing.Utility.GetPoint(, vbCr & "Pick a point on feature line:")
        pt2 = ThisDrawing.Utility.GetPoint(, vbCr & "Pick second point on the feature line:")
        Set fLine = ent
        dist = fLine.Get2dDistanceBetweenPoints(pt1, pt2)
        MsgBox "Distance betwen the 2 picked points: " & Format(dist, "#######0.000")
    Else
        MsgBox "Picked wrong entity: not a feature line!"
    End If
    
End Sub

 

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

Anonymous
Not applicable

Thanks so much for responding! Your solution worked perfectly, the issue I had was not understanding exactly how to call the Method. I had it in my code as dist=ThisDrawing.Utility.Get2dDistanceBetweenPoints, rather than recognizing that I needed to apply the Method directly to the object I had previously selected (in retrospect, should've been obvious).

 

Thanks again for your help, in future I'll be sure to post my code as well.