Create a LISP to save current drawing with appended revision to the end of the file

Create a LISP to save current drawing with appended revision to the end of the file

logan_ownbey5UKQZ
Contributor Contributor
3,526 Views
31 Replies
Message 1 of 32

Create a LISP to save current drawing with appended revision to the end of the file

logan_ownbey5UKQZ
Contributor
Contributor

Hello,

 

I am trying to create a lisp file that when used will take the current drawing file (xxxx-xxxx) and ask for what revision in a pop-up window. It will then append the revision to the end of the name with -revision. I would like it to save to the current folder. Once saved it will then open the new drawing. 

 

The issue i am running into is, if the file has already been Rev'd i would like for it to replace it with the new revision that is entered in the pop up, overwrite the current revision at the end of the name and save it and open it.

I was using chatgpt to create this and it got pretty close expect for the renaming the -revision with the updated name. not sure how to make that part work.

0 Likes
Accepted solutions (2)
3,527 Views
31 Replies
Replies (31)
Message 21 of 32

logan_ownbey5UKQZ
Contributor
Contributor

I should have mention that the title block is xref'd and the text is an attribute block. We use layout for our xref title block and attribute block.

 

It saves to the folder but it is not seeing the title block/attributes.

0 Likes
Message 22 of 32

paullimapa
Mentor
Mentor

If the Block containing the Attributes is inside the Xref then this cannot be retrieved.

What I've done to make it so I can modify the Block Attributes is to xref the Title Block only and then Insert the Block with the Attributes on top of the Title Block. Then those Attributes can be modified and retrieved because they're now separate from the xref.

Also since you mention xrefs, if you're using Relative Paths for any references that includes dwg, pdf, dwf, dgn & various image types, saving or in this case copying the dwg file to a subfolder like "01" will prevent AutoCAD from finding those xrefs


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

logan_ownbey5UKQZ
Contributor
Contributor

The title block is the only xref'd part. Attribute block is a separate part and is not xref'd.

 

When i call out the attribute, do i need to include the block that the attribute resides in?

 

See image below.

logan_ownbey5UKQZ_0-1710964758102.png

 

0 Likes
Message 24 of 32

logan_ownbey5UKQZ
Contributor
Contributor

logan_ownbey5UKQZ_0-1710965233112.png

This is what I have put into those spots. I am now getting this error.

 

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:
Command: SAVEASR
; error: too many arguments

0 Likes
Message 25 of 32

paullimapa
Mentor
Mentor

yes, that's how the lisp code can first find the Block based on its Name and then locate the Attribute based on its Tag

paullimapa_1-1710964987108.png

FYI: If you deal with more than just referencing the title blocks then to truly capture a version of the current drawing I recommend the eTransmit command. This can collect everything including xrefs and place all into a zip file. You can add to the name the current date and save the zip file where ever you want. Actually, you can even unzip the entire contents into a folder named with today's date including revision number info. Then when AutoCAD cannot locate the relative path references it'll automatically search & find them in the today's date folder (because it's the current folder). You may also want to generate a PDF of the dwg and save this in the same folder as well.  This then would be more of a complete capture of the current drawing revision which you can go back to in the future to review.


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

paullimapa
Mentor
Mentor

Share a sample of your dwg with that Block Attribute for me to test on my end.


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

logan_ownbey5UKQZ
Contributor
Contributor

See attached

0 Likes
Message 28 of 32

paullimapa
Mentor
Mentor

I made more revisions so try this version.

I also incorporated your Block name & Attribute Tag into the code.

 (setq currentFileNameOnly (vl-filename-base (getvar "DWGNAME"))
       currentFileNamelen  (strlen currentFileNameOnly)
       currentFilePath     (getvar "DWGPREFIX")
       subfolderName       "01"                         ; name of subfolder versions are saved
       titleblockName      "MIRON_TITLEBLOCK"           ; change this to user title block name
       attributetagName    "REV"                        ; change this to user attribute tag name containing revision letter
       revisionFilePath    (strcat currentFilePath subfolderName "\\") ; entire subfolder version path
 )

FYI: If REV shows a period "." and your response to the prompt is a letter like "A", though the file name will show "A" the Block Attribute will not be changed. 


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

logan_ownbey5UKQZ
Contributor
Contributor

That worked except for the fact that when the Letter changes the first number does not restart at 1.

So like it is seeing the title block being rev'd up to the next level, but it is putting the previous major change number in front still, it needs to restart back at 1 whenever a rev has been put through.

 

Also, i would not like for them to change the sequential number. I don't think it should prompt that part.

0 Likes
Message 30 of 32

paullimapa
Mentor
Mentor
Accepted solution

ok incorporated those revisions now use the attached updated version.


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

logan_ownbey5UKQZ
Contributor
Contributor

Awesome! Works perfect! Thank you very much.

0 Likes
Message 32 of 32

paullimapa
Mentor
Mentor

Glad this is finally working out for you...but remember my caveat in my reply #25 post:

@paullimapa wrote:

FYI: If you deal with more than just referencing the title blocks then to truly capture a version of the current drawing I recommend the eTransmit command. This can collect everything including xrefs and place all into a zip file. You can add to the name the current date and save the zip file where ever you want. Actually, you can even unzip the entire contents into a folder named with today's date including revision number info. Then when AutoCAD cannot locate the relative path references it'll automatically search & find them in the today's date folder (because it's the current folder). You may also want to generate a PDF of the dwg and save this in the same folder as well.  This then would be more of a complete capture of the current drawing revision which you can go back to in the future to review.


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