• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    Contributor
    Posts: 13
    Registered: ‎09-03-2012
    Accepted Solution

    changing destination location of lisp routine

    263 Views, 21 Replies
    09-20-2012 10:05 AM

    I am currently using this lisp routine to export selected objects as a dxf to import into another program:

     

    (defun c:dxf ()
    (command "_dxfout"
    (getfiled "DXF File:" "c:/dxf/" "dxf" 1)
    "_Objects" (ssget)
    "" ; completes selection
    "_Version" "2004"
    "16" ; non-default number or other option if desired, with followup line(s) if
    necessary
    )
    (princ "2004 DXF Created")
    (princ)
    )

     

     

    this saves the dxfs to a location of C:\DXF

    I would like it to save to a different location, the desired location is within the same root folder that the drawing is located in and is called "DXF-Programs-Releases"

     

    thank you

    Please use plain text.
    Distinguished Mentor
    Moshe-A
    Posts: 681
    Registered: ‎09-14-2003

    Re: changing destination location of lisp routine

    09-20-2012 11:30 AM in reply to: Scott_AGISIGN

    Scott,

     

    The (getfiled "DXF File:" "c:/dxf/" "dxf" 1) function let you choose where to save the file

    your second argument only tells the function the default folder to start with

    but you can select any folder you like.

     

    Is the problem that you want the (getfiled) to start with the last selected folder?

     

    here is my fix

     

    (defun c:dxf (/ defFolder fname ss)
     (setvar "cmdecho" 0)
    
     ; set a default folder
     (if (or (eq (getvar "users5") "")
             (not (vl-file-directory-p (getvar "users5")))
         )
      (setvar "users5" (setq defFolder "c:\\dxf\\"))
      (setq defFolder (getvar "users5"))
     ); if
    
      
     (if (and (setq fname (getfiled "DXF File:" defFolder "dxf" 1))
              (setq ss (ssget)); select object
          )
      (progn
       ; Returns the directory path of a file, after stripping out the name and extension
       (setvar "users5" (strcat (vl-filename-directory fname) "\\")); need this cause (getfiled) ommits the last '\'
                                                                    ; but need it for it's second argument
       
       (command "_dxfout"
    	     fname
    	     "_Objects" ss "" ; completes selection
    	     "_Version" "2004"
                  "16" ; non-default number or other option if desired,
    	          ; with followup line(s) if necessary
       )
       (princ "\nFormat 2004 DXF Created.")
      ); progn
     ); if
      
     (setvar "cmdecho" 1)
     (princ)
    )

     

    notice how i checks the see the value retuns from (getfiled) function? cause if the user decide to cancel the command

    he will quit without any error.

     

    also it is not a good coding [as your code does] to put (ssget) function as an argument to (command) function

    for the same reasons...to allow the user to cancel quietly.

     

    notice how defFolder variable is handles? the value is saved in sysvar USERS5 (there are 5 of these)

    which is temporary saved in the current dwg database for the duration of the current autocad session.

     

    Cheers Buddy

    Moshe

     

     

    Please use plain text.
    Contributor
    Posts: 13
    Registered: ‎09-03-2012

    Re: changing destination location of lisp routine

    09-20-2012 11:54 AM in reply to: Moshe-A

    i tried your solution but it didnt prompt me to select objects, the previous script would, i dont want it to save the entire drawing as a dxf only post selected objects, also the script before had a slightly different dialog box as the "save as" dialog box that prompts with yours, thank you for your help and the argument that returns the folder location worked well

     

    Please use plain text.
    Distinguished Mentor
    Moshe-A
    Posts: 681
    Registered: ‎09-14-2003

    Re: changing destination location of lisp routine

    09-20-2012 12:40 PM in reply to: Scott_AGISIGN

     

    Here it is wrapped in lisp file, save it to your folder and load it with APPLOAD

     

    does it works?

     

    Please use plain text.
    Contributor
    Posts: 13
    Registered: ‎09-03-2012

    Re: changing destination location of lisp routine

    09-20-2012 12:51 PM in reply to: Moshe-A

    the command worked well but it is still defaulting to the C:\dxf folder instead of the folder containing the drawing. I thought the lines above the command line in the code changed this but it doesnt appear to be changed. we are almost there, thank you for your pacience and work on this solution.

    Please use plain text.
    Contributor
    Posts: 13
    Registered: ‎09-03-2012

    Re: changing destination location of lisp routine

    09-20-2012 01:15 PM in reply to: Moshe-A

    you may have misunderstood me, i DO NOT want the "save to" folder to be C:\dxf, I WANT it to be the containing folder of the drawing that i am exporting out of. i hope this makes it a little clearer.

    Please use plain text.
    Distinguished Mentor
    Moshe-A
    Posts: 681
    Registered: ‎09-14-2003

    Re: changing destination location of lisp routine

    09-20-2012 01:34 PM in reply to: Scott_AGISIGN

     

    how about that?

     

    (defun c:dxf (/ fname ss)
     (setvar "cmdecho" 0)
       
     (if (and (setq fname (getfiled "DXF File:" (getvar "dwgprefix") "dxf" 1))
              (setq ss (ssget)); select object
          )
      (progn
        (command "_dxfout"
    	     fname
    	     "_Objects" ss "" ; completes selection
    	     "_Version" "2004"
                  "16" ; non-default number or other option if desired,
    	           ; with followup line(s) if necessary
       )
       (princ "\nFormat 2004 DXF Created.")
      ); progn
     ); if
      
     (setvar "cmdecho" 1)
     (princ)
    ) 

     

    Please use plain text.
    Contributor
    Posts: 13
    Registered: ‎09-03-2012

    Re: changing destination location of lisp routine

    09-20-2012 02:41 PM in reply to: Moshe-A

    that is better, how can i set it to go back to the folder that i saved it in once i end the command, i.e. from the default folder that the drawing is in i am going into another folder that is the same in all of my project folders "DXF-Programs-Releases" under this folder i will be creating multiple folders and saving different drawings to those folders at different times, such as the first time might be in the "R-1" folder and the second in the "R-2" folder and so on... i want it to go back to the folder i just saved in when the command starts up again.

     

    also, i have set the .lsp file to load automatically at startup but do i have to reload it in each drawing that i open after that?

    THank you

     

    Please use plain text.
    *Pro
    scot-65
    Posts: 1,932
    Registered: ‎12-11-2003

    Re: changing destination location of lisp routine

    09-20-2012 03:18 PM in reply to: Scott_AGISIGN

    Scott_AGISIGN wrote:

    ...how can i set it to go back to the folder that i saved it in once i end the command, i.e. from the default folder that the drawing is in i am going into another folder that is the same in all of my project folders "DXF-Programs-Releases" under this folder i will be creating multiple folders and saving different drawings to those folders at different times, such as the first time might be in the "R-1" folder and the second in the "R-2" folder and so on... i want it to go back to the folder i just saved in when the command starts up again.


    Huh?

    You want the ability to set to a specific folder once, DFX a bunch of files in there,

    use that folder over and over again (next week, next month), and have the ability

    to set to another specific folder at a later date to repeat the process?

     

    If yes, you will need to look into storing the destination path in the registry since you

    are interacting with multiple DWG files located in various folders. VL-REGISTRY-READ

    and VL-REGISTRY-WRITE are used to accomplish this.

     

    To "Browse for Folder", do a keyword search in this forum to get that section of code.

     

    If you require help putting all of this together, there are many of us here that can assist.

     

    ???

     

    Please use plain text.
    Contributor
    Posts: 13
    Registered: ‎09-03-2012

    Re: changing destination location of lisp routine

    09-20-2012 03:39 PM in reply to: scot-65

    i like the coding so far but i want to go one step further.

     

    today i am going to be dxf-ing parts into the "R-1" folder under another folder "DXF-Programs-Releases"

    There is a "DXF-Program-Releases"  folder in everyone of our project folders. The current code you gave has the save location going to the project folder relative to the drawing being exported from.

    The first dxf from the command i want to choose where to save it, starting from the "DXF-Program-Releases" folder,

    the save location will be within this folder but another level down in a newly created folder, "R-1" and so on...

    once i save the file, i will be repeating the command sometimes 50 to 100 times this instance,

    i want the command to rememeber where i just saved and start there when i execute the command again.

     

    another day i may open this drawing up again and export different parts out, but i want these to go into a folder "R-2" or whatever is next,

    I will execute the command, navigate to that folder, and repeat the process, having the command remember where i saved this time.

     

     

    i am trying to be specific and general at the same time, im sorry if i am confusing you. It is not a general registry location, the drawings are stored on a central drive, but the relative path to the "DXF-Prog....." is the same for all the drawings, we create folders within that one when we release our parts, we will create the folder and use that folder from the other program we need the dxfs for. i just want it to start with the folder "DXF-Programs-Releases" and remember the folder navigated to when you save it for the next time i start the command.

     

    thank you again

     

    Please use plain text.