Author Topic: Simple Delete Window in all drawings or layouts  (Read 3409 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Simple Delete Window in all drawings or layouts
« on: August 17, 2016, 09:07:42 AM »
A guy just asked about this... What are your thoughts on a command that can erase a Window selection in all layouts or selection of drawings. Is that possible? Execute a routine that prompts the user for a location to delete then does the same through the current dwg layouts. I don't know if it could do that in a selection of drawings in a folder.

thxs guys
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Simple Delete Window in all drawings or layouts
« Reply #1 on: August 17, 2016, 09:40:50 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:usewithcaution (/ p1 p2 ss)
  2.   (if (and (= 0 (getvar 'tilemode))
  3.            (setq p1 (getpoint "\nSpecify first corner point: "))
  4.            (setq p2 (getcorner p1 "\nSpecify other corner point: "))
  5.       )
  6.     (foreach tab (layoutlist)
  7.       (setvar 'ctab tab)
  8.       (and (= 1 (getvar 'cvport)) (vlax-invoke (vlax-get-acad-object) 'zoomwindow p1 p2))
  9.       (if (setq ss (ssget "W" p1 p2 (list (cons 410 tab))))
  10.         (mapcar 'entdel (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  11.       )
  12.     )
  13.   )
  14.   (princ)
  15. )
« Last Edit: August 17, 2016, 09:57:18 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Simple Delete Window in all drawings or layouts
« Reply #2 on: August 17, 2016, 09:46:14 AM »
Simple great code ronjon. Thanks for the help.
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Simple Delete Window in all drawings or layouts
« Reply #3 on: August 17, 2016, 09:49:45 AM »
Simple great code ronjon. Thanks for the help.
Glad to help  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Simple Delete Window in all drawings or layouts
« Reply #4 on: August 17, 2016, 09:55:52 AM »
Again. and again. and again. You DAH man!
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Simple Delete Window in all drawings or layouts
« Reply #5 on: August 17, 2016, 09:58:41 AM »
Again. and again. and again. You DAH man!
:)
I updated the code above to zoom to the area where the objects are to be deleted. If they were off screen the previous code would fail.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Simple Delete Window in all drawings or layouts
« Reply #6 on: August 17, 2016, 10:05:41 AM »
Sweet
Civil3D 2020

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Simple Delete Window in all drawings or layouts
« Reply #7 on: August 17, 2016, 03:29:58 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:usewithcaution (/ p1 p2 ss)
  2.   (if (and (= 0 (getvar 'tilemode))
  3.            (setq p1 (getpoint "\nSpecify first corner point: "))
  4.            (setq p2 (getcorner p1 "\nSpecify other corner point: "))
  5.       )
  6.     (foreach tab (layoutlist)
  7.       (setvar 'ctab tab)
  8.       (and (= 1 (getvar 'cvport)) (vlax-invoke (vlax-get-acad-object) 'zoomwindow p1 p2))
  9.       (if (setq ss (ssget "W" p1 p2 (list (cons 410 tab))))
  10.         (mapcar 'entdel (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  11.       )
  12.     )
  13.   )
  14.   (princ)
  15. )
Thanks for sharing this, Ron!
Its not about what the code does, but the skill of writing it.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Simple Delete Window in all drawings or layouts
« Reply #8 on: August 17, 2016, 03:33:14 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:usewithcaution   (/ p1 p2 ss)
  2.   (if (and (= 0 (getvar 'tilemode))
  3.       (setq p1 (getpoint "\nSpecify first corner point: "))
  4.       (setq p2 (getcorner p1 "\nSpecify other corner point: "))
  5.       )
  6.     (foreach tab (layoutlist)
  7.       (setvar 'ctab tab)
  8.       (and (= 1 (getvar 'cvport)) (vlax-invoke (vlax-get-acad-object) 'zoomwindow p1 p2))
  9.       (if (setq ss (ssget "W" p1 p2 (list (cons 410 tab))))
  10.    (mapcar 'entdel (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  11.       )
  12.     )
  13.   )
  14.   (princ)
  15. )
Thanks for sharing this, Ron!
Its not about what the code does, but the skill of writing it.
Glad you can use it :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Simple Delete Window in all drawings or layouts
« Reply #9 on: August 21, 2016, 03:19:23 AM »
Very good program!
I did a little modification in order to improve perfomance (see attached lisp)
1. Replaced Window mode to Crossing mode
2. Added option to unload all xrefs before execution of this program and reload it after it (no need to explane a main goal of this additon)

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Simple Delete Window in all drawings or layouts
« Reply #10 on: August 21, 2016, 07:57:01 AM »
Nice modification.
Civil3D 2020

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Simple Delete Window in all drawings or layouts
« Reply #11 on: August 22, 2016, 09:21:16 AM »
select layout, thanx dialog from Lee
Code: [Select]
(defun c:xx   (/ p1 p2 ss)

  (vl-load-com)
;; http://www.lee-mac.com/listbox.html
;; List Box  -  Lee Mac
;; Displays a DCL list box allowing the user to make a selection from the supplied data.
;; msg - [str] Dialog label
;; lst - [lst] List of strings to display
;; bit - [int] 1=allow multiple; 2=return indexes
;; Returns: [lst] List of selected items/indexes, else nil

  (defun LM:listbox (msg lst bit / dch des tmp rtn)
   (cond
      ((not
          (and
             (setq tmp (vl-filename-mktemp nil nil ".dcl"))
             (setq des (open tmp "w"))
             (write-line
                (strcat "listbox:dialog{label=\""
                        msg
                        "\";spacer;:list_box{key=\"list\";multiple_select="
                        (if (= 1 (logand 1 bit))
                           "true"
                           "false"
                        )
                        ";width=50;height=15;}spacer;ok_cancel;}"
                )
                des
             )
             (not (close des))
             (< 0 (setq dch (load_dialog tmp)))
             (new_dialog "listbox" dch)
          )
       )
       (prompt "\nError Loading List Box Dialog.")
      )
      (t
       (start_list "list")
       (foreach itm lst (add_list itm))
       (end_list)
       (setq rtn (set_tile "list" "0"))
       (action_tile "list" "(setq rtn $value)")
       (setq rtn
               (if (= 1 (start_dialog))
                  (if (= 2 (logand 2 bit))
                     (read (strcat "(" rtn ")"))
                     (mapcar '(lambda (x) (nth x lst)) (read (strcat "(" rtn ")")))
                  )
               )
       )
      )
   )
   (if (< 0 dch)
      (unload_dialog dch)
   )
   (if (and tmp (setq tmp (findfile tmp)))
      (vl-file-delete tmp)
   )
   rtn
 )


  (setq layouts (LM:listbox "Select Layouts to modify... " (layoutlist) 1))
  (vl-load-com)
  (if (and (= 0 (getvar 'tilemode))
      (setq p1 (getpoint "\nSpecify first corner point: "))
      (setq p2 (getcorner p1 "\nSpecify other corner point: "))
      )
    (foreach tab layouts
      (setvar 'ctab tab)
      (and (= 1 (getvar 'cvport)) (vlax-invoke (vlax-get-acad-object) 'zoomwindow p1 p2))
      (if (setq ss (ssget "W" p1 p2 (list (cons 410 tab))))
(mapcar 'entdel (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
      )
    )
  )
  (princ)
)
« Last Edit: August 22, 2016, 09:25:17 AM by cadplayer »

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Simple Delete Window in all drawings or layouts
« Reply #12 on: August 22, 2016, 09:25:43 AM »
Not bad!
Civil3D 2020

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Simple Delete Window in all drawings or layouts
« Reply #13 on: August 22, 2016, 09:34:01 AM »
looks better with my little modification...