Author Topic: Need a script to delete a specific block in PaperSpace  (Read 6347 times)

0 Members and 1 Guest are viewing this topic.

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Need a script to delete a specific block in PaperSpace
« on: October 08, 2014, 10:42:15 PM »
 :crazy2:
Going through loops.

Municipality requires that we deposit PDFs that include "For Construction" Stamp into their proprietary web based interface. They also require us to upload our CAD files and PDF's without the "For Construction" stamp to a different Web Based interface.

We've got a small set of 55 dwgs.. and I've already put the stamp in all 55 dwgs.  So I can publish the set to PDF and create the initial PDF's with "For Construction" but I don't want to individually open 55 files to remove the stamp.  FYI the block name is FORCONSTRUCTION.  I utilize SCRIPT Pro and so I can run an .scr file on all the dwgs in the set, but I don't know how to write the .scr file  so that it will erase a specific block with the name of "FORCONSTRUCTION".

oh.. fyi.. the block is not in the same place on every dwg.. we have 11x17's, 42x30, and 24x36, and some really odd sizes.

The stamp is in PS in all the dwgs thou.. I put them in.. so I know.

I've considered doing a simple block swap.. having the replacement block just have linework on defpoints so it doesn't plot.. but I know the municipality would rather the block just be gone.

FYI   this municipality doesn't allow XREF's.. dwgs must be 100% stand alone items prior to upload.  and broken XREF's is a no-no.. (red flag's their system)

 
I am very  trainable....   (forgive my spelling)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need a script to delete a specific block in PaperSpace
« Reply #1 on: October 09, 2014, 12:22:48 AM »
assuming it is not on a locked layer try this in your script:
Code: [Select]
(and (setq ss (ssget "X" '((0 . "INSERT") (2 . "FORCONSTRUCTION"))))
     (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     (mapcar (function (lambda (x) (entdel x))) lst)
)

It does not purge the block just removes the inserts.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: Need a script to delete a specific block in PaperSpace
« Reply #2 on: October 09, 2014, 04:55:39 AM »
I believe that this 2 routines can cover your needs
http://www.lee-mac.com/odbxbase.html
http://www.lee-mac.com/deleteblocks.html

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need a script to delete a specific block in PaperSpace
« Reply #3 on: October 09, 2014, 05:53:21 AM »
You'll find that ssget will select the blocks in paperspace layouts BUT
(entdel block) will only work for the last or current paperspace layout and Modelspace.
The ActiveX vla-delete will work correctly.

This should do the job ;
Code - Auto/Visual Lisp: [Select]
  1. (if (setq ss (ssget "X" '((0 . "INSERT") (2 . "FORCONSTRUCTION"))))
  2.   (while (setq block (ssname ss 0))
  3.     (vla-delete (vlax-ename->vla-object block))
  4.     (ssdel block ss)
  5.   )
  6. )



I have used it like this to remove Approval Submission stamp blocks :
Code - Auto/Visual Lisp: [Select]
  1. ;; Remove Approval Stamps.scr
  2. (LOAD "K:\\SteelTools\\ScriptPro 2.0\\CodeFiles\\Remove Approval Stamps.lsp")
  3. (Remove_Approval_Stamps)
  4.  

Code - Auto/Visual Lisp: [Select]
  1. ;; Remove Approval Stamps.lsp
  2. ;; Codehimbelonga kdub@theSwamp 2014/10/08
  3.  
  4. (defun remove_approval_stamps (/)
  5.   (setq exprt (getvar "expert"))
  6.   (setvar "EXPERT" 5)
  7.   (command "-layer" "set" "0" "")
  8.   (command "Zoom" "All")
  9.   (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  10.   ;;
  11.   (if
  12.     (setq ss (ssget "X" '((0 . "INSERT") (2 . "FORCLIENTALLROVAL"))))
  13.      (while (setq block (ssname ss 0))
  14.        (vla-delete (vlax-ename->vla-object block))
  15.        (ssdel block ss)
  16.      )
  17.   )
  18.   (vl-cmdf "_.Audit" "Y")
  19.   (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  20.   (setvar "EXPERT" exprt)
  21.   (command "QSAVE")
  22.   (princ)
  23. )
  24.  
  25.  
  26.  
« Last Edit: October 09, 2014, 06:04:01 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Rob...

  • King Gator
  • Posts: 3824
  • Take a little time to stop and smell the roses.
Re: Need a script to delete a specific block in PaperSpace
« Reply #4 on: October 09, 2014, 06:43:20 AM »
Those types of requirements annoy the hell out of me. Requirements from the paper only days for electronic files and dictating how we handle our files.

Why don't they get a CAD person to set up the files as necessary for their system?
CAD Tech

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need a script to delete a specific block in PaperSpace
« Reply #5 on: October 09, 2014, 08:27:21 AM »
Thanks Kerry I forgot about entdel not working in all cases.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need a script to delete a specific block in PaperSpace
« Reply #6 on: October 09, 2014, 08:45:17 AM »
Thanks Kerry I forgot about entdel not working in all cases.

You're welcome.
I think I owe Jeff Mishler for the original solution. ( about 10 years ago :) )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need a script to delete a specific block in PaperSpace
« Reply #7 on: October 09, 2014, 11:16:05 AM »
Time flies when you haven fun.  8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Need a script to delete a specific block in PaperSpace
« Reply #8 on: October 09, 2014, 12:38:24 PM »
Guys, I'm not great at scripting.  I don't know enough to do the following myself, but I was just thinking as I was about to shar this with my cooworkers,   And I thought how usefull this could actually be, and that my coworkers are going to want to modify this all the time for different blocks in different situations. 

How could the code be modified in the LSP to prompt the user for the name of the block?

I was thinking if I could add a lisp like the above to the startup suit.. scripting would be even easier

REMBLOCK
FORCONSTRUCTION
QSAVE

Thoughts?

I have attached the script as a txt file as I've modified it thus far.  I really appreciate the help and it can be used for the purpose I posted as is.. but I'm trying to think ahead.
I am very  trainable....   (forgive my spelling)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need a script to delete a specific block in PaperSpace
« Reply #9 on: October 09, 2014, 01:28:22 PM »
Looks at this which allows more than one name.
Code: [Select]
;; RemStamps.lsp
;; MODIFIED CODE
;; thanks to Codehimbelonga kdub@theSwamp 2014/10/08
(vl-load-com)

(defun remstamp (blknames / blkname)
  (setq exprt (getvar "expert"))
  (setvar "EXPERT" 5)
  (command "-layer" "set" "0" "")
  (command "Zoom" "All")
  (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  ;;
  (foreach blkname blknames
  (if
    (setq ss (ssget "X" (list '(0 . "INSERT") (cons 2  blkname))))
     (while (setq block (ssname ss 0))
       (vla-delete (vlax-ename->vla-object block))
       (ssdel block ss)
     )
  )
  )
  (vl-cmdf "_.Audit" "Y")
  (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  (setvar "EXPERT" exprt)
  (command "QSAVE")
  (princ)
)


(princ)


;;;;; RemStamp.scr
;;;(LOAD "P:\\DWells\\LSP\\REMOVE_Block\\REMSTAMP.lsp")
;;;(RemStamp (list "FORCONSTRUCTION" "REMBLOCK"))

;|«Visual LISP© Format Options»
(70 2 45 2 nil "end of " 80 9 1 0 0 nil nil nil T)
;*** DO NOT add text below the comment! ***|;
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cadtag

  • Swamp Rat
  • Posts: 1152
Re: Need a script to delete a specific block in PaperSpace
« Reply #10 on: October 09, 2014, 01:28:38 PM »
Stamp only need to be on the PDFs, right?  why not just apply the stamp to the PDF instead of in the drawing file?   think of it as a watermark that just needs to be applied to those specific pdf files going to that specific destination.
The only thing more dangerous to the liberty of a free people than big government is big business

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Need a script to delete a specific block in PaperSpace
« Reply #11 on: October 09, 2014, 02:30:27 PM »
The higher ups are considering this as well but some believe.. that if the cad technicians are already in the files.. why can't they just put in the stamps.. and  followed by why do document control personell need to do that.. and then we have to train them on which stamps...  ultimatly I believe the pdf stamp is an option, but my gut says.. we'll be doing it in cad if management has anything to say.
I am very  trainable....   (forgive my spelling)

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Need a script to delete a specific block in PaperSpace
« Reply #12 on: October 09, 2014, 02:52:52 PM »
I'm not getting this to work propperly... I loaded the lisp and then tried to run via the command remstamp and I get

Unknown command "REMSTAMP". Press F1 for Help.

Did I miss something??

if I run via the scr I get

; error: too few arguments

I am very  trainable....   (forgive my spelling)

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Need a script to delete a specific block in PaperSpace
« Reply #13 on: October 09, 2014, 02:56:38 PM »
You have to supply the block names .. like so:
Quote
(remstamp "REMBLOCK,FORCONSTRUCTION")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Need a script to delete a specific block in PaperSpace
« Reply #14 on: October 09, 2014, 03:24:50 PM »
 :-(
I get that, but I can't use it at the command prompt that way if I load the lsp... 

Awesome for running with SCRIPT PRO.  but what could we do to get it to work at the command prompt.. ultimatly multiple options are very cool, but being aple to type the comand.. hit enter then type the block name would be ideal.  like mentioned before, one could always script it to run twice

remstamp
forconstruction
remstamp
forapproval
qsave

It would be handy to have at the command prompt while in the file as much as just for scripting use.

Does that make sence?
most of the crew i work with don't even know how to make .scr files.. so I got to get it simpler.
I am very  trainable....   (forgive my spelling)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need a script to delete a specific block in PaperSpace
« Reply #15 on: October 09, 2014, 03:32:51 PM »
You have to supply the block names .. like so:
Quote
(remstamp "REMBLOCK,FORCONSTRUCTION")
Hummm, I don't think so.
Something else causing the error.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need a script to delete a specific block in PaperSpace
« Reply #16 on: October 09, 2014, 03:36:57 PM »
:(
I get that, but I can't use it at the command prompt that way if I load the lsp... 

Awesome for running with SCRIPT PRO.  but what could we do to get it to work at the command prompt.. ultimatly multiple options are very cool, but being aple to type the comand.. hit enter then type the block name would be ideal.  like mentioned before, one could always script it to run twice

remstamp
forconstruction
remstamp
forapproval
qsave

It would be handy to have at the command prompt while in the file as much as just for scripting use.

Does that make sence?
most of the crew i work with don't even know how to make .scr files.. so I got to get it simpler.

Look at this subroutine:
http://www.theswamp.org/index.php?topic=2688.msg34342#msg34342
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Need a script to delete a specific block in PaperSpace
« Reply #17 on: October 09, 2014, 03:54:33 PM »
OK..
I have two blocks in the drawing,
one named DEMOLITON and one named FORCONSTRUCTION

I paisted

(remstamp "REMBLOCK,FORCONSTRUCTION")
and
(remstamp "DEMOLITION,FORCONSTRUCTION")
both times the purge seems to run but then I get this at the command prompt

I even typed it in instad of paisting .. i attached the lsp and the DWG.


Command: ; error: bad argument type: consp "REMBLOCK,FORCONSTRUCTION"
Command: ; error: bad argument type: consp "DEMOLITION,FORCONSTRUCTION"

I even re-copied your code, resaved the .lsp file, and reloaded the lsp. and ran it a second time...
something.. aint right.
I am very  trainable....   (forgive my spelling)

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Need a script to delete a specific block in PaperSpace
« Reply #18 on: October 09, 2014, 03:59:00 PM »
I don't know how to implement the subroutine.. I'm not good at writing the code.. I had a rough time following the script above.. the subroutine is way over my head. .
I am very  trainable....   (forgive my spelling)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need a script to delete a specific block in PaperSpace
« Reply #19 on: October 09, 2014, 06:37:46 PM »
This is how I'd do it.

Use the enclosed lisp File.
Use a script file for each combination of blocks ; each file with a unique name.

If used manually, type SCRIPT at the command line and select the appropriate script.
If used with ScriptPro, call the appropriate script.

Code - Auto/Visual Lisp: [Select]
  1. ;; RemStamps.lsp
  2. ;; MODIFIED CODE 2014/10/10
  3. ;; Codehimbelonga kdub@theSwamp 2014/10/08
  4.  
  5. (defun remstamp (blknames / blkname)
  6.   (setq exprt (getvar "expert"))
  7.   (setvar "EXPERT" 5)
  8.   (command "-layer" "set" "0" "")
  9.   (command "Zoom" "All")
  10.   ;;
  11.   (if
  12.     (setq ss (ssget "X" (list '(0 . "INSERT") (cons 2  blknames))))
  13.      (while (setq block (ssname ss 0))
  14.        (vla-delete (vlax-ename->vla-object block))
  15.        (ssdel block ss)
  16.      )
  17.   )
  18.  
  19.   (vl-cmdf "_.Audit" "Y")
  20.   (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  21.   (setvar "EXPERT" exprt)
  22.   (command "QSAVE")
  23.   (princ)
  24. )
  25.  
  26.  


Code - Auto/Visual Lisp: [Select]
  1. ;;;;; RemStamp-01.scr
  2. (LOAD "P:\\DWells\\LSP\\REMOVE_Block\\REMSTAMP.lsp")
  3. (RemStamp "FORCONSTRUCTION,DEMOLITION")
  4.  

Code - Auto/Visual Lisp: [Select]
  1. ;;;;; RemStamp-02.scr
  2. (LOAD "P:\\DWells\\LSP\\REMOVE_Block\\REMSTAMP.lsp")
  3. (RemStamp "CONSTRUCTION,DEMOLITION")
  4.  

Code - Auto/Visual Lisp: [Select]
  1. ;;;;; RemStamp-03.scr
  2. (LOAD "P:\\DWells\\LSP\\REMOVE_Block\\REMSTAMP.lsp")
  3. (RemStamp "FORCONSTRUCTION,SPECIALNOTES")
  4.  

Code - Auto/Visual Lisp: [Select]
  1. ;;;;; RemStamp-04.scr
  2. (LOAD "P:\\DWells\\LSP\\REMOVE_Block\\REMSTAMP.lsp")
  3. (RemStamp "HOLDFORINFORMATION,SPECIALNOTES,REVIEWSTAMP")
  4.  

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need a script to delete a specific block in PaperSpace
« Reply #20 on: October 09, 2014, 07:10:46 PM »
Just for info, I've used this to update/revise a block in multiple drawings, via ScriptPro.
Particularly handy when 'someone' misspells something in a block that is inserted into hundreds of drawings.

Code - Auto/Visual Lisp: [Select]
  1. ;;(updateReviewStamp "FORREVIEW" "FORCONSTRUCTION")
  2. ;; Rev 2011.08.07
  3.  
  4. (defun updateReviewStamp (oldBlock newBlock)
  5.   (setq exprt (getvar "expert"))
  6.   (setvar "EXPERT" 5)
  7.   (command "-layer" "set" "0" "")
  8.   (command "Zoom" "All")
  9.   (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  10.   ;;
  11.   (if (setq ss (ssget "X" (list '(0 . "INSERT") (cons 2  oldBlock))))
  12.         (progn
  13.           (vl-cmdf "_.rename"
  14.                            "block"
  15.                            oldBlock
  16.                            newBlock
  17.           )
  18.           (vl-cmdf
  19.                   "_.Insert"
  20.             (strcat newBlock "=P:\\ProjBlocks\\" newBlock ".dwg")
  21.                 (list 0. 0. 0.)
  22.                 1
  23.                 1
  24.                 0
  25.           )
  26.           (vl-cmdf "_erase" (entlast) "")        
  27.         )
  28.   )
  29.   (vl-cmdf "_.Audit" "Y")
  30.   (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  31.   (setvar "EXPERT" exprt)
  32.   (command "QSAVE")
  33.   (princ)
  34. )
  35.  
  36.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Need a script to delete a specific block in PaperSpace
« Reply #21 on: October 09, 2014, 08:34:04 PM »
This seems to be work'n.   Thanks Everyone..


 :wink:
I am very  trainable....   (forgive my spelling)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need a script to delete a specific block in PaperSpace
« Reply #22 on: October 09, 2014, 10:46:28 PM »
You have to supply the block names .. like so:
Quote
(remstamp "REMBLOCK,FORCONSTRUCTION")

Sorry Ron I thought you were talking about my code.
I'm slipping, need more sleep. :(
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Need a script to delete a specific block in PaperSpace
« Reply #23 on: October 10, 2014, 08:48:34 AM »
You have to supply the block names .. like so:
Quote
(remstamp "REMBLOCK,FORCONSTRUCTION")

Sorry Ron I thought you were talking about my code.
I'm slipping, need more sleep. :(
No worries Charles  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC