sirsebast Posted September 12, 2013 Posted September 12, 2013 Is it possible to find max x and minus x from polyline ? Quote
ReMark Posted September 12, 2013 Posted September 12, 2013 If I don't learn something new (or two somethings) a day I feel as though I wasted my awake time so tell me what is "max x" and "minus x" and just what it is you are going to accomplish by obtaining that information? Are these polyline coordinates you are attempting to retrieve by some lisp code? Could it have something to do with polyline vertices? Quote
sirsebast Posted September 12, 2013 Author Posted September 12, 2013 I want make retangle in lisp whith max et min xy. Quote
ReMark Posted September 12, 2013 Posted September 12, 2013 We seem to be stuck. Let's give this thread a *bump* and see what happens. Quote
neophoible Posted September 12, 2013 Posted September 12, 2013 This probably needs to be in the LISP forum, doesn't it? I'm not clear on how you are inputting the info from a polyline. I can tell you that 'min' here should mean minimum (not minus), comtrasted with max for maximum. The values seem to be reversed in both cases shown. Perhaps more explanation is in order as well. Quote
JD Mather Posted September 12, 2013 Posted September 12, 2013 .... The values seem to be reversed in both cases shown. Looks right to me. A negative is less than a positive. I know in some of the CAD programs I use they will return the bounding box x,y (and z) that irregular geometry would fit into. But I have no idea of the code for retrieving this information. BTW - without your picture I would have had absolutely no idea what you were after. Quote
sirsebast Posted September 13, 2013 Author Posted September 13, 2013 (edited) I think I found what I want but the code is create in 1998. (defun C:BoundPoly (ss Cwd / Lst ssl ename entl cnt elast la pt1 pt2 vlist cen dia vlist1 vlist2 p11 p12 p21 p22 ename1 ename2 PolySS ss1 en flag OS ) (if (= (type ss) 'ENAME) (progn (setq ss1 (ssadd)) (ssadd ss ss1) (setq ss ss1) )) (setq OS (getvar "OSMODE")) (setvar "OSMODE" 0) (setq PolySS nil) (if ss (progn (LA_mk_c_lyr "0" "") (setq ssl (sslength ss) PolySS (ssadd) cnt 0 ) (repeat ssl (setq ename (ssname ss cnt) entl (entget ename) en (LI_item 0 entl) cnt (1+ cnt) ) (cond ((= en "CIRCLE") (setq dia (* 2.0 (LI_item 40 entl)) Cen (LI_item 10 entl) ) (command "._Donut" dia dia Cen "") (ssadd (entlast) PolySS) ) ((member en (list "LINE" "POLYLINE")) (if (= en "LINE") (setq flag 0 vlist (list (LI_item 10 entl) (LI_item 11 entl))) (setq flag (LI_item 70 entl) vlist (PL_plist ename)) ) (if (zerop (logand flag 1)) ; Open polyline or line (progn (LA_mk_c_lyr "0" "") (command "._Mline" "_Justification" "_Zero" "_Scale" Cwd) (foreach pt vlist (command pt)) (command "") (setq elast (MI_xentlast)) (command "._Explode" (entlast)) (setq ss1 (MI_after elast) ss1 (PL_PlJoin ss1 nil) ) (if (and ss1 (= (sslength ss1) 2)) (progn (command "._Change" ss1 "" "_Properties" "_Layer" "0" "") (setq vlist1 ( PL_plist (ssname ss1 0) ) vlist2 ( PL_plist (ssname ss1 1) ) p11 (nth 0 vlist1) p12 (nth (1- (length vlist1) ) vlist1) p21 (nth 0 vlist2) p22 (nth (1- (length vlist2) ) vlist2) ) (command "._Line" p11 p21 "") (setq ename1 (entlast)) (command "._Line" p12 p22 "") (setq ename2 (entlast)) (command "._Pedit" (ssname ss1 0) "_Join" (ssname ss1 1) ename1 ename2 "" "_X" "._Pedit" (entlast) "_Close" "_X" ) (ssadd (entlast) PolySS) )) ) (progn (command "._Copy" ename "" (list 0.0 0.0 0.0) "") (ssadd (entlast) PolySS) )) ) ) ) )) (setvar "OSMODE" OS) PolySS ) Edited September 13, 2013 by Tiger added code-tags Quote
Lee Mac Posted September 13, 2013 Posted September 13, 2013 For straight-segmented LWPolylines: (defun c:bbpoly ( / e l ) (if (setq e (ssget "_+.:E:S" '((0 . "LWPOLYLINE")))) (progn (setq l (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget (ssname e 0)))) l (mapcar '(lambda ( x ) (apply 'mapcar (cons x l))) '(min max)) ) (entmake (list '(000 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(090 . 4) '(070 . 1) (cons 10 (car l)) (list 10 (caadr l) (cadar l)) (cons 10 (cadr l)) (list 10 (caar l) (cadadr l)) ) ) ) ) (princ) ) Quote
Lee Mac Posted September 13, 2013 Posted September 13, 2013 For multiple straight-segmented LWPolylines: (defun c:bbpoly ( / i l s ) (if (setq s (ssget '((0 . "LWPOLYLINE")))) (progn (repeat (setq i (sslength s)) (setq l (cons (mapcar 'cdr (vl-remove-if-not (function (lambda ( x ) (= 10 (car x))) ) (entget (ssname s (setq i (1- i)))) ) ) l ) ) ) (setq l (apply 'append l) l (mapcar '(lambda ( x ) (apply 'mapcar (cons x l))) '(min max)) ) (entmake (list '(000 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(090 . 4) '(070 . 1) (cons 10 (car l)) (list 10 (caadr l) (cadar l)) (cons 10 (cadr l)) (list 10 (caar l) (cadadr l)) ) ) ) ) (princ) ) Quote
David Bethel Posted September 13, 2013 Posted September 13, 2013 I use this very often to find limits of a point list and the overall x & y size: (defun plimits (l) (setq mnx (apply 'min (mapcar 'car l)) mxx (apply 'max (mapcar 'car l)) mny (apply 'min (mapcar 'cadr l)) mxy (apply 'max (mapcar 'cadr l)) ysz (- mxy mny) xsz (- mxx mnx)) ) For your needs, you would feed the point values from the LWPOLYLINE entities to the call: It's a starting point. -David 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.