Hsanon Posted Saturday at 07:54 AM Posted Saturday at 07:54 AM Hi, Is there a Lisp routine which can move all objects within a selected polyline to a layer called "exist" and all objects outside that same polyline to a layer called "site" ?? ignoring all frozen or OFF layers ?? Regards. Quote
Steven P Posted Saturday at 10:43 AM Posted Saturday at 10:43 AM If you want to have a go, look at Selection Sets to select everything within the polyline (see Lee Mac Selection sets page - it is rather good - ssget), window polygon or crossing polygon Do 2 selection sets - one for everything "_X" and one for Crossing Polygon, I think Lee Mac has a routine there to remove one selection set from another. This gives you 2 sets of entities to work with Loads of LISPs out there to change layers. Have a go, it is easier than you might think Quote
aridzv Posted Saturday at 11:38 AM Posted Saturday at 11:38 AM (edited) Try this: (defun c:chglyobjpl (/ acdoc p_list p_coord sset ent obj newLayerName i) (vl-load-com) (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))) ;;;;;;;;;;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/selection-set-using-existing-polygon/td-p/11307274 ;;;;;;;;;;;calderg1000 msg-7 (setq p_list (entget (car (entsel "\nSelect the LwPolyline: ")))) (if (setq p_coord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) p_list) );;end setq p_coord );;end if condition (sssetfirst nil (setq sset (ssget "_wp" p_coord))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;Select Objects In polygon;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;Change Objects Layer;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if sset (progn (setq newLayerName "exist") ;;(getstring T "\nEnter new layer name: ")) (repeat (setq i (sslength sset)) (setq i (1- i)) (setq ent (ssname sset i)) (setq obj (vlax-ename->vla-object ent)) (vla-put-Layer obj newLayerName) );;repeat (vla-Regen acdoc acAllViewports) (sssetfirst nil nil) );;progn (princ "\nNo objects found in the drawing.") );;if ;;;;;;;;;;;;;;;;;;;;;;;;;;;;Change Objects Layer;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (princ) );;end defun Edited Saturday at 11:44 AM by aridzv Quote
Hsanon Posted Saturday at 02:29 PM Author Posted Saturday at 02:29 PM Thanks ... but..... on running the program, its saying that "no objects found in the drawing" and the program closes Quote
aridzv Posted Saturday at 03:03 PM Posted Saturday at 03:03 PM (edited) see new code. make sure the layers names are correct. (defun c:chglyobjpl (/ acdoc p_list p_coord sset ent obj newLayerName newLayerName1 i) (vl-load-com) (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))) (princ "\nSelect All Objects To Proccess") (setq ssall (ssget)) (setq p_list (entget (car (entsel "\nSelect the Polyline Boundery For ''exist'' Layer: ")))) (setq i 0) ;;;;;;;;;;;;;;;;;;;;;;;;;;;Change Objects To site Layer;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if ssall (progn (sssetfirst nil nil) (setq newLayerName1 "site");;(getstring T "\nEnter new layer name: ")) (repeat (setq i (sslength ssall)) (setq i (1- i)) (setq ent (ssname ssall i)) (setq obj (vlax-ename->vla-object ent)) (vla-put-Layer obj newLayerName1) );;repeat (vla-Regen acdoc acAllViewports) (sssetfirst nil nil) );;progn (princ "\nNo objects found in the drawing.") );;if ;;;;;;;;;;;;;;;;;;;;;;;;;;;Change Objects To site Layer;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq ent nil) (setq obj nil) (setq i 0) ;;;;;;;;;;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/selection-set-using-existing-polygon/td-p/11307274 ;;;;;;;;;;;calderg1000 msg-7 (if (setq p_coord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) p_list) );;end setq p_coord );;end if condition (sssetfirst nil (setq sset (ssget "_wp" p_coord))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;Select Objects In polygon;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;Change Objects Layer;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if sset (progn (sssetfirst nil nil) (setq newLayerName "exist");;(getstring T "\nEnter new layer name: ")) (repeat (setq i (sslength sset)) (setq i (1- i)) (setq ent (ssname sset i)) (setq obj (vlax-ename->vla-object ent)) (vla-put-Layer obj newLayerName) );;repeat (vla-Regen acdoc acAllViewports) (sssetfirst nil nil) );;progn (princ "\nNo objects found in the drawing.") );;if ;;;;;;;;;;;;;;;;;;;;;;;;;;;;Change Objects To exist Layer;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (sssetfirst nil nil) (princ) );;end defun test1.mp4 Edited Saturday at 03:43 PM by aridzv Quote
BIGAL Posted yesterday at 01:30 AM Posted yesterday at 01:30 AM My $0.05 does not check for off or frozen layers. (defun c:wow ( / ent co-ord ss) (if (tblsearch "layer" "Site") (princ) (command "-layer" "Make" "Site" "c" 1 "" "") ) (if (tblsearch "layer" "Exist") (princ) (command "-layer" "Make" "Exist" "c" 2 "" "") ) (command "chprop" "all" "" "la" "Site" "") (setq ent (car (entsel "\nPick the pline "))) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent)))) (setq ss (ssget "WP" Co-ord)) (command "chprop" ss "" "LA" "Exist" "") (princ) ) (c:wow) 1 Quote
Hsanon Posted 9 hours ago Author Posted 9 hours ago Hi, many thanks for your help Aridzv and BigAl, But, all entities are being converted to layer "site". The ones inside the pline are not being moved to layer "exist" I'm attaching the drawing on which I am testing. surveytest.dwg Quote
aridzv Posted 7 hours ago Posted 7 hours ago (edited) @Hsanon I tried both lisps and they work. @BIGAL lisp works - after you run the command you need to select the boundery polygon. with my lisp - before runnig it you need to make sure both "exist" and "site" layers exist. in your case you need to create "exist" layer. See attached Video using my lisp. Recording 2025-11-10 110909.mp4 Edited 7 hours ago by aridzv Quote
Hsanon Posted 1 hour ago Author Posted 1 hour ago And its not happening on my machine......am i doing anything wrong ???? is it an autocad issue ??? attaching a screen recording... sorry to be such a bother !!!!! changing layers.mp4 Quote
aridzv Posted 1 hour ago Posted 1 hour ago @Hsanon the only way I can reproduse what you show is if "exist" layer dosen't exist. I don't see that layer in the video you shared. MAKE THIS LAYER BEFORE RUNNING THE LISP AS SHOWN IN MY VIDEO. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.