PDA

View Full Version : lisp to move largest room polyline to another layer for floor gross polyline



TheresaT
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:

jammie
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?

Regards

Jammie

TheresaT
25th Aug 2010, 12:55 pm
Jammie -
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.

jammie
25th Aug 2010, 02:08 pm
No problem

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)?

jammie
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)

(vl-load-com)

(setq selectionFilter (list (cons 0 "*POLYLINE")(cons 8 "A-AREA"))
targetLayer "A-AREA-GROSS")

(if

(Setq tempSelectionSet (ssget "x" selectionFilter))

(progn


(if
(not (tblsearch "layer" targetLayer))
(progn
(setq layerCollection (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))

(vla-add layerCollection targetLayer)))


(setq i 0 maxArea 0.0)

(repeat

(sslength tempSelectionSet)

(setq object (vlax-ename->vla-object (ssname tempSelectionSet i))
i (1+ i))

(setq objectArea (vla-get-area object))

(cond
((> 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)
)
)
)
)

TheresaT
25th Aug 2010, 03:24 pm
That's exactly what we needed! Many thanks. It works just fine.

alanjt
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))
)
(vla-delete ss)
(foreach x l
(and (equal v (car x)) (vl-catch-all-apply (function vla-put-layer) (list (cdr x) layer)))
)
)
(vla-get-name
(vla-add (vla-get-layers
(cond (*AcadDoc*)
((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
)
)
new
)
)
)
)
)