AutoCAD script for updating an Attribute in a block

AutoCAD script for updating an Attribute in a block

francesca_boothCE7KE
Explorer Explorer
509 Views
30 Replies
Message 1 of 31

AutoCAD script for updating an Attribute in a block

francesca_boothCE7KE
Explorer
Explorer

So I've written a pythod code that sets out what I assumed would be the correct script layout for AutoCAD.

 

I've run into an issue on the Open command in AutoCAD 2025. I've changed my FILDEA from 1 to 0 and 0 back to 1 to see if that would change anything but it doesn't. When the script tries to run the OPEN command it's just stalls on either the popup or saying I need to press entre to confirm docuemtn that I want to open which in turn kind of cancelles the script.

 

I've even tried changing the open to -open.

0 Likes
510 Views
30 Replies
Replies (30)
Message 2 of 31

Moshe-A
Mentor
Mentor

@francesca_boothCE7KE hi,

 

First a script file must have .scr file type

Second an empty line (in script format) mean pressing enter on keyboard. 

so if you use for example TEXT in script, to end text we need enter? there you leave empty line

script does not use FILEDIA cause it does not stop to get input. all the inputs need to run the script smoothly must exist in the script otherwise it will stop working.

 

does this help you?

 

Moshe

 

0 Likes
Message 3 of 31

francesca_boothCE7KE
Explorer
Explorer

Hi,

 

My script is a .scr file, I could only load the .txt as this didn't allow me to load my script file, don't ask me why.

 

With the empty line situation are you stating that my script should end up looking something like below?

 

The only reason why I was messing with FILDEA was because it was previous opening the popup for me to search for the location of the file, and then I turned it off to get rid of the popup which it then just left me with the please press entre to say yes to open, and if I did press enter it opened the drawing but wouldn't continue with the -attedit and below.

 

'OPEN
"-file location-"

<this is an empty line for enter>

-ATTEDIT
N
N
TL_LINE08
SHEET 100 OF 502
QSAVE
CLOSE'

0 Likes
Message 4 of 31

paullimapa
Mentor
Mentor

You should be able to drag and drop this script file onto Autocads drawing area or enter command Script and then select this script file to run. But instead of these two lines:

"-file location-"
<this is an empty line for enter>

 You’ll just need path and name of dwg

"-file location-"

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

francesca_boothCE7KE
Explorer
Explorer

I meant here in the forum I couldn't drag my script file in as a .Scr. I either drag and drop into CAD or use the run script.

 

What I currently have is just "-file location-" as a line after the Open. For some reason when I've updated to 2025, it's doing this prompt to search for my file location when I've given it the location and command to open. 

0 Likes
Message 6 of 31

Moshe-A
Mentor
Mentor

@francesca_boothCE7KE 

 

i can not test if your script is running right now

 

to post here files as SCR try to zip it.

 

With the empty line situation are you stating that my script should end up looking something like below?

NO i did not say that, what i said where an enter key is needed, you should leave empty line.

and open command does not need it.

in script format every character has a meaning. a space is the same as pressing spacebar. 2 spaces is like pressing spacebar twice.

 

i recommend putting CLOSE command in comment (or remove it) for the duration of debugging and only when you see a success finish, restore it.

 

Moshe

 

 

0 Likes
Message 7 of 31

paullimapa
Mentor
Mentor

Yes, I knew what you meant. I just wanted to make sure you're aware of the methods to launch a script file from within AutoCAD.

Perhaps a 3rd party app might have redefined your OPEN command?

Try replacing in your script:

OPEN

with underscore & period before command like this:

_.OPEN

 

 


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

francesca_boothCE7KE
Explorer
Explorer

Hi Paul,

I tried changing the open ot _.open, see snip of updated script line below. I've added a screen shot as well to show the what is happening in the command line as well as the pop-up that's started opening again.

 

_.OPEN
"C:\Users\francesca.booth.WLP\Waterline Projects\Projects 2022 - Oyu Tolgoi 211091 Engineering Backdrafting Design\A. Drawings\1833\Ready for QA\1833-65-E2-1702\1833-65-E2-1702_2 Sh100of502.dwg"
-ATTEDIT
N
N
TL_LINE08
SHEET 100 OF 502
QSAVE

0 Likes
Message 9 of 31

francesca_boothCE7KE
Explorer
Explorer

Sorry if that's not what you meant, I didn't read it like that, but thank you for explaining it to me further.

