TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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.
-
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? :-)
-
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? :-)
-
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. :-)
(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)
)
-
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
(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.
-
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. :-)
(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)
)
-
I wouldn't call it great but thanks for the compliment :) Glad it worked out for you.
Ron
-
lots nicer than what immediately came to my mind....