Lisp Command to purge and save as dwg to specific location

Lisp Command to purge and save as dwg to specific location

Anonymous
Not applicable
2,710 Views
12 Replies
Message 1 of 13

Lisp Command to purge and save as dwg to specific location

Anonymous
Not applicable

I have the following code, on the last line, I'm trying to figure out how to make the drawing save as to a specific location. It will use its' current drawing name. Any help would be appreciated. 

 

(defun c:test ()

(command "_.purge" "_all" "*" "_no"
"_.setbylayer" "_all" "" "_yes" "_yes"
"_.layer" "_color" "253" "*" ""
"_.audit" "_yes"
"_.saveas" "2013" "S:\ENGINEERING\JOBS\16-006 GM Ramos\DRAWINGS\GK\GK XREF\" "Here is where I think I can tell it to use its current dwg name")

)

0 Likes
Accepted solutions (1)
2,711 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

Try this:

 

(defun c:test nil
  (command "_.Purge" "_All" "*" "_No"
	   "_.Setbylayer" "_All" "" "_Yes" "_Yes"
	   "_.Layer" "_Color" 253 "*" ""
	   "_.Audit" "_Yes")
  (command "_SAVE" (strcat "File Location" (getvar "dwgname")))
  (princ)
  )

 

 

0 Likes
Message 3 of 13

Anonymous
Not applicable

This works great. In the event that I have to overwrite an existing file name, I will have to answer "Yes" somewhere. I just found one where it is asking yes or no. Is that easy to add? I tried it in a few places, it didn't work. 

0 Likes
Message 4 of 13

Anonymous
Not applicable

@Anonymous

Specify your question a bit better, add a picture

 

 

 

 

0 Likes
Message 5 of 13

Anonymous
Not applicable

@cdebolt1984

 

 

 

0 Likes
Message 6 of 13

Anonymous
Not applicable

I want to answer yes to this.

0 Likes
Message 7 of 13

Anonymous
Not applicable

@Anonymous

Are you using Saveas?

yes, if you need it:

(defun c:test nil
  
  (command "_.Purge" "_All" "*" "_No"
	   "_.Setbylayer" "_All" "" "_Yes" "_Yes"
	   "_.Layer" "_Color" 253 "*" ""
	   "_.Audit" "_Yes")
  
  (command "_.SAVEAS" "2013" (strcat "C:\\File Location\\" (getvar "dwgname")) "_Yes")
(princ) )
0 Likes
Message 8 of 13

Anonymous
Not applicable

This was working, now I'm getting this message. I'm not sure why. Here is the exact code I'm trying. Double check my directory hashes... you guys were showing a different amount, also, I've seen a lot of people use forward slashes for the directory, does this matter???

 

(defun c:test nil

(command "_.Purge" "_All" "*" "_No"
"_.Setbylayer" "_All" "" "_Yes" "_Yes"
"_.Layer" "_Color" 253 "*" ""
"_.Audit" "_Yes")

(command "_.SAVEAS" "2013" (strcat "\\universal-5010\S\ENGINEERING\JOBS\16-006 GM Ramos\DRAWINGS\GK\GK XREF\" (getvar "dwgname")) "_Yes")
(princ)
)

0 Likes
Message 9 of 13

Anonymous
Not applicable

Would it be this?

 

(command "_.SAVEAS" "2013" (strcat "\\universal-5010\\S\\ENGINEERING\\JOBS\\16-006 GM Ramos\\DRAWINGS\\GK\\GK XREF\\" (getvar "dwgname")) "_Yes")

 

 

0 Likes
Message 10 of 13

Anonymous
Not applicable

It is naming the drawing, yes.dwg. Please see attached command prompt, here is my latest code. so, close. 

 

(defun c:test nil
(command "_.Purge" "_All" "*" "_No"
"_.-purge" "_R" "_All" "_No"
"_.Setbylayer" "_All" "" "_Yes" "_Yes"
"_.Layer" "_Color" 253 "*" ""
"_.Audit" "_Yes")

(command "_.SAVEAS" "2013" (strcat "\\universal-5010\\S\\ENGINEERING\\JOBS\\16-006 GM Ramos\\DRAWINGS\\GK\\GK XREF\\" (getvar "dwgname")) "_Yes")
(princ)
)

0 Likes
Message 11 of 13

Anonymous
Not applicable

Make sure the location of your file is correct.
if possible attach a photo with the detailed location.

 

 

(Command "_.SaveAS" "2013" (strcat "C:\\universal-5010\\S\\ENGINEERING\\JOBS\\16-006 GM Ramos\\DRAWINGS\\GK\\GK XREF\\" (getvar "dwgname")) "_Yes")

 

 

 

 

0 Likes
Message 12 of 13

roland.r71
Collaborator
Collaborator

You'll have to build in a check to add the "_Y" when needed (and only then) otherwise the command will try to answer a question never asked. Messing up your "batch flow" (As that will get you errors)

 

Check if the file exists, if so, add "_Y" to your command arguments.

 

Example:

(setq filename (strcat "c:/Path/To/" (getvar "dwgname")))
(if (findfile filename)                      ; if the file exists
   (command "_.SAVEAS" "2013" filename "_Y") ; add "yes" for overwrite
   (command "_.SAVEAS" "2013" filename)      ; add nothing
)
0 Likes
Message 13 of 13

roland.r71
Collaborator
Collaborator
Accepted solution

@Anonymous wrote:

It is naming the drawing, yes.dwg. Please see attached command prompt, here is my latest code. so, close. 

 

(defun c:test nil
(command "_.Purge" "_All" "*" "_No"
"_.-purge" "_R" "_All" "_No"
"_.Setbylayer" "_All" "" "_Yes" "_Yes"
"_.Layer" "_Color" 253 "*" ""
"_.Audit" "_Yes")

(command "_.SAVEAS" "2013" (strcat "\\universal-5010\\S\\ENGINEERING\\JOBS\\16-006 GM Ramos\\DRAWINGS\\GK\\GK XREF\\" (getvar "dwgname")) "_Yes")
(princ)
)


Your path is incomplete.

There should be a drive letter in front of it, or if its a network path there should be 2 more backslashes.

 

C:\\universal-5010\\S\\ -or- C:/universal-5010/S/ or 😧 E: F: etc.

\\\\universal-5010\\S\\ -or- //universal-5010/S/

0 Likes