AutoCAD Map 3D Forum
Welcome to Autodesk’s AutoCAD Map 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lengths of polylines with many vertices in CS?

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
АлексЮстасу
543 Views, 13 Replies

lengths of polylines with many vertices in CS?

A simple question was asked today.
There is a CS assigned in the file.
How to get the lengths of polylines with many vertices in CS?
(The available MAPDIST only for one segment)

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

13 REPLIES 13
Message 2 of 14

Perhaps with this?

(defun c:map_dist-vertex_po ( / js n ent pr pt_start pt_end)
  (princ "\nSelect polylines.")
  (while
    (null
      (setq js
        (ssget
          '(
            (0 . "*POLYLINE")
            (-4 . "<NOT")
              (-4 . "&") (70 . 112)
            (-4 . "NOT>")
          )
        )
      )
    )
    (princ "\nSelect is empty, or isn't POLYLINE!")
  )
  (repeat (setq n (sslength js))
    (setq
      ent (ssname js (setq n (1- n)))
      pr -1
    )
    (repeat (fix (vlax-curve-getEndParam ent))
      (setq
        pt_start (vlax-curve-GetPointAtParam ent (setq pr (1+ pr)))
        pt_end (vlax-curve-GetPointAtParam ent (1+ pr))
      )
      (command "_.mapdist" "_none" pt_start "_none" pt_end)
    )
  )
  (textscr)
  (prin1)
)
Message 3 of 14

Thank you Bruno! Great!!!
You are again solving problems instead of AutoCAD. 😀

 

Is it possible to output the total length? The lengths of each segment can be output, but they are rarely needed.

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

Message 4 of 14


@АлексЮстасу  a écrit :

Thank you Bruno! Great!!!
You are again solving problems instead of AutoCAD. 😀

 

Is it possible to output the total length? The lengths of each segment can be output, but they are rarely needed.

 


Yes it is possible, but at this moment I give up MAPDIST...
Indeed mapdist gives the distance between 2 points and not the real length of a polyline arc.


If it fits, I prefer this version where the total length will correlate with the properties. In addition it will work under a full version (without map)

(defun c:dist-vertex_po ( / js n ent pr cumul dist_start dist_end pt_start pt_end seg_len  bulge rad alpha)
  (princ "\nSelect polylines.")
  (while
    (null
      (setq js
        (ssget
          '(
            (0 . "*POLYLINE")
            (-4 . "<NOT")
              (-4 . "&") (70 . 112)
            (-4 . "NOT>")
          )
        )
      )
    )
    (princ "\nSelect is empty, or isn't POLYLINE!")
  )
  (repeat (setq n (sslength js))
    (setq
      ent (ssname js (setq n (1- n)))
      pr -1
      cumul 0.0
    )
    (repeat (fix (vlax-curve-getEndParam ent))
      (setq
        dist_start (vlax-curve-GetDistAtParam ent (setq pr (1+ pr)))
        dist_end (vlax-curve-GetDistAtParam ent (1+ pr))
        pt_start (vlax-curve-GetPointAtParam ent pr)
        pt_end (vlax-curve-GetPointAtParam ent (1+ pr))
        seg_len (- dist_end dist_start)
        bulge (nth pr (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 42)) (entget ent))))
        rad (if (zerop bulge) 0.0 (/ (distance pt_start pt_end) (sin (* 2.0 (atan bulge))) 2.0))
        alpha (angle (trans pt_start 0 1) (trans pt_end 0 1))
        cumul (+ cumul seg_len)
      )
      (princ (strcat "\nLength from vertex " (itoa pr) " to vertex " (itoa (1+ pr)) " = " (rtos seg_len 2 3) "\tSegment/Chord orientation : " (angtos alpha (getvar "AUNITS") 4) "\tRadius = " (rtos (abs rad) 2 3)))
    )
    (princ (strcat "\nTotal length = " (rtos cumul 2 3)))
  )
  (textscr)
  (prin1)
)

 

Message 5 of 14

I have something wrong with dist-vertex_po.lsp:
- For 3DPolyline there is an error.
- And the distances are not in CS.

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

Message 6 of 14

@АлексЮстасу 

So to have cartographic distances AND the total with Map if a CS is assigned, I suggest using MAPCGCDIST instead of MAPDIST

 

(defun c:map_dist-vertex_po ( / js n ent pr)
  (princ "\nSelect polylines.")
  (while
    (null
      (setq js
        (ssget
          '(
            (0 . "*POLYLINE")
            (-4 . "<NOT")
              (-4 . "&") (70 . 112)
            (-4 . "NOT>")
          )
        )
      )
    )
    (princ "\nSelect is empty, or isn't POLYLINE!")
  )
  (repeat (setq n (sslength js))
    (setq
      ent (ssname js (setq n (1- n)))
      pr 0
    )
    (command "_.mapcgcdist" "_Continuous" "_none" (vlax-curve-GetPointAtParam ent pr))
    (repeat (fix (vlax-curve-getEndParam ent))
      (command "_none" (vlax-curve-GetPointAtParam ent (setq pr (1+ pr))))
    )
    (command "")
  )
  (textscr)
  (prin1)
)

 

