Drawing Clean-up Script

Drawing Clean-up Script

Crass
Collaborator Collaborator
395 Views
8 Replies
Message 1 of 9

Drawing Clean-up Script

Crass
Collaborator
Collaborator

Hi. This is not my strong suit, but I am trying to make a script (.scr) that will "clean" incoming consultant drawings such as architectural floor plans in one click instead of multiple steps. It will be executed through a button in tool palettes. This is what I have so far:

 

-LAYOUT
D

-LAYOUT
D

XREFDETACH
ALL

-IMAGE
D
SETBYLAYER
AUDIT
Y
-PURGE
A
N

 

My question is three-fold:

  1. SETBYLAYER doesn't work because it has a few prompts that I don't know how to handle. Essentially I want to select all and apply to blocks or whatever the default is on that choice
  2. Generally, is there anything else you would do to clean this up
  3. Any other commands you would add? 

Thanks!

 

-----
AutoCAD 2018/2021
AutoCAD Civil 3D 2021
0 Likes
Accepted solutions (2)
396 Views
8 Replies
Replies (8)
Message 2 of 9

DGCSCAD
Advisor
Advisor
Accepted solution

You could put that into a LISP function, which has a bit more flexibility:

 

(defun c:dwg_cleanup ( / sbl_sv ss i ent)
(vl-load-com)

;;;; Audit the drawing first
(command "_.AUDIT" "_Y")

;;;; Delete 2 layouts
(repeat 2 (command "-layout" "d" pause))

;;;; If there are images, delete them
(if (setq ss (ssget "X" '((0 . "IMAGE"))))
	(progn
		(setq i (sslength ss))
		(while (> i 0)
			(setq ent (ssname ss (setq i (1- i))))
			(entdel ent)
		)
		(princ (strcat "\nErased " (itoa (sslength ss)) " image instances."))
    	)
	(princ "\nNo image instances found in drawing.")
)
(command "-image" "d" "*")

;;;; Purge the drawing to get rid of instances
(repeat 3 (command "_.PURGE" "_A" "" "_N"))

;;;; Set all remaining objects to ByLayer
(setq sbl_sv (getvar "SETBYLAYERMODE"))
(setvar "SETBYLAYERMODE" 255)
(command "-setbylayer" "all" "" "y" "y")
(setvar "SETBYLAYERMODE" sbl_sv)

(princ)
)

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 3 of 9

Crass
Collaborator
Collaborator

Hi @DGCSCAD - Thank you for the suggestion and maybe that does make the most sense. My only hesitation would be that everyone in the company would need to have that LISP loaded for the button to work. We currently don't set up a standard company profile though this is probably another reason to go that route. What would you recommend for the most friction-less way to deploy something like this company-wide?

-----
AutoCAD 2018/2021
AutoCAD Civil 3D 2021
0 Likes
Message 4 of 9

DGCSCAD
Advisor
Advisor
Accepted solution

Take a look at how to create and use an acaddoc.lsp and how to set up company wide deployments. You'll need to create a folder structure, and then set your SFSP's to match that. You'll open up a new world of possibilities.

 

Until then, you could use this approach:

  • Create a folder that can be accessed by all (for demo purposes, I'll use S:\AutoCad_Support\LISP).
  • Save dwg_cleanup.lsp to that folder.
  • *Optional: In Acad, set a Trusted Path (Options->Files->Trusted Locations) to that folder.
  • Put this in a Command Button: ^C^C(load"S:\\AutoCad_Support\\LISP\\dwg_cleanup");dwg_cleanup

*The Trusted Locations popup should only fire once if you tell it to Always Load.

 

AutoCad 2018 (full)
Win 11 Pro
Message 5 of 9

paullimapa
Mentor
Mentor

Questions:

1) Are there specific layouts names that you want to delete or do you just want to delete all layouts?

2) As for Setbylayer following these SetbylayerMode settings:

paullimapa_0-1785785640507.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 9

Crass
Collaborator
Collaborator

Hi @DGCSCAD - I appreciate the response(s).

 


@DGCSCAD wrote:

Take a look at how to create and use an acaddoc.lsp and how to set up company wide deployments. You'll need to create a folder structure, and then set your SFSP's to match that. You'll open up a new world of possibilities.

Do you know of any resources (training videos, forum threads, white papers, etc.) that walks you through this? I can do some internet searching on my own as well. 

 


@DGCSCAD wrote:

Until then, you could use this approach:

  • Create a folder that can be accessed by all (for demo purposes, I'll use S:\AutoCad_Support\LISP).
  • Save dwg_cleanup.lsp to that folder.
  • *Optional: In Acad, set a Trusted Path (Options->Files->Trusted Locations) to that folder.
  • Put this in a Command Button: ^C^C(load"S:\\AutoCad_Support\\LISP\\dwg_cleanup");dwg_cleanup

*The Trusted Locations popup should only fire once if you tell it to Always Load.

 


With this method, would the dwg_cleanup.lsp file need to be in the Startup Suite of APPLOAD? It would be fine either way. We are not a huge company. I'm just trying to understand if I'd need to set this up individually on each machine.

-----
AutoCAD 2018/2021
AutoCAD Civil 3D 2021
0 Likes
Message 7 of 9

Sea-Haven
Mentor
Mentor

Just my $0.05 I dont use acaddoc.lsp rather custom lisp programs loaded on startup via the Appload command. Inside the custom lisp is many useful defuns used on a daily basis, it has Autoload function that load a lisp on demand by typing a command name.

 

For me I am old fashioned and use POP menu's these are simple to maintain and can be made and edited in Notepad. This one has 130 lisps behind it.

 

SeaHaven_0-1785816587615.png

You can also make your own Ribbon menus but have to use the CUI option for that.

 

Re install on multiple pc's, two scenarios local and server.

Server

The server is much simpler as all programs menu's, blocks std dwg's are saved on the server. When you make a change to a menu add programs etc, the next time CAD is opened the new features are there straight away.

 

Local

Copy all the programs, menus, std dwg's etc to a local drive. A little harder to manage as each pc must be upgraded. Ok good news there is various ways to install software onto a local PC. For my clients I have used Install.lsp and a zip file that contains all prementioned items, the lisp is ran and the zip file is automatically unzipped to a known directory, "C:\cad-tools" or your name, support paths added, new menus added or reloaded. I am happy to provide the example of this method. The end user is emailed the two files save the zip to say downloads. Then just run the install.lsp it auto unzips to correct directory

 

As the startup program list is saved in a appload.dfs file on the local drive under C:\users......... I am looking at adding that also to the install.lsp.

0 Likes
Message 8 of 9

DGCSCAD
Advisor
Advisor

@Crass wrote:

Do you know of any resources (training videos, forum threads, white papers, etc.) that walks you through this? I can do some internet searching on my own as well. 


There are some out there but I'd have to search as well.

 

One method I use is to create a LISP function/file (I'll call it the Initialization.lsp file) stored in a network folder that users can drag/drop onto an open AutoCad drawing, which only needs to happen once.

 

Setting up the folder structure first is key, with folders named such as LISP, Blocks, Data, etc., then the Initialization.lsp LISP function sets the Support File Search Paths and Trusted Paths to those folders. Within that folder structure is an acaddoc.lsp file that loads and sets all necessary functionality when each drawing is opened.

 

By default, when AutoCad opens each drawing it looks for an acaddoc.lsp, then loads the contents of that file into the drawing at startup. Setting the SFSP's and having that acaddoc.lsp located within that folder structure ensures that every user that has drag/dropped the Initialization.lsp file into an open drawing has the same environment and functionality.

 

A good resource and starting point would be here: https://www.lee-mac.com/envvarfunctions.html

 


@Crass wrote:

With this method, would the dwg_cleanup.lsp file need to be in the Startup Suite of APPLOAD? It would be fine either way. We are not a huge company. I'm just trying to understand if I'd need to set this up individually on each machine.


No, it doesn't have to be in the Startup Suite, it just needs to reside in the folder specified in the text string "S:\\AutoCad_Support\\LISP\\dwg_cleanup" (notice the use of double back slashes. Thats so LISP can read the back slashes literally, otherwise a back slash gets treated as a control character).

 

Hard coding the path ensures that it gets loaded before calling the function. The LISP string could be adjusted to check and see if the dwg_cleanup.lsp is already loaded, but it's a minimal impact so not absolutely necessary.

 

If each user has that button on a Tool Palette and access to the folder specified, then that's all you need to do.

AutoCad 2018 (full)
Win 11 Pro
Message 9 of 9

lauri_barnhart
Autodesk
Autodesk

Hello, @Crass.

 

Hope you are well. Just checking in to see if any of the replies provided the information you need to resolve your issue. If any post(s) provided the information you needed, please consider clicking on the 'Accept Solution' button. If you still have questions and need assistance, please provide an update here.

 

Thanks,


Lauri | Community Manager
0 Likes