TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Adesu on March 31, 2008, 10:28:42 PM

Title: How to close rectangular
Post by: Adesu on March 31, 2008, 10:28:42 PM
Hi Alls,
I have a drawing with multiple rectangular (llook at attach file), but that object is alls opened, I want to become close.
I hope "don't use pedit" function, any idea to solve it.
Title: Re: How to close rectangular
Post by: CAB on March 31, 2008, 11:59:45 PM
Simple if the rectangles are aligned with the x & y axis.
Get the max & min x & Y values & create a new object or update the existing one.

You can handle that can't you? :-)
Title: Re: How to close rectangular
Post by: Adesu on April 01, 2008, 01:22:12 AM
That right, it's real solution and I would try it.

Simple if the rectangles are aligned with the x & y axis.
Get the max & min x & Y values & create a new object or update the existing one.

You can handle that can't you? :-)

Title: Re: How to close rectangular
Post by: daron on April 01, 2008, 09:22:27 AM
As you're trying out code, you will run into issues that don't quite work. Post the code using the appropriate tags [code ][/ code] and ask questions about the problems you're having.
Title: Re: How to close rectangular
Post by: ronjonp on April 01, 2008, 03:31:05 PM
Here is my effort...it's not very pretty but seems to work on the examples provided.  :-)

Code: [Select]
(defun c:clsrect (/ int pt1 pt2 pt3 pt4 pts ss x)
  (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
    (progn
      (mapcar '(lambda (x)
(if (and (setq pts (vlax-get x 'Coordinates))
  (>= (length pts) 10)
  (<= (length pts) 12)
     )
   (progn
     (cond ((= (length pts) 10)
    ;;get inter of first and last point and apply
    (setq pt1 (list (nth 0 pts) (nth 1 pts))
  pt2 (list (nth 2 pts) (nth 3 pts))
  pt3 (list (nth 6 pts) (nth 7 pts))
  pt4 (list (nth 8 pts) (nth 9 pts))
  int (inters pt1 pt2 pt3 pt4 nil)
  pts (cddr pts)
  pts (vl-list* (car int) (cadr int) pts)
  pts (cddr (reverse pts))
  pts (vl-list* (cadr int) (car int) pts)
  pts (reverse pts)
    )
    (vlax-put x 'coordinates pts)
    (vla-put-closed x :vlax-true)
   )
   ((= (length pts) 12)
    ;;remove first and last point and close
    (setq pts (cddr pts)
  pts (cddr (reverse pts))
  pts (reverse pts)
    )
    (vlax-put x 'coordinates pts)
    (vla-put-closed x :vlax-true)
   )
     )
   )
)
       )
      (mapcar 'vlax-ename->vla-object
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      )
      )
    )
  )
  (princ)
)
Title: Re: How to close rectangular
Post by: Adesu on April 01, 2008, 07:46:59 PM
Hi Daron,
Thanks for your attention, I'm not quite but one day I attempt it to solve my code, and I got problem to continoues that code
Code: [Select]
(defun massoc (key alist / x nlist)          ; Jaysen Long
  (foreach x alist
    (if
      (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
    ) ; if
  )   ; foreach
  (reverse nlist)
)     ; defun

(defun c:test (/ )
  (if
    (setq ss (ssget "x" '((0 . "LWPOLYLINE"))))
    (progn
      (setq ssl (sslength ss))
      (setq cnt 0)
      (repeat
ssl
(setq ssn (ssname ss cnt))
(setq sse (entget ssn))
(setq lst (massoc 10 sse))
          ; from here I confuse what I should do!

As you're trying out code, you will run into issues that don't quite work. Post the code using the appropriate tags [code ][/ code] and ask questions about the problems you're having.
Title: Re: How to close rectangular
Post by: Adesu on April 01, 2008, 07:55:52 PM
Hi ronjonp,
Your code is "GREAT" and your solution as I looking for.
thanks you very much for your share.


Here is my effort...it's not very pretty but seems to work on the examples provided.  :-)

Code: [Select]
(defun c:clsrect (/ int pt1 pt2 pt3 pt4 pts ss x)
  (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
    (progn
      (mapcar '(lambda (x)
(if (and (setq pts (vlax-get x 'Coordinates))
  (>= (length pts) 10)
  (<= (length pts) 12)
     )
   (progn
     (cond ((= (length pts) 10)
    ;;get inter of first and last point and apply
    (setq pt1 (list (nth 0 pts) (nth 1 pts))
  pt2 (list (nth 2 pts) (nth 3 pts))
  pt3 (list (nth 6 pts) (nth 7 pts))
  pt4 (list (nth 8 pts) (nth 9 pts))
  int (inters pt1 pt2 pt3 pt4 nil)
  pts (cddr pts)
  pts (vl-list* (car int) (cadr int) pts)
  pts (cddr (reverse pts))
  pts (vl-list* (cadr int) (car int) pts)
  pts (reverse pts)
    )
    (vlax-put x 'coordinates pts)
    (vla-put-closed x :vlax-true)
   )
   ((= (length pts) 12)
    ;;remove first and last point and close
    (setq pts (cddr pts)
  pts (cddr (reverse pts))
  pts (reverse pts)
    )
    (vlax-put x 'coordinates pts)
    (vla-put-closed x :vlax-true)
   )
     )
   )
)
       )
      (mapcar 'vlax-ename->vla-object
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      )
      )
    )
  )
  (princ)
)
Title: Re: How to close rectangular
Post by: ronjonp on April 01, 2008, 08:56:01 PM
I wouldn't call it great but thanks for the compliment :)  Glad it worked out for you.

Ron
Title: Re: How to close rectangular
Post by: uncoolperson on April 02, 2008, 01:46:00 AM
lots nicer than what immediately came to my mind....