Jump to content

Recommended Posts

Posted

Hello Guys

I'm trying to create a routine Lisp to Saveas the DWG file open it the same file again. but i don't know how to open the file through LISP.

I want to save as and open the file Automatically.

Please anyone Help me to do this.

 

 

Thanks in Advance.

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • acad1985

    11

  • ronjonp

    6

  • rlx

    3

  • Cad64

    2

Top Posters In This Topic

Posted

Your request is confusing. If you do a SaveAs, you can't open the file because it's already open. You just saved it with a different name.

Posted

Hey Thanks.

Actually i have to save as the file with different name then i need to open.

Posted

This is why I'm confused. The SaveAs command, saves your current drawing to a new location and/or a new file name. Once the file has been saved, your current drawing is now the new file that you just saved. So you don't need to open it because it's already open.

 

Maybe what you need to do is save the file to a different name and then open the previous file from before the SaveAs?

Posted

Like cad64 you write a new script file every time get current dwg name and put that as "open" last line, just use lisp to write script file and call as last line (command "script" "saveasy")

 

Roughly script is

saveas olddwg2 close
open olddwg 

Posted

Actually I'm using GIS software Which is worked on AutoCAD platform. When i do this manually. i need to saveas the file from to a folder with different name. At that time current file name will not changed. So again i need to open the file from folder.

Posted
(defun C:ReOpenSave_On nil
 (foreach rtr (cdar (vlr-reactors :VLR-Editor-reactor)) (if (= "ReOpenSave" (vlr-data rtr)) (vlr-remove rtr)) )
 (vlr-set-Notification (vlr-Editor-reactor "ReOpenSave" '((:VLR-SaveComplete . ReOpenSave:CB) (:VLR-BeginSave . ReOpenSave:CB))) 'all-documents)
 (princ)
)
(defun C:ReOpenSave_Off nil
 (foreach rtr (cdar (vlr-reactors :VLR-Editor-reactor)) (if (= "ReOpenSave" (vlr-data rtr)) (vlr-remove rtr)) )
 (princ)
)

(defun ReOpenSave:CB ( rtr args / rea )
 (setq rea (vlr-current-reaction-name))
 (cond 
   ( (eq :VLR-BeginSave rea)
     (if (not (zerop (getvar 'dwgtitled))) (setq *ReOpenSave* (apply 'strcat (mapcar 'getvar '(dwgprefix dwgname))) ) )
   )
   ( (eq :VLR-SaveComplete rea)
     (if (and *ReOpenSave* (not (eq (apply 'strcat (mapcar 'getvar '(dwgprefix dwgname))) *ReOpenSave*)))
       (
         (lambda ( fpath / shell )
           (if fpath
             (vl-catch-all-apply
               (function
                 (lambda nil
                   (setq shell (vlax-get-or-create-object "Shell.Application"))
                   (vlax-invoke-method shell 'Open fpath)
                 )
               )
             )
           )
           (vl-catch-all-apply 'vlax-release-object (list shell))
         ); lambda
         *ReOpenSave* 
       )  
     ); if
     (setq *ReOpenSave* nil)
   )
   ( '(67 114 101 100 105 116 115 32 116 111 32 76 101 101 32 77 97 99) )
 ); cond
); defun ReOpenSave

(vl-load-com) (princ)
(C:ReOpenSave_On)

Posted

Haha ... :)

(apply 'strcat (mapcar 'chr '(67 114 101 100 105 116 115 32 116 111 32 76 101 101 32 77 97 99)))

Posted
Haha ... :)

(apply 'strcat (mapcar 'chr '(67 114 101 100 105 116 115 32 116 111 32 76 101 101 32 77 97 99)))

 

Could not mention my friend in a discrete way (he taught me reactors). :)

Posted

Maybe you mean you need to copy a file to another directory rather than saveas? Give this a try:

(defun c:foo (/ f nf p sf sh)
 (setq sf "MySubFolderNameZippityDooDah")
 (setq p (getvar 'dwgprefix))
 (setq f (getvar 'dwgname))
 (setq nf (strcat p sf "\\" f))
 (cond	((cond ((findfile nf) (print "File exists...") nil)
       ((vl-file-directory-p (strcat p sf)) (vl-file-copy (strcat p f) nf) t)
       ((vl-mkdir (strcat p sf)) (vl-file-copy (strcat p f) 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)

Posted

Guys Thank you for your codes.

Both your codes working perfectly.

 

@ronjonp your code is creates a folder on same path and saveas the file on that folder. can you make small modification on this?

 

I have to saveas the files on folder called as "Plans". can we select the path manually instead of Automatically select the path.

 

Once run the lisp dialog box should be open to select the path, (All the files saved inside this folder, E:\Autocad Files\SSC\North Region\SNE ,so file

 

browser ;should open with this folder while open to select the path)

after select the path "Plans" folder will be create automatically on that folder and open automatically.

Posted

Hi, Anyone Please Help me.

Posted
The SaveAs command, saves your current drawing to a new location and/or a new file name. Once the file has been saved, your current drawing is now the new file that you just saved. So you don't need to open it because it's already open.

 

Correct, whereas the SAVE command writes the contents of the editor out to a new file, but keeps you in the current file. More info.

Posted

Try this:

(defun c:foo (/ _dir F NF P SF SH)
 (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
     (setq f (getvar 'dwgname))
     (setq sf "Plans")
     (setq nf (strcat p sf "\\" f))
     (cond
((cond
   ((findfile nf) (print "File exists...") nil)
   ((vl-file-directory-p (strcat p sf)) (vl-file-copy (strcat (getvar 'dwgprefix) f) nf) t)
   ((vl-mkdir (strcat p sf)) (vl-file-copy (strcat (getvar 'dwgprefix) f) 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)

Posted

This is amazing. worked perfectly.

This is worked what i want,Thank you so much ronjonp.

 

Thank you all of your effort.

 

Much Appreciated.:D

Posted

Hey Guys, i had a same scenario here.

I have a Lisp file to do some process automatically, every time we need saveas the file and run the lisp.

instead of that, can we run the lisp automatically after open the saved file through above posted lisp?

We can't add the lisp to Acaddoc.lsp file because we need to run the lisp to the file which we opened by above code(Saveas file)

 

I think if i add the lisp on Acaddoc.lsp, it's will run all the time when we open the AutoCAD right?

 

Thanks

Posted
This is amazing. worked perfectly.

This is worked what i want,Thank you so much ronjonp.

 

Thank you all of your effort.

 

Much Appreciated.:D

 

Glad to help :)

Posted
Hey Guys, i had a same scenario here.

I have a Lisp file to do some process automatically, every time we need saveas the file and run the lisp.

instead of that, can we run the lisp automatically after open the saved file through above posted lisp?

We can't add the lisp to Acaddoc.lsp file because we need to run the lisp to the file which we opened by above code(Saveas file)

 

I think if i add the lisp on Acaddoc.lsp, it's will run all the time when we open the AutoCAD right?

 

Anyone Have an idea to do this?

  • 4 weeks later...
Posted

Hello ronjonp,

The above code was working Perfectly.

but i have a another issue on this.

Can i put the file name manually when i save the file. actually this is save the file automatically.

Every time i need to do the rename of the file once process done.

so if i can put the file name could be better.

 

Sorry for delay.

Thanks.

Posted

Hello... Please help me anyone...:(

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