Lisp to save 2017 Civil3D back to previous version - It works...almost

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In the wake of upgrading to AutoCAD Civil3D 2017, we've learned the sad truth that 2017 can't save back to older releases, at least the files it creates cannot be saved with an older version. This seems to be tied to Civil3D objects that remain in the drawing after using etransmit and the like. Some of our clients insist on using software made back when cassette tapes were all the rage, so they need to be able to see our survey points, surfaces, etc. The workaround that we've found is to export to dxf 2007. When this process was presented to the CAD manager, they thought that others in the office might find it a little too overwhelming. So they rang the poor programmer tucked in the back corner of storage room B who still hasn't received his paycheck and asked him to write a lisp. So here I am...
I got it pretty far along, but I'd like to ultimately have it be a one step process. I came up with the code below. It does the following:
- Run first lisp that exports the dwg to dxf 2007.
- Close dwg file and quit 2017.
- Open 2014.
- User manually opens dxf file.
- Save as 2007 dwg file over top of original file.
- Delete the dxf file.
(sorry, I know it's choppy, but this is the end result of a lot of trial and error, so some parts may not be necessary...)
Right now it is two separate lisps and requires each user to have 2017 & 2014 installed. My goals are the following:
- Combine two steps into a single command.
- If possible, remove the need to have 2014 installed simply for this process.
- I would like to be able to start with my top level drawing and run this entire process on all attached drawings.
- I also would like to write the etransmit process into it as well, but I know that etransmit is a command that can be forced to the command line so I can probably accomplish that on my own.
(defun c:BlowItUp (/ drwordrctl filelen file path newfile)
(prompt "\nThis will export current drawing to 2007 dxf format in the current directory.")
(prompt "\nIt will then close the drawing and open AutoCAD 2014.")
(initget "BlowItUp Quit")
(setq ans (getkword "\nPlease type BlowItUp to continue or Enter to quit [BlowItUp/Quit] <Quit>: "))
(if (not ans) (setq ans "Quit"))
(cond ((= ans "BlowItUp")
(setq drwordrctl (getvar "draworderctl")
filelen (strlen (getvar "dwgname"))
file (substr (getvar "dwgname") 1 (- filelen 4))
path (getvar "DWGPREFIX")
file (strcat path file)
newfile (strcat file "-CIVIL-3Dexport.dxf")
);setq
(command "tilemode" 1)
(command "filedia" 0)
(command "cmddia" 0)
(setvar "QAFLAGS" 1)
(setvar "draworderctl" 1)
(command "EXPORTTOAUTOCAD2007DXF" newfile)
(command "filedia" 1)
(command "cmddia" 1)
(setvar "QAFLAGS" 0)
(setvar "draworderctl" drwordrctl)
(command "close" "y")
);end BlowItUp
);cond
);defun
(defun c:DxftoDwg (/ drwordrctl filelen file path dxffile newfile svenv)
(setq drwordrctl (getvar "draworderctl")
filelen (strlen (getvar "dwgname"))
file (substr (getvar "dwgname") 1 (- filelen 19))
path (getvar "DWGPREFIX")
dxffile (strcat path file "-CIVIL-3Dexport.dxf")
file (strcat path file)
newfile (strcat file ".dwg")
svenv (getenv "DefaultFormatForSave")
);setq
(command "tilemode" 1)
(command "filedia" 0)
(command "cmddia" 0)
(setvar "QAFLAGS" 1)
(setvar "draworderctl" 1)
(setenv "DefaultFormatForSave" "36")
(command "saveas" 2007 newfile "y")
(command "filedia" 1)
(command "cmddia" 1)
(setvar "QAFLAGS" 0)
(setenv "DefaultFormatForSave" svenv)
(setvar "draworderctl" drwordrctl)
(vl-file-delete dxffile)
(command "quit")
);defun
Essentially, I'm trying to re-create the etransmit command to have it actually do what it says it will by saving back to an earlier version. Yes, I'm aware the almighty Autodesk in its infinite wisdom doesn't intend for us to have this functionality as has been mentioned elsewhere, but yes, we still need this functionality and this export process seems to do the trick. (Insert political rant about greedy software companies here).
I’m simply trying to uncomplicate this as much as possible for those in the office that are a little less...tech savvy... My sticking point is getting lisp to have 2017 instruct 2014 to open a specified file. (I can get it to open 2014, but when I try to use GETFILED to specify the file, 2014 tells me that the file I've specified doesn't exist despite the fact that it does). Once I figure that out, my thought was to tie the two together by having the first lisp write an acaddoc.lsp in the file directory that instructs 2014 to run the second lisp on open (and then delete the acaddoc.lsp afterward), but because I'm having trouble getting it to open the file I've specified I'm kind of stymied. I'm hoping I'm close and someone can just nudge me in the right direction. Or tell me I'm over-complicating things and there's a way easier way...
Thanks in advance. -JK