"Rename"/ "save as" drawing at the end of a lisp

"Rename"/ "save as" drawing at the end of a lisp

Sandervp
Advocate Advocate
1,246 Views
3 Replies
Message 1 of 4

"Rename"/ "save as" drawing at the end of a lisp

Sandervp
Advocate
Advocate

Hello everybody,

 

I've got a lisp file (see clean up lisp). I want to add something at the end of this lisp that what will save this drawing as "XREF - drawing name".

 

Drawing 1 becomes xref-drawing 1, drawing 2 becomes xref-drawing 2, etc.

 

Is this possible?

0 Likes
Accepted solutions (1)
1,247 Views
3 Replies
Replies (3)
Message 2 of 4

hmsilva
Mentor
Mentor

Try

 

(defun xfile (/ file)
    (setq file (strcat (getvar 'dwgprefix) "XREF-" (getvar 'dwgname)))
    (if (findfile file)
        (command "_.-wblock" file "Y" "*")
        (command "_.-wblock" file "*")
    )
)

 

and add a call to the 'xfile' function at the end of your clean up lisp... (xfile)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 4

Sandervp
Advocate
Advocate
Accepted solution

Thanks again Henrique!

 

The text "xref-" becomes a part of the filename now. If I want to change this (in the future) into "example-xref.dwg" instead of "xref-example.dwg", the only thing I have to change in the code is:

 

   (setq file (strcat (getvar 'dwgprefix) (getvar 'dwgname) "-XREF" ))

 

instead of:

 

   (setq file (strcat (getvar 'dwgprefix) "XREF-" (getvar 'dwgname)))

 

0 Likes
Message 4 of 4

hmsilva
Mentor
Mentor

@Sandervp wrote:

Thanks again Henrique!

 

The text "xref-" becomes a part of the filename now. If I want to change this (in the future) into "example-xref.dwg" instead of "xref-example.dwg", the only thing I have to change in the code is:

 

   (setq file (strcat (getvar 'dwgprefix) (getvar 'dwgname) "-XREF" ))

 

instead of:

 

   (setq file (strcat (getvar 'dwgprefix) "XREF-" (getvar 'dwgname)))

 


You're welcome, Sandervp!

 

No,

(getvar 'dwgname) will return "xxx.dwg", we have to remove the file extension from the file name, one way

(setq file (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) "-XREF" ))

 

Hope this helps,
Henrique

EESignature

0 Likes