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)
Solved! Go to Solution.
Solved by CADaSchtroumpf. Go to Solution.
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)
)
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.
@АлексЮстасу 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)
)
I have something wrong with dist-vertex_po.lsp:
- For 3DPolyline there is an error.
- And the distances are not in CS.
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)
)
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?
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...😕
I changed the path to the log files in the code. And the "Distance" language.
And it worked!
Thank you!
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.?
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...
Distance is twice the sum of the lengths of the segments.
Are you saying that this lisp is only for versions 2018 and later?
@АлексЮстасу a écrit :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
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.
Can't find what you're looking for? Ask the community or share your knowledge.