View Full Version : lisp to move largest room polyline to another layer for floor gross polyline
25th Aug 2010, 05:02 am
I need a autolisp routine to search an existing layer of room closed polylines (A-AREA) and pick out the largest one, create a new layer for this and then move this object to this new layer (A-AREA-GROSS). Is this possible? Thanks in advance for any help.:unsure:
25th Aug 2010, 11:48 am
Welcome to the forum!
That should be possible to do. Have you any code written that you could post? Or even thoughts about how you would like to achieve it?
25th Aug 2010, 12:55 pm
I haven't a clue how to approach this as it's been years since I created any lisp routines. Any help would be appreciated.
25th Aug 2010, 02:08 pm
Is there a possibility that there could be multiple polylines of the same area? That more then one polyine will need to be placed on layer (A-AREA-GROSS)?
25th Aug 2010, 02:30 pm
Not heavily tested but as a starting point maybe
(defun c:test (/ selectionFilter targetLayer tempSelectionSet layerCollection maxArea i object objectArea tempObjectList)
(setq selectionFilter (list (cons 0 "*POLYLINE")(cons 8 "A-AREA"))
(Setq tempSelectionSet (ssget "x" selectionFilter))
(not (tblsearch "layer" targetLayer))
(setq layerCollection (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(vla-add layerCollection targetLayer)))
(setq i 0 maxArea 0.0)
(setq object (vlax-ename->vla-object (ssname tempSelectionSet i))
i (1+ i))
(setq objectArea (vla-get-area object))
((> objectArea maxArea)(setq maxArea objectArea tempObjectList (list object )))
((equal objectArea maxArea 1e-6)(setq tempObjectList (append tempObjectList (list object )))))
(foreach <object> tempObjectList
(vla-put-layer <object> targetLayer)
25th Aug 2010, 03:24 pm
That's exactly what we needed! Many thanks. It works just fine.
25th Aug 2010, 07:11 pm
One more example - which will only select closed LWPolylines...
(defun foo (search new / ss)
;; eg. (foo "Layer1" "NewLayer")
;; Alan J. Thompson, 08.25.10
(if (setq ss (ssget "_X"
(list '(0 . "LWPOLYLINE")
'(-4 . "<OR")
'(70 . 1)
'(70 . 129)
'(-4 . "OR>")
(cons 8 search)
((lambda (layer / a v l)
(vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*))
(or (> v (setq a (vla-get-area x))) (setq v a))
(setq l (cons (cons a x) l))
(foreach x l
(and (equal v (car x)) (vl-catch-all-apply (function vla-put-layer) (list (cdr x) layer)))
((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.