Jump to content

lsp help for saving a copy of all opened dwgs to specified folder with suffix no.++!


jamesfui

Recommended Posts

hi.. need help on creating lsp that can:

 

> save out a copy each on all opened dwgs to specified folder with suffix increase as per existing by next number!

 

example;

```````

Currently opened dwgs:

abc.dwg , def.dwg , ghi.dwg , etc.dwg

 

when the command function is execute, it will create a copy each in specified folder same as the above opened filenames with a suffix added as shown below;

c:\documents & settings\user\backup\abc_1.dwg

c:\documents & settings\user\backup\def_1.dwg

c:\documents & settings\user\backup\ghi_1.dwg

if the second time of the command function is execute, it will save another copy with increment of 1 as per existing filename as shown below;

c:\documents & settings\user\backup\abc_2.dwg

c:\documents & settings\user\backup\def_2.dwg

c:\documents & settings\user\backup\ghi_2.dwg

thanks 8)

 

Link to comment
Share on other sites

Try something like this:

 

([color=BLUE]defun[/color] c:backup ( [color=BLUE]/[/color] dir dwg dfn sfn inc )

   ([color=BLUE]setq[/color] dir [color=MAROON]"C:\\YourDirectory"[/color]) [color=GREEN];; Backup Directory[/color]

   ([color=BLUE]if[/color] ([color=BLUE]vl-file-directory-p[/color] ([color=BLUE]setq[/color] dir ([color=BLUE]vl-string-right-trim[/color] [color=MAROON]"\\"[/color] ([color=BLUE]vl-string-translate[/color] [color=MAROON]"/"[/color] [color=MAROON]"\\"[/color] dir))))
       ([color=BLUE]vlax-for[/color] doc ([color=BLUE]vla-get-documents[/color] ([color=BLUE]vlax-get-acad-object[/color]))
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]not[/color] ([color=BLUE]eq[/color] [color=MAROON]""[/color] ([color=BLUE]setq[/color] sfn ([color=BLUE]vla-get-fullname[/color] doc))))
                   ([color=BLUE]setq[/color] dwg ([color=BLUE]vl-filename-base[/color] ([color=BLUE]vla-get-name[/color] doc))
                         inc 0
                   )
                   ([color=BLUE]while[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] dfn ([color=BLUE]strcat[/color] dir [color=MAROON]"\\"[/color] dwg [color=MAROON]"_"[/color] ([color=BLUE]itoa[/color] ([color=BLUE]setq[/color] inc ([color=BLUE]1+[/color] inc))) [color=MAROON]".dwg"[/color]))))
                   ([color=BLUE]vla-save[/color] doc)
                   ([color=BLUE]vl-file-copy[/color] sfn dfn)
               )
           )
       )
       ([color=BLUE]princ[/color] [color=MAROON]"\nInvalid Backup Directory."[/color])
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color])

 

Change the backup directory as required.

Link to comment
Share on other sites

it works just fine, :lol:b this is one of the most good lsp i always wanted to insure my drawings safe...

but it also triggers the 'qsave' command which i prefer to switch this feature off if possible, cause

mostly i need to create a backup copy "BEFORE & after"... so if there is a field update on lastsaved, it will update automatically on the original drawings!! :(

 

Also the same lsp, i try to change the save file extension from ".dwg" to ".bak"

it runs/works just fine, but when i try to change the extension to ".lnk"

the created shortcut *.lnk doesn't seem to link back to the source drawing!?!

 

like when i try to right click to 'open file location', the created *.lnk didn't work so! :ouch:?

 

so if possible to switch off the 'qsave' command & also make the created *.lnk work. thanks! 8)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...