Author Topic: possible to copy a dwg to another directory as a saved down version in lsp?  (Read 5151 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
long explaination why so i wont get into it but im looking into if its possible to copy a dwg (not doing a saveas) to another directory and copying it as an acad 2000 version.

I have the code to copy a dwg to another directory, im just looking into if its possible to copy it down in version.

any guidance is appreciated

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
AFAIK, a 'save' operation would be required to change the dwg file version whichever way you decide to do it.

andrew_nao

  • Guest
i couldnt figure anything out so i came up with this

Code: [Select]
(defun SaveDwg (/ new_dir activedoc docname newdoc)
(setq new_dir (strcat (getvar "dwgprefix") "test\\"))
(vl-mkdir new_dir)
 (setq activedoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq docname (vl-filename-base (vla-get-name activedoc)))
  (setq newdoc (strcat new_dir docname))
 
  (vla-save activedoc)
  (vla-saveas activedoc newdoc ac2000_dwg)
  (vl-cmdf "._close" "y")

) ;defun

*edit added the code tags
« Last Edit: March 20, 2012, 09:42:04 AM by andrew_nao »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
As far as I can remember, a simply command-line save would save the DWG, but not make the new copy current as the SaveAs command would (not sure if the same applies to the ActiveX Save & SaveAs). Regarding a save down to earlier version, I think there's similar command-line options in the Save command as there are in SaveAs.

Actually for my own position, I'd rather go with an ETransmit. In such case it can be set to save to any specific file version, even adding all the xrefs and/or bind them. It's a "prefect" solution for making a backup of your drawing, as all the xrefs become mapped relative to the main DWG saved. You need not use the ZIP file in eTrans - it could save to any folder you choose just as well.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

MeasureUp

  • Bull Frog
  • Posts: 465
Code: [Select]
(setvar "filedia" 0)
(command "_.saveas" "2000" "NewDrawingName")
Hope it helps.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
 :police:
Don't forget to restore the FileDia system variable to it's former value   :-)

edit:
On second thoughts .... I don't believe the variable needs to be changed when run from an AutoLisp or ARX command ... but check that :)
« Last Edit: March 19, 2012, 10:35:55 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...

edit:
On second thoughts .... I don't believe the variable needs to be changed when run from an AutoLisp or ARX command ... but check that :)
x2
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Code: [Select]
(setvar "filedia" 0)
(command "_.saveas" "2000" "NewDrawingName")
Hope it helps.
As per my previous post, that would make the new copy the current drawing. If that's what you want, then it should be perfect. Unless there's some other reason the OP stated "not doing a saveas".

If you simply want to make a "backup" copy of the current drawing, yet still have the same original drawing open, then try this:
Code: [Select]
(command "_.SAVE" "NewDrawingName")Unfortunately it doesn't seem to have the version options as the SaveAs command does. Only way I can think of would be to modify the "DefaultFormatForSave" environment variable (i.e. the default format in the Options dialog's Open and Save tab).

On the other hand, perhaps the OP wanted something which could be called through ObjectDBX - i.e. allowing to work on multiple documents quite quickly (faster than scripts). Then something like this might do:
Code: [Select]
(vl-load-com)

(defun SaveCopy (doc newPath version / newFile)
  (if (not (vl-file-directory-p newPath))
    (vl-mkdir newPath)
  )
  (setq newFile (strcat (vl-string-right-trim "\\/" newPath) "\\" (vla-get-Name doc)))
  (if (findfile newFile)
    (vl-file-delete newFile)
  )
  (vla-SaveAs doc newFile version)
)
Call it using something like this:
Code: [Select]
(defun BackupDrawings2000 ( / dbx doc newPath *error*)
  (defun *error* (msg)
    (foreach obj '(doc dbx)
      (if (and (eq (type obj) 'VLA-OBJECT) (not (vlax-object-released-p obj)))
        (vlax-release-object obj)
      )
    )
    (or (not msg)
        (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **"))
    )
    (princ)
  )
 
  (setq dbx (vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." (itoa acver)))
        newPath "MyNewPath"
  )
 
  (foreach file '("FilePath1" "FilePath2" ... "FilePath#")
    (if (not (vl-catch-all-error-p (setq doc (vl-catch-all-apply 'vla-Open (list dbx file)))))
      (progn
        (SaveCopy doc newPath ac2000_dwg)
        (vla-Close doc :vlax-false)
      )
    )
  )
  (*error* nil)
)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

andrew_nao

  • Guest
what i was looking to do in this case, is just to copy the open dwg to a different directory at the same time saving it down without opening it, or making it the current dwg.

this is to allow customers who dont have the latest acad to open it up.
yea we could just make a pdf of it, but when the customer requests dwg files, pdf obviously wont do.

dgorsman

  • Water Moccasin
  • Posts: 2437
Why not just batch convert as part of the "send to client" procedure?
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
what i was looking to do in this case, is just to copy the open dwg to a different directory at the same time saving it down without opening it, or making it the current dwg.

this is to allow customers who dont have the latest acad to open it up.
yea we could just make a pdf of it, but when the customer requests dwg files, pdf obviously wont do.

Why not just batch convert as part of the "send to client" procedure?

Exactly what I was on about previously.

Actually for my own position, I'd rather go with an ETransmit. In such case it can be set to save to any specific file version, even adding all the xrefs and/or bind them. It's a "prefect" solution for making a backup of your drawing, as all the xrefs become mapped relative to the main DWG saved. You need not use the ZIP file in eTrans - it could save to any folder you choose just as well.
All possible steps in one go: Save to specified version, bind, include xrefs, fonts, images, plot configs, etc. All pathing sourted out for you and in newer acads there's even a purge option. And all this can be automated in a script or even a button. It won't affect the current drawing, as only the copy will be adjusted to suit.

As for not opening the file in order to make a saved down duplicate of it, that's a bit "impossible". The file needs to be opened in order to save it down. That doesn't mean you need to open it for editing on screen though. My previous post shows how you can make use of ObjectDBX to open the DWG in the background and then saveas. Alternatively a much easier and faster way: DWG TrueView/Convert.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
AFAIK, the 'version' parameter of the 'SaveAs' method doesn't work with ObjectDBX

andrew_nao

  • Guest
Why not just batch convert as part of the "send to client" procedure?

its overkill for just 1 dwg

andrew_nao

  • Guest
AFAIK, the 'version' parameter of the 'SaveAs' method doesn't work with ObjectDBX

what i posted works for saving down to vers. 2000

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
AFAIK, the 'version' parameter of the 'SaveAs' method doesn't work with ObjectDBX

what i posted works for saving down to vers. 2000

Your code doesn't use ObjectDBX.