mhy3sx Posted Sunday at 06:54 PM Posted Sunday at 06:54 PM Hi. I am searching for a lisp to select a 3d polyline and find the lower elevation Thanks Quote
BIGAL Posted Sunday at 10:37 PM Posted Sunday at 10:37 PM Give this a try (defun co-ords2xy (xyz co-ords / I XY ) (setq co-ordsxy '()) (if (= xyz 2) (progn (setq I 0) (repeat (/ (length co-ords) 2) (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) )) (setq co-ordsxy (cons xy co-ordsxy)) (setq I (+ I 2)) ) ) ) (if (= xyz 3) (progn (setq I 0) (repeat (/ (length co-ords) 3) (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) )) (setq co-ordsxy (cons xy co-ordsxy)) (setq I (+ I 3)) ) ) ) (princ) ) (defun c:getxyz ( / obj entname) (setq obj (vlax-ename->vla-object (car (entsel "\nPlease choose 2d or 3d pline ")))) (setq entname (vlax-get obj 'objectname)) (if (= entname "AcDb3dPolyline") (setq 23d 3) (setq 23d 2) ) (setq coords (vlax-get obj 'coordinates)) (co-ords2xy 23d coords) (princ) ) (setq co-ordsxy (vl-sort co-ordsxy '(lambda (x y) (< (car x)(car y))))) (alert (strcat "Y min is " (rtos (cadr (car co-ordsxy )) 2 3 ))) 1 Quote
Tsuky Posted Sunday at 11:16 PM Posted Sunday at 11:16 PM This give a point at min z on 3Dpolyline. (vl-load-com) (defun c:min_z ( / js obj ename pr pt lst_pt lst_z id_seg nw_pt) (princ "\nSelect 3DPolylines: ") (while (null (setq js (ssget '((0 . "POLYLINE") (-4 . "&") (70 . 8))))) (princ "\nObjects not valid!") ) (repeat (setq n (sslength js)) (setq obj (ssname js (setq n (1- n))) ename (vlax-ename->vla-object obj) pr -1 lst_pt nil ) (repeat (if (zerop (vlax-get ename 'Closed)) (1+ (fix (vlax-curve-getEndParam ename))) (fix (vlax-curve-getEndParam ename))) (setq pt (vlax-curve-GetPointAtParam ename (setq pr (1+ pr))) lst_pt (cons pt lst_pt) ) ) (setq lst_z (mapcar 'caddr lst_pt) id_seg (- (length lst_z) (length (member (apply 'min lst_z) lst_z))) ) (setq nw_pt (vlax-invoke (if (eq (getvar "CVPORT") 1) (vla-get-PaperSpace (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))) ) 'AddPoint (nth id_seg lst_pt) ) ) (vla-put-Normal nw_pt (vlax-3d-point '(0 0 1))) ) (prin1) ) 1 Quote
GLAVCVS Posted Sunday at 11:30 PM Posted Sunday at 11:30 PM Maybe this will help you... (defun c:ptoZmin? (/ ent lstent punto lstpts zMin ptoZmin) (if (setq ent (car (entsel "\nSelect POLYLINE..."))) (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "POLYLINE") (while (/= (cdr (assoc 0 (setq lstent (entget (entnext (cdr (assoc -1 lstent))))) ) ) "SEQEND" ) (setq punto (cdr (assoc 10 lstent))) (if zMin (if (= (min zMin (last punto)) (last punto)) (setq zMin (last punto) ptoZmin punto ) ) (setq zMin (last punto) ptoZmin punto ) ) ) ) ) (if ptoZmin (progn (grdraw (polar pto 0.785398 (* 0.025 (getvar "viewsize"))) (polar pto 3.92699 (* 0.025 (getvar "viewsize"))) 2 1 ) (grdraw (polar pto 2.35619 (* 0.025 (getvar "viewsize"))) (polar pto 5.49779 (* 0.025 (getvar "viewsize"))) 2 1 ) (alert (strcat "Point with minimum Z:\nX = " (rtos (car ptoZmin) 2 2) "\nY = "(rtos (cadr ptoZmin) 2 2) "\nZ = "(rtos (caddr ptoZmin) 2 2))) (princ (strcat "\nPoint with minimum Z:\nX = " (rtos (car ptoZmin) 2 2) "; Y = "(rtos (cadr ptoZmin) 2 2) "; Z = "(rtos (caddr ptoZmin) 2 2))) ) ) (princ) ) Quote
GLAVCVS Posted Sunday at 11:42 PM Posted Sunday at 11:42 PM (edited) Or function only To call it you must provide the entity name of the 3D polyline in the 'ent' argument. (defun ptoZmin? (ent / lstent punto lstpts zMin ptoZmin) (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "POLYLINE") (while (/= (cdr (assoc 0 (setq lstent (entget (entnext (cdr (assoc -1 lstent))))))) "SEQEND") (setq punto (cdr (assoc 10 lstent))) (if zMin (if (= (min zMin (last punto)) (last punto)) (setq zMin (last punto) ptoZmin punto ) ) (setq zMin (last punto) ptoZmin punto ) ) ) ) ptoZmin ) Edited Sunday at 11:46 PM by GLAVCVS Quote
mhy3sx Posted Sunday at 11:53 PM Author Posted Sunday at 11:53 PM I check the codes, only BIGAL is close.I want to princ the Zmin of the 3d polyline. The Ymin not help me because for example in the midle of the 3d polyline will have minZ. ptoZmin Not working and min_z insert a point at minZ (I want to princ the elevation) Thanks Quote
mhy3sx Posted Sunday at 11:56 PM Author Posted Sunday at 11:56 PM I try this on Tsuky code and works fine (vl-load-com) (defun c:min_z2 ( / js obj ename pr pt lst_pt lst_z min_z) (princ "\nSelect 3DPolylines: ") (while (null (setq js (ssget '((0 . "POLYLINE") (-4 . "&") (70 . 8))))) (princ "\nObjects not valid!") ) (setq min_z nil) ; Initialize min_z to nil (repeat (setq n (sslength js)) (setq obj (ssname js (setq n (1- n))) ename (vlax-ename->vla-object obj) pr -1 lst_pt nil ) (repeat (if (zerop (vlax-get ename 'Closed)) (1+ (fix (vlax-curve-getEndParam ename))) (fix (vlax-curve-getEndParam ename))) (setq pt (vlax-curve-GetPointAtParam ename (setq pr (1+ pr))) lst_pt (cons pt lst_pt) ) ) (setq lst_z (mapcar 'caddr lst_pt) ; Extract Z values min_z (if (null min_z) (apply 'min lst_z) (min min_z (apply 'min lst_z))) ; Update min_z ) ) (if min_z (princ (strcat "\nMinimum Elevation: " (rtos min_z 2 4))) ; Print the minimum elevation (princ "\nNo valid elevations found.") ) (prin1) ) Thanks you all for the help Quote
GLAVCVS Posted 21 hours ago Posted 21 hours ago (edited) I think I misunderstood your explanation of what you needed. Anyway, the code can be easily adapted to what you asked for. I've corrected the small oversight in the 'grvecs' functions, which I included at the last minute and didn't check. Here is the modified code, in case anyone finds it useful... (defun c:ptoZmin? (/ ent lstent punto lstpts zMin ptoZmin conj n) (setq n 0) (if (setq conj (ssget '((0 . "POLYLINE")))) (while (setq ent (ssname conj n)) (setq lstent (entget ent)) (while (/= (cdr (assoc 0 (setq lstent (entget (entnext (cdr (assoc -1 lstent))))) ) ) "SEQEND" ) (setq punto (cdr (assoc 10 lstent))) (if zMin (if (= (min zMin (last punto)) (last punto)) (setq zMin (last punto) ptoZmin punto ) ) (setq zMin (last punto) ptoZmin punto ) ) ) (setq n (1+ n)) ) ) (if ptoZmin (progn (grdraw (polar ptoZmin 0.785398 (* 0.025 (getvar "viewsize"))) (polar ptoZmin 3.92699 (* 0.025 (getvar "viewsize"))) 2 1 ) (grdraw (polar ptoZmin 2.35619 (* 0.025 (getvar "viewsize"))) (polar ptoZmin 5.49779 (* 0.025 (getvar "viewsize"))) 2 1 ) (alert (strcat "Point with minimum Z:\nX = " (rtos (car ptoZmin) 2 2) "\nY = "(rtos (cadr ptoZmin) 2 2) "\nZ = "(rtos (caddr ptoZmin) 2 2))) (princ (strcat "\nPoint with minimum Z:\nX = " (rtos (car ptoZmin) 2 2) "; Y = "(rtos (cadr ptoZmin) 2 2) "; Z = "(rtos (caddr ptoZmin) 2 2))) ) ) (princ) ) Edited 21 hours ago by GLAVCVS 1 Quote
BIGAL Posted 8 hours ago Posted 8 hours ago You really need to look harder at the solutions provided and get an understanding of what they are doing. A quick fix. (setq co-ordsxy (vl-sort co-ordsxy '(lambda (x y) (< (caddr x)(caddr y))))) (alert (strcat "Z min is " (rtos (caddr (car co-ordsxy )) 2 3 ))) If you swap < for > you will get max value. 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.