Jump to content

Lisp to Saveas and Open the file Automatically


acad1985

Recommended Posts

adding a getstring to ask for filename is not rocket science....

 

(defun c:foo (/ _dir F NF P SF SH dwg)
 (defun _dir (msg path / sh folder out)
   (or (vl-file-directory-p path) (setq path (getvar 'dwgprefix)))
   (cond ((and    (setq sh (vlax-get-or-create-object "Shell.Application"))
       (setq folder (vlax-invoke-method sh 'browseforfolder 0 msg "&H2000" path))
      )
      (setq out (vlax-get-property (vlax-get-property folder 'self) 'path))
      (setq out (strcat (vl-string-right-trim "\\" out) "\\"))
     )
   )
   (and sh (vlax-release-object sh))
   out
 )
 (setq dwg (strcat (getvar 'dwgprefix) (getvar 'dwgname)))
 (if (and (setq p (_dir "Pick a directory yo!" "E:\\Autocad Files\\SSC\\North Region\\SNE\\"))
          (setq f (getstring "\nEnter file name for drawing : "))) ; *** added ask for new drawing name here ***
   (progn
     (setq sf "Plans" nf (strcat p sf "\\" f ".dwg")) 
     (cond
       ((cond
        ((findfile nf) (prompt "File exists...") nil)
        ((vl-file-directory-p (strcat p sf)) (vl-file-copy dwg nf) t)
        ((vl-mkdir (strcat p sf)) (vl-file-copy dwg nf) t)
    )
    (setq sh (vlax-get-or-create-object "Shell.Application"))
    (vlax-invoke-method sh 'open nf)
    (vlax-release-object sh)
   )
     )
   )
 )
 (princ)
)
(vl-load-com)

Edited by rlx
Link to comment
Share on other sites

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • acad1985

    11

  • ronjonp

    6

  • rlx

    3

  • Cad64

    2

Top Posters In This Topic

Hello RLX

Actually I'm very newbie for LISP,just i'm learning these things.

and very for disturbing again.

I have Tested your code, it is asking the file name but it will not save the file.

it is just created the Plans folder.

 

 

Thanks

Link to comment
Share on other sites

Hello RLX

Actually I'm very newbie for LISP,just i'm learning these things.

and very for disturbing again.

I have Tested your code, it is asking the file name but it will not save the file.

it is just created the Plans folder.

 

 

Thanks

 

you're absolutely right , my mistake , updated code above ... shouldn't have typed it directly in browser without testing (and I did it again cause I still haven't tested it...)

 

to make your life a little easier , this version has default option (enter to keep the same drawing name)

(defun c:foo (/ _dir F NF P SF SH dwg)
 (vl-load-com)
 (setq dwg (strcat (getvar 'dwgprefix)(getvar 'dwgname)))
 
 (defun _dir (msg path / sh folder out)
   (or (vl-file-directory-p path) (setq path (getvar 'dwgprefix)))
   (cond ((and (setq sh (vlax-get-or-create-object "Shell.Application"))
               (setq folder (vlax-invoke-method sh 'browseforfolder 0 msg "&H2000" path)))
          (setq out (vlax-get-property (vlax-get-property folder 'self) 'path))
          (setq out (strcat (vl-string-right-trim "\\" out) "\\"))
     )
   )
   (and sh (vlax-release-object sh))
   out
 )
 
 (if (setq p (_dir "Pick a directory yo!" "E:\\Autocad Files\\SSC\\North Region\\SNE\\"))
   (progn
     (if (eq "" (setq f (getstring (strcat "\nEnter drawing name <" (vl-filename-base dwg) "> : "))))
       (setq f (vl-filename-base dwg)))
     (setq sf "Plans" nf (strcat p sf "\\" f ".dwg"))
     (cond
       ((cond
          ((findfile nf) (prompt "File exists...") nil)
          ((vl-file-directory-p (strcat p sf)) (vl-file-copy dwg nf) t)
          ((vl-mkdir (strcat p sf)) (vl-file-copy dwg nf) t))
        (setq sh (vlax-get-or-create-object "Shell.Application"))
        (vlax-invoke-method sh 'open nf)
        (vlax-release-object sh)
      )
     )
   )
 )
 (princ)
)

Edited by rlx
Link to comment
Share on other sites

Thank you so much RLX.

Both the codes is working perfectly as what i want.

 

Thanks again.:D

 

you're welcome although most of the credit goes of cource to ronjonp...; :beer:

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...