DDS-NCorette Posted August 9, 2021 Posted August 9, 2021 Hello Everyone, We are looking for a lisp that will delete objects on every layout in a drawing. I have seen a lisp that will delete objects of the same type and layer on every layout, but unfortunately that doesn't give us enough descriptiveness to only delete the objects we need to delete. The location of the objects we want to delete will be the same on every layout, so ideally the lisp will be able to take a selection window on one layout, and delete all the objects within that window location on every layout. If it is easier for coding purposes, we could even draw a box with lines/polylines on one layout and use that to define the selection window for all the other layouts, and then just delete the box at the end from the one layout. If anyone has any ideas, or if any more information would be helpful, please let me know! Thank you all, - Noah Quote
BIGAL Posted August 9, 2021 Posted August 9, 2021 If you pick 2 points for a window erase save them then yes just go to each layout and carry out the erase. The one rule every layout must have is that objects are always in the same place. Try this (alert "Make sure you are in a layout") (setq pt1 (getpoint "\pick 1st point for window ")) (setq pt2 (getpoint pt1 "\pick 2nd point for window ")) (vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))) (command "pspace") (command "erase" "w" pt1 pt2 "" ) ) You can say do pick pts and also window combo's. with points need to use ssget . Quote
DDS-NCorette Posted August 10, 2021 Author Posted August 10, 2021 12 hours ago, BIGAL said: If you pick 2 points for a window erase save them then yes just go to each layout and carry out the erase. The one rule every layout must have is that objects are always in the same place. Try this (alert "Make sure you are in a layout") (setq pt1 (getpoint "\pick 1st point for window ")) (setq pt2 (getpoint pt1 "\pick 2nd point for window ")) (vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))) (command "pspace") (command "erase" "w" pt1 pt2 "" ) ) You can say do pick pts and also window combo's. with points need to use ssget . Hello BIGAL, Thank you for the response. I tried the code as a script, and also modified it slightly into a Lisp, but neither way I tried it could I get it to work... I have a pretty limited understanding of running scripts and what not, perhaps I am missing something obvious... could you by chance elaborate slightly on how you would go about implementing this code? Thank you, - Noah Quote
DDS-NCorette Posted August 10, 2021 Author Posted August 10, 2021 Hello again everyone, Between searching through various forums, BIGAL's help, and just messing around with Lisps, I have managed to put together a very simple lisp that accomplishes what I want to do: ; Deletes an object from the same selection window in all layouts (defun c:DELayouts () (setq pt1 (getpoint "\pick 1st point for window ")) (setq pt2 (getpoint pt1 "\pick 2nd point for window ")) (foreach layout (layoutlist) (setvar "ctab" layout) (command "pspace") (command "erase" "w" pt1 pt2 "" ) );foreach (princ) );defun It takes a little while for it to run, but it's way way better than manually opening each layout and deleting an object. Thanks for your help BIGAL! Thanks, - Noah Quote
mhupp Posted August 10, 2021 Posted August 10, 2021 This checks if your in model space, then only have to select a item and will generate the two points. it will display "# Item(s) deleted" So if you have 5 tabs and it says 37 items deleted you might want to check what was deleted. then returns you to the tab you where on before you ran the command. ; Deletes an object from the same selection window in all layouts (defun c:DELayouts (/ obj old PT1 PT2 LAYOUT SS c) (vl-load-com) (if (= (getvar "TILEMODE") 0) ;check if on a tab (progn (setvar 'CVPORT 1) ; go into paper space (if (setq obj (car (entsel "\nSelect entity to delete from all tabs"))) (progn (setq old (getvar 'ctab) c 0 ) (vla-getboundingbox (vlax-ename->vla-object obj) 'minpt 'maxpt) (setq PT1 (vlax-safearray->list minpt) ; Object's Lower Left PT2 (vlax-safearray->list maxpt) ; Object's Upper Right ) (foreach layout (layoutlist) (setvar 'ctab layout) (setvar 'cvport 1) ; go into paper space (if (setq SS (ssget "W" PT1 PT2 '((cons 410 layout)))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (vla-delete (vlax-ename->vla-object ent)) (setq c (1+ c)) ) ) (setvar 'ctab old) (prompt (strcat "\n" (itoa c) " Item(s) Deleted")) ) ) (prompt "\nNothing selected or item isn't in paper space") ) ) (prompt "\nYou need to be in paper space to use this command") ) (princ) ) Quote
CADWORKER Posted February 26 Posted February 26 On 8/10/2021 at 7:14 PM, mhupp said: This checks if your in model space, then only have to select a item and will generate the two points. it will display "# Item(s) deleted" So if you have 5 tabs and it says 37 items deleted you might want to check what was deleted. then returns you to the tab you where on before you ran the command. ; Deletes an object from the same selection window in all layouts (defun c:DELayouts (/ obj old PT1 PT2 LAYOUT SS c) (vl-load-com) (if (= (getvar "TILEMODE") 0) ;check if on a tab (progn (setvar 'CVPORT 1) ; go into paper space (if (setq obj (car (entsel "\nSelect entity to delete from all tabs"))) (progn (setq old (getvar 'ctab) c 0 ) (vla-getboundingbox (vlax-ename->vla-object obj) 'minpt 'maxpt) (setq PT1 (vlax-safearray->list minpt) ; Object's Lower Left PT2 (vlax-safearray->list maxpt) ; Object's Upper Right ) (foreach layout (layoutlist) (setvar 'ctab layout) (setvar 'cvport 1) ; go into paper space (if (setq SS (ssget "W" PT1 PT2 '((cons 410 layout)))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (vla-delete (vlax-ename->vla-object ent)) (setq c (1+ c)) ) ) (setvar 'ctab old) (prompt (strcat "\n" (itoa c) " Item(s) Deleted")) ) ) (prompt "\nNothing selected or item isn't in paper space") ) ) (prompt "\nYou need to be in paper space to use this command") ) (princ) ) Hi Mhupp, I was going though the request of symoin and then searching the related I landed here. Is it possible to delete the objects from the model space in a similarway? Quote
BIGAL Posted February 26 Posted February 26 Using a delete window it does not matter what space your in, but if the objects are not in the same place in say multiple dwg's it will not work. 1 Quote
mhupp Posted February 27 Posted February 27 @CADWORKER unfortunately AutoCAD doesn't support or I haven't figured it out how to use a lisp across multiple drawings with out using a scripts. @symoin This should help speed up the process of deleting "selected objects across multiple drawings" as long as its in the same place like BIGAL said. Open up a Drawing. Zoom to what you want to delete. run the command and select "yes" and set the zoom window around the objects. this will send the zoom location to any drawing you have open or open in the same Autocad session using vl-propagate go to next drawing and type in command select "No" if the object is in the "same" place it will be in your zoom window. Also entity names are generated when a drawing is opened or when its created. these are unique to the drawing and change if the drawing is closed and open again. ;;----------------------------------------------------------------------------;; ;; Zoom Area Across Multiple Drawings (defun C:ZAD (/ ask) ;Zoom Across Drawings (vl-load-com) (initget "Yes No") (setq ask (cond ((getkword "\nRedefine Zoom Area? [Yes/No]: ")) ( "No") ) ) (if (= "Yes" ask) (progn (vl-cmdf "_.Zoom" "W" Pause Pause) (setq vc (getvar 'viewctr)) (setq SZ (getvar 'viewsize)) (vl-propagate 'vc) (vl-propagate 'sz) ) (if (or (= vc nil) (= sz nil)) (prompt "\nPlease Define Zoom Area") (vl-cmdf "_.Zoom" "C" VC SZ) ) ) (princ) ) Quote
BIGAL Posted February 27 Posted February 27 " lisp across multiple drawings " OBDBX will do, but in this case I dont think getting a window of objects in another dwg will mean they are correct objects, moving stuff in Model is to easy. 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.