Jump to content

Recommended Posts

Posted (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 by aaryan
Posted

Can you run that by me again Aaryan? Post an example this time :)

Posted

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

Posted

Maximum base.

LxBxH where H is height which i dont require to mention in my drawing only the LxB.

Posted

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 : ?

Posted

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

Posted

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?

Posted

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.

Posted

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.

Posted

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

Posted

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...