Author Topic: Modify code for use on dwg and dxf files  (Read 755 times)

0 Members and 1 Guest are viewing this topic.

CraigP

  • Mosquito
  • Posts: 12
Modify code for use on dwg and dxf files
« on: May 24, 2022, 11:04:28 PM »
Hi,

I found this code here for renaming drawings and it works great, thanks Kelie.

Is it possible to modify this code so that it can also be used on dxf files?
As it is now I get a double? extension on the renamed dxf file ie: *.dwg.dxf
I am new to lisp and have no idea where to start.

Thanks

Code: [Select]
;;;COMMAND: RENDWG
;;;FUNCTION: Save current drawing as a new one with user specified name and
;;;          delete original drawing if successful.
;;;NOTES: Current drawing should have been saved prior to using this command.
;;;By: Kelie Feng, April 2006.
;;;   
(defun C:RENDWG (/ *ERROR* app saveAsType doc oPath oDwgName dir nDwgName nPath)
  (setq app    (vlax-get-acad-object)
saveAsType (vla-get-saveastype
     (vla-get-opensave
       (vla-get-preferences app)
     )
   )
doc    (vla-get-activedocument app)
oPath    (vla-get-fullname doc)
oDwgName   (vla-get-name doc)
dir    (getvar "DWGPREFIX")
  )
  (setq nDwgName (getstring 1 "\nType new drawing name w/o extension: ")
nPath (strcat dir nDwgName ".dwg")
  )
  (if (or (not (findfile nPath))
  (KF:Yes? nil
   (strcat "File \"" nDwgName ".dwg\"" " exists. Overwrite?")
  )
      )
    (if (not
  (vl-catch-all-error-p
    (vl-catch-all-apply
      (function
(lambda ()
  (vla-saveas doc nPath saveAsType)
  (vl-file-delete oPath)
)
      )
    )
  )
)
      (prompt "\nDone.")
      (prompt "\nRename/delete failed.")
    )
  )
  (princ)
)

(defun KF:Yes? (default msg / input)
  (initget "Yes No")
  (setq input (getkword (strcat "\n"
msg
" [Yes/No] <"
(if default
  "Y"
  "N"
)
">: "
)
      )
  )
  (cond
    ((= input "Yes") t)
    ((= input "No") nil)
    (t default)
  )
)

(princ)

BIGAL

  • Swamp Rat
  • Posts: 1423
  • 40 + years of using Autocad
Re: Modify code for use on dwg and dxf files
« Reply #1 on: May 25, 2022, 12:19:38 AM »
A man who never made a mistake never made anything

CraigP

  • Mosquito
  • Posts: 12
Re: Modify code for use on dwg and dxf files
« Reply #2 on: May 29, 2022, 10:10:22 PM »
Thanks, I will have a look and see how I go.