LISP to modify content (Title block) of DWG in batch

LISP to modify content (Title block) of DWG in batch

zirudezirude
Advocate Advocate
1,542 Views
15 Replies
Message 1 of 16

LISP to modify content (Title block) of DWG in batch

zirudezirude
Advocate
Advocate

Hi Guys,

 

I put together this script in order to change the content of the title block (ATT texts) of multiple drawings, 

So After trying to execute it, it returns this note:

"error: Automation Error. Method not available in MDI mode. Use Open method of Documents collection."

However after changing the SDI to 1 it did not work.

 

Can someone take a look at it please? 

 

*I attached two variants one to place the path within the Lisp and the other should browse for folder using a browser for folder lisp.

 

Any effort would be appreciated.

0 Likes
Accepted solutions (1)
1,543 Views
15 Replies
Replies (15)
Message 2 of 16

paullimapa
Mentor
Mentor

can't use vla-open method

but could try odbx or autocad core console method


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

DGCSCAD
Collaborator
Collaborator

Hello  zirudezirude,

 

I've had success with batch processing using this small bit of code. I've updated it to process your "1Modify DWG Title Blcok Content+Browse for Folder" lisp

 

 

;batch_anything.lsp
;Description:	Batch Process
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;start prog

(DEFUN C:batch_anything ()

;;;;;;;;;;;;;;;;;;;;;;;;;Select directory to be processed

	(setq dfil (getfiled "Select A File In The Directory You Want To Batch Process" "c:/" "dwg" 0));;;;This uses C:/ directory. Change for your use.
	(setq wutdir (vl-filename-directory dfil))
	(setq wutfiles (vl-directory-files wutdir "*.dwg"))

	(setq scrfile (open "c:\\scrfile.scr" "w"))
	(close scrfile)
	(setq scrfile (open "c:\\scrfile.scr" "a"))

(foreach n wutfiles
	(setq n2 (strcat "\""wutdir "\\" n "\""))
	(setq n2 (vl-string-translate "\\" "\\" n2))
	(setq scrline (strcat "open" " " n2 " " "(load\"1Modify DWG Title Blcok Content+Browse for Folder\")" " " "ModifyTitleBlock1" " " "qsave" " " "close"));;;;;;;COMMANDS FOR BATCH GO HERE
	(write-line scrline scrfile)
	(princ)
)
	(close scrfile)
(command "script" "c:\\scrfile")
(princ "\n***Batch complete.***")
(princ)
);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEFUN

 

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 4 of 16

zirudezirude
Advocate
Advocate

I am not good at lisp, 

Where did I use val-open?

Can you elaborate the other methods please or integrate them into the one I attached.

0 Likes
Message 5 of 16

zirudezirude
Advocate
Advocate

I uploaded the one you provide now beside the one I attached as is but it returns the same error:

error: Automation Error. Method not available in MDI mode. Use Open method of Documents collection.

0 Likes
Message 6 of 16

paullimapa
Mentor
Mentor

***Update:

I modified lisp to include code (strcase) function so all attribute tags converts to uppercase to properly check for match

And if you do use Lee Mac's Script Writer then the Script Line should be:

_.Open *file* (load"ModifyTitleBlock1") ModifyTitleBlock1 _.QSAVE _.CLOSE

***

I've included modified lisp that works on a single dwg.

You'll need to save this lisp in a location that is in Autocad Trusted folder location and in support path.

I've also included a script file that loads the lisp & runs the commands to update the attributes.

Now you'll just need to run an app like Lee Mac's which can apply a script file to all dwgs in a single folder:

http://www.lee-mac.com/scriptwriter.html


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

paullimapa
Mentor
Mentor

This is even easier without having to install anything else.

Just load the attached DwgModBlkTtl.lsp and then run it.

It'll ask for folder location to process all drawings under that folder (subfolders not supported).

DwgModBlkTtl opens dwgs using ODBX so you won't see any drawings actually opened on the screen.

After DwgModBlkTtl finishes, the folder will open in Explorer for you to review all drawings modified.

 


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

zirudezirude
Advocate
Advocate

thanks @paullimapa for the help

 

Did you set it up for one DWG and its layouts?

 

So I am looking for an update that modify a batch of drawings (in their folder at once)

even the one you changed after I ran it only two inputs that have uppercase ATT have changed. 

 

So would you please integrate both the batch option, non case sensitive and the LM:browseforfolder (attached) . 

 

Thanks

 

0 Likes
Message 9 of 16

paullimapa
Mentor
Mentor

Did you try the ODBX lisp version in my most recent post which takes care of multiple dwgs in the same folder?

As for why only 2 attributes are changed, perhaps you can share your title block with the attributes then I can run tests from my end


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

zirudezirude
Advocate
Advocate

would you please send over to a copy of ODBX?  I never seen it

0 Likes
Message 11 of 16

paullimapa
Mentor
Mentor
0 Likes
Message 12 of 16

zirudezirude
Advocate
Advocate

Thanks for the help @paullimapa 

 

I ran it as is, so only 3 inputs were populated (start with "New")

also some of the inputs (like project name, Line number, Scale ) that set up in the project setup were ignored by the lisp.

0 Likes
Message 13 of 16

zirudezirude
Advocate
Advocate

Here is the ATT background of the title block

zirudezirude_0-1694730962248.png

 

0 Likes
Message 14 of 16

paullimapa
Mentor
Mentor
Accepted solution

Now that you've provided me with the Title Block showing the Attributes I can properly set the Attribute Tag names.

Typically Attribute Tag names are created in all in caps. But in your case they weren't. So I just revised the code so that the Attribute Tags are as you've originally inputted them in the code. Now when the code runs all the Attribute values update. If you do add more, just again match the case as you have them:

paullimapa_0-1694733127533.png

FYI: Your Title Block currently does NOT have an Attribute TAG matching N.T.S.

Instead this is currently placed in the Block as Text:

paullimapa_0-1694732668972.png

 


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

zirudezirude
Advocate
Advocate


@paullimapa you're brilliant Guy thanks a lot 👍

0 Likes
Message 16 of 16

paullimapa
Mentor
Mentor

glad to have helped...cheers!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes