aaryan Posted June 29, 2012 Posted June 29, 2012 (edited) Hi all, how can i find a length and breadth of closed polyline which is not exactly a rectangle (but has four segments) from their midpoints from autolisp. Thanks in advance Regards Atleast if anyone can guide me to make a routine to find a midpoint of all segments of a polyline. Please Edited June 29, 2012 by aaryan Quote
pBe Posted June 29, 2012 Posted June 29, 2012 Can you run that by me again Aaryan? Post an example this time Quote
aaryan Posted June 29, 2012 Author Posted June 29, 2012 LxB.dwg Thanks for reply pBe. I have attached a drawing which has two closed polyline which four segments (but segments can be more in my actual work). I just need to know the maximum length and maximum breadth from those polyline. I thought this can be done from finding their midpoints to midpoints distance. Is it possible? Please suggest me. Regards Quote
aaryan Posted June 29, 2012 Author Posted June 29, 2012 Maximum base. LxBxH where H is height which i dont require to mention in my drawing only the LxB. Quote
pBe Posted June 29, 2012 Posted June 29, 2012 I'm sorry aaryan, dont really understand what maximum base is. Tell you what. give me the final result of the sample drawing you posted. Maximum length : ? Maximum breadth : ? Quote
aaryan Posted June 29, 2012 Author Posted June 29, 2012 LxB.dwg I hope attached drawing clears the confusion of requirement. If you notice i have taken length of midpoints on both direction. Regards Aaryan Quote
pBe Posted June 29, 2012 Posted June 29, 2012 Got it. I noticed that one of the polylines on your sample drawing is not "really" a closed polyline. so this line (setq ss (ssget [b][color=blue]"_X"[/color][/b] '((0 . "LWPOLYLINE") [color=blue][b](-4 . "&=") (70 . 1)[/b][/color]))) Will not select that polyline on the other hand it is safe to use (setq ss (ssget [b][color=blue]"_:L"[/color][/b] '((0 . "LWPOLYLINE") ))) selecting objects on screen. Another things is. (but segments can be more in my actual work). What will be the maximum values for those? the four segment polyline is easy. but what of those with multiple segment. how complex are the shapes? and is that maximum? or is it average? Quote
marko_ribar Posted June 29, 2012 Posted June 29, 2012 Try this, helped with Lee Mac's subfunctions... (defun _vertices ( l ) (if (eq "LWPOLYLINE" (cdr (assoc 0 l))) (_vertices1 l) (_vertices2 (entnext (cdr (assoc -1 l)))) ) ) (defun _vertices1 ( l / p ) (if (setq p (assoc 10 l)) (cons (cdr p) (_vertices1 (cdr (member p l)))) ) ) (defun _vertices2 ( e ) (if (eq "VERTEX" (cdr (assoc 0 (entget e)))) (cons (cdr (assoc 10 (entget e))) (_vertices2 (entnext e))) ) ) (defun _uniquefuzz ( l f ) (if l (cons (car l) (_uniquefuzz (vl-remove-if '(lambda ( x ) (equal x (car l) f)) (cdr l)) f ) ) ) ) (defun c:len&bre ( / ss pl ptlst l-r-ptlst d-u-ptlst midl midr midd midu len bre ) (while (not ss) (prompt "\nSelect 2dpolyline") (setq ss (ssget "_+.:E:S:L" '((0 . "*POLYLINE")))) ) (setq pl (ssname ss 0)) (setq ptlst (_uniquefuzz (_vertices (entget pl)) 1e-) (setq l-r-ptlst (vl-sort ptlst '(lambda (a b) (< (car a) (car b))))) (setq d-u-ptlst (vl-sort ptlst '(lambda (a b) (< (cadr a) (cadr b))))) (setq midl (mapcar '(lambda (a b) (/ (+ a b) 2.0)) (car l-r-ptlst) (cadr l-r-ptlst))) (setq midr (mapcar '(lambda (a b) (/ (+ a b) 2.0)) (caddr l-r-ptlst) (cadddr l-r-ptlst))) (setq midd (mapcar '(lambda (a b) (/ (+ a b) 2.0)) (car d-u-ptlst) (cadr d-u-ptlst))) (setq midu (mapcar '(lambda (a b) (/ (+ a b) 2.0)) (caddr d-u-ptlst) (cadddr d-u-ptlst))) (setq len (distance midl midr)) (setq bre (distance midd midu)) (prompt "\nLength : ")(princ len) (prompt "\nBreadth : ")(princ bre) (princ) ) M.R. Quote
pBe Posted June 29, 2012 Posted June 29, 2012 Well, there you have it. 5 minutes into coding and behold, M.R. provide a solution Try it a complex shape and see if it gives you the result want aaryan. Quote
aaryan Posted June 29, 2012 Author Posted June 29, 2012 Thats it! Thank You so much M.R. pBe. I think this is enough for me. I will look into more complex shape and let you know. Thanks & Regards Aaryan Quote
aaryan Posted June 30, 2012 Author Posted June 30, 2012 I noticed a small error. Can you rectify it please. If my object is smaller in size even after the object has only four segments it gives the breadth same as length. Regards 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.