0 Likes
Message 10 of 31

paullimapa
Mentor
Mentor

As a test I would first simplify by opening a drawing that is on your C: drive and with a shorter path.

For example create a drawing directly under Documents folder call it Test.dwg and then place this path+dwg name in the script file to see if it now opens up that drawing.


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

paullimapa
Mentor
Mentor

Also notice the sequence of the Attedit command prompt.

Assuming you want to find & replace the following:

Attribute TAG: SHEET

Current value: 100 OF 502

String to change: 502

Replace with: 503

Then this is what it would look like:

Command: -ATTEDIT
Edit attributes one at a time? [Yes/No] <Y>: N
Performing global editing of attribute values.
Edit only attributes visible on screen? [Yes/No] <Y>: N
Drawing must be regenerated afterwards.
Enter block name specification <*>: TL_LINE08
Enter attribute tag specification <*>: SHEET
Enter attribute value specification <*>: 100 OF 502
1 attributes selected.
Enter string to change: 502
Enter new string: 503

This is the script file that opens a sample dwg I saved under folder: Downloads and with file name: A-01.dwg that executes the above sequence (at the end with Qsave instead of Close)

_.Open
"C:\Users\PauLpc\Downloads\A-01.dwg"
-ATTEDIT
N
N
TL_LINE08
SHEET
100 OF 502
502
503
_.Qsave
; Script Ends

 


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

francesca_boothCE7KE
Explorer
Explorer

Hi Paul,

The issue still seems to be with the open command, I can do the attedit fine if I copy that directly into the command line when I manually open the drawing. Trying to have AutoCAD open the drawings by itself to then apply the attedit, it needs me to select the drawing I want open it, but like I stated before it then doesn't run the rest of the script on the now opened drawing.

0 Likes
Message 13 of 31

paullimapa
Mentor
Mentor

Do you have latest 2025 updates installed?

Enter About command do a screenshot and share that here


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

francesca_boothCE7KE
Explorer
Explorer

francesca_boothCE7KE_0-1756856581280.png

 

0 Likes
Message 15 of 31

paullimapa
Mentor
Mentor

You are behind by one update. You may try installing that to see if it makes a difference

https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/How-to-tie-the-Pro...

The other thing to try would be another computer or install 2024 to test 


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

francesca_boothCE7KE
Explorer
Explorer

ok I'll give both options a go and see how that works.

0 Likes
Message 17 of 31

paullimapa
Mentor
Mentor

Another thing to try incase a third party app is running intercepting commands is to start AutoCAD in safemode 

How to start an AutoCAD Product with a minimum of plug-ins or add-ons

 


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

paullimapa
Mentor
Mentor

And yet another option...use accoreconsole.exe which bypasses the AutoCAD graphics window completely by running in a dos command window.

read up on it here: Son of a Batch! AutoCAD Core Console Through Lisp | House of BIM

I've attached a sample command batch file which opens from Downloads folder drawing file name: A-01.dwgand runs script file called Open.scr

paullimapa_0-1756864103386.png

paullimapa_1-1756865146975.png

 


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

Sea-Haven
Mentor
Mentor

I seem to remember something about opening a file with a long directory. maybe try this method you can run lisp in a script. note the dbl backslash. Maybe try the forward slash.

 

(setq blkname (setq blkname "C:\\Users\\francesca.booth.WLP\\Waterline Projects\\Projects 2022 - Oyu Tolgoi 211091 Engineering Backdrafting Design\\A. Drawings\\1833\\Ready for QA\\1833-65-E2-1702\\1833-65-E2-1702_2 Sh100of502.dwg")
)
(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(vla-activate (vla-open acDocs blkname))

  

just a comment you can Map a drive so your super long path could be just X:, pick a drive letter not being used.

 

Type CMD lower left in windows, then.

subst X: "C:\Users\francesca.booth.WLP\Waterline Projects\Projects 2022 - Oyu Tolgoi 211091 Engineering Backdrafting Design\A. Drawings\1833"

You now have a X: drive hopefully will work with your script. 

You can work out how deep you want the drive to be.

0 Likes
Message 20 of 31

francesca_boothCE7KE
Explorer
Explorer

with this trial of using a new drive to actually be the location in sharepoint, would everyone who needs to do something similar to me (not always the same folder location) have to do the same thing to be able to run the lisp?

0 Likes