Get list of Length and width of Rectangle or polyine shape to excel from Autocad

Get list of Length and width of Rectangle or polyine shape to excel from Autocad

jalal.mousa
Advocate Advocate
577 Views
4 Replies
Message 1 of 5

Get list of Length and width of Rectangle or polyine shape to excel from Autocad

jalal.mousa
Advocate
Advocate

Hi There,

i am drawing polyline or Rectangle using 

 

Set outerLoop(0) = MyDWG.ModelSpace.AddPolyline(points)

i can get total area and total length of this shape but, is there a way to get list of length and width(edges)of the shape ?

 

0 Likes
Accepted solutions (1)
578 Views
4 Replies
Replies (4)
Message 2 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

I'm not sure I understand what you want. Do you mean that you want to get the length of each segment of the polyline? If so, you can use the function below to get the distance between the points you are adding to the polyline.


Public Function XYZDistance(Point1 As Variant, Point2 As Variant) As Double
    On Error GoTo Err_Control
    'Returns the distance between two points
    Dim dblDist As Double
    Dim dblXSl As Double
    Dim dblYSl As Double
    Dim dblZSl As Double
    Dim varErr As Variant
    On Error GoTo Err_Control
    'Calc distance
    dblXSl = (Point1(0) - Point2(0)) ^ 2
    dblYSl = (Point1(1) - Point2(1)) ^ 2
    dblZSl = (Point1(2) - Point2(2)) ^ 2
    dblDist = Sqr(dblXSl + dblYSl + dblZSl)
    'Return Distance
    XYZDistance = dblDist
Exit_Here:
    Exit Function
Err_Control:
    Select Case Err.Number
    'Add your Case selections here
    'Case Is = 1000
        'Handle error
        'Err.Clear
        'Resume Exit_Here
    Case Else
        MsgBox Err.Number & ", " & Err.Description, , "XYZDistance"
        Err.Clear
        Resume Exit_Here
    End Select
End Function

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

Message 3 of 5

jalal.mousa
Advocate
Advocate
thanks i will try it shortly, how i can apply this solution to rectangle with 2 points (from corner to corner ) ?
0 Likes
Message 4 of 5

Ed__Jobe
Mentor
Mentor

In your code above, you have:

Set outerLoop(0) = MyDWG.ModelSpace.AddPolyline(points)

While you are defining the collection of points, use the function I gave you.

Dim dist As Double
dist = XYZDistance(pt1,pt2)
dist = dist + XYZDistance(pt3,pt4)
'etc.

 

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

Message 5 of 5

jalal.mousa
Advocate
Advocate

Hi Ed,

I am using code you suggested and works fine as part of loop i am using to add points

below partial code

the problem i am facing is that when i am multiply Length 1 * L2 to get area, and if for some reason i draw extra segment on straight line the total area will be less than actual area see screen shot attached (test)

in attached example area will be Length 1*L2 = 1.89*0.78 result will be less than actual area (1.89*(0.78+1.34))

is there a way to add up lengths if they are on same direction such as adding L2+L3 to become 0.78+1.34

this way i can avoid mistakes in calculation

should i run test for example maybe if 

dblXSl (i2) = dblXSl (i3) or 

dblYSl (i2) =dblYSl (i3)

this means they are on same angle (direction)

 

n = 0
On Error Resume Next
For i = 0 To 2000 Step 3

Label1:
' first point use actual postion for exact location
AktPt = MyDWG.Utility.GetPoint

ReDim Preserve points(i + 5) As Double
plineObj.Delete
' first point
' x vertix
points(i) = AktPt(0)
' y vertix
points(i + 1) = AktPt(1)
' z vertix
points(i + 2) = AktPt(2)

points(i + 3) = points(0)
points(i + 4) = points(1)
points(i + 5) = points(2)

' jalal add length 2023
'Calc distance
If i = 0 Then GoTo labelnextpoint
dblXSl = (points(i) - points(i - 3)) ^ 2
dblYSl = (points(i + 1) - points(i - 2)) ^ 2
dblZSl = (points(i + 2) - points(i - 1)) ^ 2

'Return Distance
ReDim XYZDistance(n)
dblDist = Sqr(dblXSl + dblYSl + dblZSl)
XYZDistance(n) = dblDist
If n = 1 Then
UserForm_DrawToCalc.TextBoxshapeLength1 = Format(XYZDistance(n), "##,##0.00")
End If
If n = 2 Then
UserForm_DrawToCalc.TextBoxshapeLength2 = Format(XYZDistance(n), "##,##0.00")
End If

If n = 3 Then
UserForm_DrawToCalc.TextBoxshapeLength3 = Format(XYZDistance(n), "##,##0.00")
End If
If n = 4 Then
UserForm_DrawToCalc.TextBoxshapeLength4 = Format(XYZDistance(n), "##,##0.00")
End If
If n = 5 Then
UserForm_DrawToCalc.TextBoxshapeLength5 = Format(XYZDistance(n), "##,##0.00")
End If
If n = 6 Then
UserForm_DrawToCalc.TextBoxshapeLength6 = Format(XYZDistance(n), "##,##0.00")
End If

'TextBoxshapeLength = "TextBoxshapeLength" & n
' TextBoxshapeLength(n) = Format(XYZDistance(n), "##,##0.00")


'UserForm_DrawToCalc.
'UserForm_DrawToCalc.TextBoxshapeLength5 = Format(XYZDistance(5), "##,##0.00")

labelnextpoint:
Set plineObj = MyDWG.ModelSpace.AddPolyline(points)
'
'Return Distance


'LastplineObj = MyDWG.ModelSpace.AddPolyline(points)
If Err Then
Err.Clear

0 Likes