Author Topic: How to close rectangular  (Read 2878 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
How to close rectangular
« 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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to close rectangular
« Reply #1 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? :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Adesu

  • Guest
Re: How to close rectangular
« Reply #2 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? :-)


daron

  • Guest
Re: How to close rectangular
« Reply #3 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.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to close rectangular
« Reply #4 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)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Adesu

  • Guest
Re: How to close rectangular
« Reply #5 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.

Adesu

  • Guest
Re: How to close rectangular
« Reply #6 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)
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to close rectangular
« Reply #7 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
« Last Edit: April 01, 2008, 11:05:25 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

uncoolperson

  • Guest
Re: How to close rectangular
« Reply #8 on: April 02, 2008, 01:46:00 AM »
lots nicer than what immediately came to my mind....