And for the full version (without Map) corrected for the LWPOLYLINE POLYLINE2D and POLYLINE3D

 

(defun c:dist-vertex_po ( / js n ent pr cumul flag bulge nent dist_start dist_end pt_start pt_end seg_len rad alpha)
  (princ "\nSelect polylines.")
  (while
    (null
      (setq js
        (ssget
          '(
            (0 . "*POLYLINE")
            (-4 . "<NOT")
              (-4 . "&") (70 . 112)
            (-4 . "NOT>")
          )
        )
      )
    )
    (princ "\nSelect is empty, or isn't POLYLINE!")
  )
  (repeat (setq n (sslength js))
    (setq
      ent (ssname js (setq n (1- n)))
      pr -1
      cumul 0.0
      flag (if (assoc 66 (entget ent)) T nil)
      bulge nil
    )
    (if flag
      (progn
        (setq nent (entget ent))
        (while (/= (cdr (assoc 0 nent)) "SEQEND") (setq bulge (cons (cdr (assoc 42 (setq nent (entget (entnext (cdar nent)))))) bulge)))
        (setq bulge (reverse (cdr bulge)))
      )
    )
    (repeat (fix (vlax-curve-getEndParam ent))
      (if (not flag)
        (setq bulge (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 42)) (entget ent))))
      )
      (setq
        dist_start (vlax-curve-GetDistAtParam ent (setq pr (1+ pr)))
        dist_end (vlax-curve-GetDistAtParam ent (1+ pr))
        pt_start (vlax-curve-GetPointAtParam ent pr)
        pt_end (vlax-curve-GetPointAtParam ent (1+ pr))
        seg_len (- dist_end dist_start)
        rad (if (or (not bulge) (zerop (nth pr bulge))) 0.0 (/ (distance pt_start pt_end) (sin (* 2.0 (atan (nth pr bulge)))) 2.0))
        alpha (angle (trans pt_start 0 1) (trans pt_end 0 1))
        cumul (+ cumul seg_len)
      )
      (princ (strcat "\nLength from vertex " (itoa pr) " to vertex " (itoa (1+ pr)) " = " (rtos seg_len 2 3) "\tSegment/Chord orientation in UCS : " (angtos alpha (getvar "AUNITS") 4) "\tRadius = " (rtos (abs rad) 2 3)))
    )
    (princ (strcat "\nTotal length = " (rtos cumul 2 3)))
  )
  (textscr)
  (prin1)
)

 

Message 7 of 14

Alas. MAPCGCDIST does not give distances in CS ("geodetic distance" in AutoCAD units/ in meters).
Apparently only MAPDIST can do that?
To use MAPDIST, the problem is that the measurements are only displayed in the text window?
And therefore it is not possible (unclear how) to get the sum of MAPDIST measurements?

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

Message 8 of 14

@АлексЮстасу 

 

I have a not very clean solution (I use history log) that will require modifying the code where it is commented.

I couldn't find any other way...😕

 

 

 

 

Message 9 of 14

@CADaSchtroumpf,

I changed the path to the log files in the code. And the "Distance" language.
And it worked!
Thank you!

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

Message 10 of 14

@CADaSchtroumpf,

I was also advised for log files - https://dotsoft.com/blog/?p=350.
It mentions LOGFILEPATH, LOGFILEON, LOGFILEOFF commands.
Maybe this would allow you to determine the path programmatically?

 

And is it possible to programmatically know the language of AutoCAD - for "Distance = " or "Расстояние = ", etc.?

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

Message 11 of 14

Hi @АлексЮстасу 

Thank you for LOGFILEPATH, indeed it helps me...

For the other two they are no longer valid under my 2019, I think they are replaced by LOGFILEMODE (which I was already using)

Normally this version should work without modifying anything under your version in Russian, I can only test in French version...

 

Message 12 of 14

@CADaSchtroumpf,

Distance is twice the sum of the lengths of the segments.

 

Are you saying that this lisp is only for versions 2018 and later?

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

Message 13 of 14


@АлексЮстасу  a écrit :

@CADaSchtroumpf,

Distance is twice the sum of the lengths of the segments.

 

Are you saying that this lisp is only for versions 2018 and later?

 


@АлексЮстасу 

For distance, I can't observe this in my test!?!?

Have you duplicate polyline on your drawing selected by crossing?

In fact for LOGFILEON LOGFILEOFF isn't variable but command, in french:

LOGFILEON = FICHJOURNAC

LOGFILEOFF = FICHJOURNIN

But the variable LOGFILEMODE reflete the status off this command since 2016

Message 14 of 14

@CADaSchtroumpf,

Yes, today my total Distance is correct.
Apparently there was something strange yesterday...

 

But in Russian AutoCAD 2012 "Distance = 0.0".
Apparently, it does affect the fact that the word "Расстояние" ("Distance") is in Russian.

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report