0 Members and 1 Guest are viewing this topic.
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?
(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))
(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.
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))