+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 28
  1. #1
    Full Member
    Discipline
    Mechanical
    Using
    Mechanical 2015
    Join Date
    Mar 2018
    Posts
    34

    AutoCAD Lisp to Saveas and Open the file Automatically

    Registered forum members do not see this ad.

    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.

  2. #2
    Super Moderator Cad64's Avatar
    Computer Details
    Cad64's Computer Details
    Operating System:
    Windows 7 Profesional x64
    Computer:
    XI Computers
    Motherboard:
    Asus P8Z77-V Pro
    CPU:
    Intel Core I7 3770K 4.1 Ghz Quad Core 3rd Gen
    RAM:
    24GB DDR3 @ 1333MHz
    Graphics:
    Nvidia GeForce GTX 570 1280MB GDDR5
    Primary Storage:
    SATAII 500GB 7200 RPM
    Secondary Storage:
    Western Digital My Book Studio Edition II - 2TB capacity
    Monitor:
    Asus VG248 24" Widescreen & Cintiq 21ux
    Discipline
    Multi-disciplinary
    Cad64's Discipline Details
    Occupation
    Freelance Digital Artist
    Discipline
    Multi-disciplinary
    Details
    3D model building, texturing and rendering. Photoshop Color Graphics.
    Using
    AutoCAD 2014
    Join Date
    Feb 2006
    Location
    San Antonio, TX
    Posts
    10,313

    Default

    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.
    CGSociety Portfolio: http://rdeweese.cgsociety.org/
    Facebook:
    https://www.facebook.com/rdeweese67/


    "Work Smart, Not Hard"

  3. #3
    Full Member
    Discipline
    Mechanical
    Using
    Mechanical 2015
    Join Date
    Mar 2018
    Posts
    34

    Default

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

  4. #4
    Super Moderator Cad64's Avatar
    Computer Details
    Cad64's Computer Details
    Operating System:
    Windows 7 Profesional x64
    Computer:
    XI Computers
    Motherboard:
    Asus P8Z77-V Pro
    CPU:
    Intel Core I7 3770K 4.1 Ghz Quad Core 3rd Gen
    RAM:
    24GB DDR3 @ 1333MHz
    Graphics:
    Nvidia GeForce GTX 570 1280MB GDDR5
    Primary Storage:
    SATAII 500GB 7200 RPM
    Secondary Storage:
    Western Digital My Book Studio Edition II - 2TB capacity
    Monitor:
    Asus VG248 24" Widescreen & Cintiq 21ux
    Discipline
    Multi-disciplinary
    Cad64's Discipline Details
    Occupation
    Freelance Digital Artist
    Discipline
    Multi-disciplinary
    Details
    3D model building, texturing and rendering. Photoshop Color Graphics.
    Using
    AutoCAD 2014
    Join Date
    Feb 2006
    Location
    San Antonio, TX
    Posts
    10,313

    Default

    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?
    CGSociety Portfolio: http://rdeweese.cgsociety.org/
    Facebook:
    https://www.facebook.com/rdeweese67/


    "Work Smart, Not Hard"

  5. #5
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,603

    Default

    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
    Code:
    saveas olddwg2 close
    open olddwg
    A man who never made mistakes never made anything

  6. #6
    Full Member
    Discipline
    Mechanical
    Using
    Mechanical 2015
    Join Date
    Mar 2018
    Posts
    34

    Default

    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.

  7. #7
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,456

    Default

    Code:
    (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)

  8. #8
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    859

    Default

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

  9. #9
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,456

    Default

    Quote Originally Posted by ronjonp View Post
    Haha ...
    Code:
    (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).

  10. #10
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    859

    Default

    Registered forum members do not see this ad.

    Maybe you mean you need to copy a file to another directory rather than saveas? Give this a try:
    Code:
    (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)

Similar Threads

  1. Open file and run lisp - macro
    By mdbdesign in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 26th May 2010, 08:08 pm
  2. Save/Saveas/Open!!!!Problem
    By Shibuboss in forum AutoCAD General
    Replies: 2
    Last Post: 27th Jan 2010, 05:07 am
  3. Macro to Open a template & prompt saveas
    By raj banerjee in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 30th Oct 2008, 07:07 pm
  4. Macro to open a dwg, then SAVEAS?
    By dcowell in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 30th Oct 2008, 07:03 pm
  5. open drawing and prompt for saveas routine
    By raj banerjee in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 15th Aug 2007, 12:15 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts