MP7 Posted August 1, 2019 Posted August 1, 2019 Hello, I'm using a nice LISP which lists the segments length of a polyline you select, but I would just like to add shortest, longest and average below the text "total polyline length is..." like MIN: xx MAX: yy AVG: zz (defun c:Test (/ T_Entity T_Object T_Start T_End T_SegmentLengths T_Count) (if (and (setq T_Entity (car (entsel "\nSelect polyline: "))) (= (vla-get-ObjectName (setq T_Object (vlax-ename->vla-object T_Entity))) "AcDbPolyline") ) (progn (setq T_Start (vlax-curve-getStartParam T_Object)) (setq T_End (vlax-curve-getEndParam T_Object)) (while (< T_Start T_End) (setq T_SegmentLengths (append T_SegmentLengths (list (- (vlax-curve-getDistAtParam T_Object (setq T_Start (1+ T_Start))) (vlax-curve-getDistAtParam T_Object (1- T_Start)))))) ) (setq T_Count 0) (foreach T_Item T_SegmentLengths (princ (strcat "\nSegment " (itoa (setq T_Count (1+ T_Count))) ": " (rtos T_Item (getvar "LUNITS") 6))) ) (princ (strcat "\n\n ** Total polyline length is " (rtos (vla-get-Length T_Object) (getvar "LUNITS") 6))) ) (princ "\n ** Nothing selected or not a polyline.") ) (princ) ) Thx MINMAXLENGHTS.lsp Quote
dlanorh Posted August 1, 2019 Posted August 1, 2019 (edited) Try this. I've altered the lisp slightly as your didn't need to store everything as a list of lists, just a list. The list is built using the cons function not append as this is quicker but means you have to reverse the final list to end up with the correct order. As a single list it also makes it easier to sort and extract the max & min length. (defun c:Test (/ T_Entity T_Object T_Start T_End T_SegmentLengths T_Count) (if (and (setq T_Entity (car (entsel "\nSelect polyline: "))) (= (vla-get-ObjectName (setq T_Object (vlax-ename->vla-object T_Entity))) "AcDbPolyline") ) (progn (setq T_Start (vlax-curve-getStartParam T_Object)) (setq T_End (vlax-curve-getEndParam T_Object)) (while (< T_Start T_End) (setq T_SegmentLengths (cons (- (vlax-curve-getDistAtParam T_Object (setq T_Start (1+ T_Start))) (vlax-curve-getDistAtParam T_Object (1- T_Start))) T_SegmentLengths)) ) (setq T_Count 0) (foreach T_Item (reverse T_SegmentLengths) (princ (strcat "\nSegment " (itoa (setq T_Count (1+ T_Count))) ": " (rtos T_Item (getvar "LUNITS") 6))) ) (princ (strcat "\n\n ** Minimum Segment length is " (rtos (car (vl-sort T_SegmentLengths '<)) (getvar "LUNITS") 6))) (princ (strcat "\n\n ** Maximum Segment length is " (rtos (car (vl-sort T_SegmentLengths '>)) (getvar "LUNITS") 6))) (princ (strcat "\n\n ** Average Segment length is " (rtos (/ (vla-get-Length T_Object) T_Count) (getvar "LUNITS") 6))) (princ (strcat "\n\n ** Total polyline length is " (rtos (vla-get-Length T_Object) (getvar "LUNITS") 6))) ) (princ "\n ** Nothing selected or not a polyline.") ) (princ) ) Edited August 1, 2019 by dlanorh 1 Quote
MP7 Posted August 1, 2019 Author Posted August 1, 2019 Holy cow, yeah that's just perfect man! Awesome! Thx a bunch man! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.