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
Solved! Go to Solution.
Solved by Moshe-A. Go to Solution.
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
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
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.
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.
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) )
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
@Anonymous 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.
???
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
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
OK, you make more sense this go around...
A simplified folder tree would look like this?
Job Folder
- Sub Folder 1
- Sub Folder 2
- Release Folder
- R-1
- R-2
- Sub Folder 4
- Etc...
And you want the program to either automatically select the latest folder or
create a new folder? How will the program know which option to choose?
A user of this program must make this determination.
Overnight thinking suggest a list_box that will display these sub folders.
One would either select from the list (as default action), or go ahead and
create a new folder (a button).
Using our file structure here as the example, I may suggest that your "R-1" is
not sufficient enough to make a determination as to which option the user will
choose from. Now if the folder name contains a Date, the user will have an
easier time of selecting which option to choose - "Release 2012-09-21".
Program steps:
- Start routine.
- A dialog box showing all the Release sub folders for that particular Job Folder where the last line is highlighted.
- The user either accepts what is showing (OK or [Enter]), or selects a button to "Create New Folder".
- The program does it's thing...
What do you think?
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
our simple folder tree would look like this
-Project folder
-projectdrawing.dwg
-subfolder 1
-subfolder 2
-subfolder 3
-DXF-Programs-Releases
-R-1
-R-2
-subfolder 4
these folders are named the same relative to the drawing, the first set of dxfs we will put in R-1, the next set in R-2, and so on, we dont need the command to create the folder, just come back to it after we navigate to it in the first instance of the command, just to reduce the number of clicks and drill downs we have to do to save the dxfs, we are running the command sometimes 100s of times and a little time saved here and there helps.
if i run the command, save it to -R-1 folder, click save, re-run the command, i dont need it to start again in the -DXF-program-releases folder, i want to stay in R-1 until i navigate out and into R-2 then re-run the command i want it to come back to the R-2 folder and so on.
i hope this is clear enough,
thank you
Scott
Scott,
check this buddy
this one is looking for "DXF-Programs-Releases" folder which must be exist under the current open drawing folder
note that if you open a dwg in "Subfolder1" folder? then it will look for "DXF-Programs-Releases" under that folder.
(hope this will satisfy you now)
Moshe
(defun c:dxf (/ AppDataKey dxfProjFolder prjDrive dxfDrive fname ss) (setq AppDataKey "AppData/scott_agisign/dxfDrive") (setq dxfProjFolder "DXF-Programs-Releases\\") (setq prjDrive (getvar "dwgprefix")) (if (or (not (setq dxfDrive (getcfg AppDataKey))) (eq (setq dxfDrive (getcfg AppDataKey)) "") (not (vl-file-directory-p dxfDrive)) (not (= (strlen prjDrive) (vl-string-mismatch prjDrive dxfDrive 0 0 t))) ) (setq dxfDrive (setcfg AppDataKey (strcat prjDrive dxfProjFolder))) ); case (setvar "cmdecho" 0) (if (and (setq fname (getfiled "DXF File:" dxfDrive "dxf" 1)) (setq ss (ssget)); select object ) (progn (setcfg AppDataKey (strcat (vl-filename-directory fname) "\\")) (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) )
I have an interest, though rather different from you, on this type of program.
During the weekend I was thinking of all the sceneries that would cause one
to loose place on which directory to continue with if AutoCAD crashes or
there is a power failure, or you switched directories where SDI=0...
I was also pondering on how many sub directories you may have as we
have an unknown limit, as shown on the pasted image of my last reply.
This program can also be written similar to Moshe in that it will check to see
if current directory matches to the temporarily stored value and if it does not,
the program will display the interface once again...
Below is a rough interface (only) that may interest you.
Since Moshe provided an answer for you, the interface may not be needed
but I can attach what I have if you request it.
Now that I know you have only two sub directories, the interface can further be
simplified to only display radio buttons for the two sub folders... My only question
still remains: How does one know which directory to select in the beginning?
Moshe:
I'm not going there, but it is a nice alternative I had not considered (I don't like to write to file).
(setcfg cfgname cfgval)
Writes application data to the AppData section of the acad2006.cfg file
Scot-65
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
Scot-65,
Not sure about it but Autodesk stop using acadX.cfg since R2004 and actually writing
the calls to (setcfg) directry to registry so in this case it is the same as using (vl-registry-write)
nice dialog box you have created, do you have plans to use it for own purposes? cause
i do not see how the OP can use it only if you are planning to sit and write the full code
to handle it (it's is a lot of code)
recenly i been writing a small lisp program that does some time log on open drawing files
(recall? did open two threads here and you helped) it contains a small dcl that
only asks the user for folder to save a log file [by theway first time i did use (acet-ui-pickdir)
function from acetutil.arx wonderful function] the whole source file took about 300 code line
only to handle the dcl took about 200 lines (piece of cake)
Moshe
the routine works great, just what i was looking for.
how do i make autocad load it into every drawing i open?
i have added it to the startup suite through appload but does that only load it in the blank drawing when autocad opens not if i open an existing drawing after autocad starts up?
also, we have a designer who has AutoCad LT and the command appload isnt found in that version, how do i load this for him?
thank you so much for your code, it helps out every day already
Scott,
putting it in startup suite is the best place for you. it will autoload at each open drawing
ofcours in the current open drawing where you actually put it in startup suite it isn't loaded
you have to manually load it or close & reopen
AutoCAD LT can not run custom Applications (not LSP/VBA/ARX)
Moshe
@Anonymous wrote:i have added it to the startup suite through appload but does that only load it in the blank drawing when autocad opens not if i open an existing drawing after autocad starts up?
does sysvar ACADLSPASDOC = 1