mhy3sx Posted 5 hours ago Posted 5 hours ago Hi. I am searching for a lisp to select a 3d polyline and find the lower elevation Thanks Quote
BIGAL Posted 2 hours ago Posted 2 hours ago 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 1 hour ago Posted 1 hour ago 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 1 hour ago Posted 1 hour ago 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 1 hour ago Posted 1 hour ago (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 59 minutes ago by GLAVCVS Quote
mhy3sx Posted 52 minutes ago Author Posted 52 minutes ago 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 49 minutes ago Author Posted 49 minutes ago 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
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.