Importing data from AutoCAD
I have an AutoCAD drawing that contains all my basins, flow lines and impervious areas (all drawn with polylines). What is the fastest way to get the data into a SWMM input file?
Short of third party software, our typical approach would be to
We tried to develop routines to do this automatically, but always ended up running into scenarios that did not fit the standard approach, and ended up taking more time. So sometimes simple is good, so we stuck to the approach above.
I couldn't find my original circa 2005 or 2008 post, so here is a re-upload of Autolisp code to write a Windows Meta File world coordinates file
See instructions here...
Also, it is really easy using AutoLisp to write node (point) coordinates, link (polyline) vertices and catchment (closed polyline) boundaries to a text file (or excel spreadsheet) as SWMM 5 input format.
(defun C:WMF_World ( / MyScreenSize ScreenX ScreenY MyAspectRatio ViewHeight HalfView) ; KJMcRae - UMA Engineering Ltd. - July 2005 ; Write world file for use with Windows Meta File (or .tiff, .jpg, etc) (setvar "cmdecho" 0) ; Screen size in pixels (setq MyScreenSize (getvar "screensize")) (setq ScreenX (float (car MyScreenSize))) (setq ScreenY (float (cadr MyScreenSize))) (setq MyAspectRatio (/ ScreenX ScreenY)) (prompt "\nAcad viewport width = ")(princ ScreenX) (prompt " height = ")(princ ScreenY) (prompt " Aspect Ratio = ")(princ MyAspectRatio)(princ) ; Height of the view in the current viewport (drawing units) (setq ViewHeight (getvar "viewsize")) ;Center of view in the current viewport (drawing units) (setq MyCentreCoord (getvar "viewctr")) (setq CX (car MyCentreCoord)) (setq CY (cadr MyCentreCoord)) (setq OffsetX (* 0.5 ViewHeight MyAspectRatio)) (setq OffsetY (* 0.5 ViewHeight)) ; Corner of viewport / screen (in drawing units) (setq Xmin (- CX offsetX)) (setq Xmax (+ CX offsetX)) (setq Ymin (- CY offsetY)) (setq Ymax (+ CY offsetY)) ; Display coordinates (prompt "\nXmin = ")(princ Xmin)(prompt " Xmax = ")(princ Xmax)(princ) (prompt "\nYmin = ")(princ Ymin)(prompt " Ymax = ")(princ Ymax)(princ) ; draw a polyline boundary around the viewport limits (command "PLINE" (list Xmin Ymin 0.0) (list Xmax Ymin 0.0) (list Xmax Ymax 0.0) (list Xmin Ymax 0.0) "C") ; finish drawing polyline ; Size of Pixel (setq XPixelSize (/ (- Xmax Xmin) ScreenX)) ; positive (setq YPixelSize (/ (- Ymin Ymax) ScreenY)) ; typically negative (prompt "\nX pixel size = ")(princ XPixelSize) (prompt " Y pixel size = ")(princ YPixelSize)(princ) ; Centre of Upper Left X and Y pixel (*** not upper left edge edge of pixel) (setq XUL_Ctr (+ Xmin (* 0.5 XPixelSize))) ; half an x-pixel right of Xmin (setq YUL_Ctr (+ Ymax (* 0.5 YPixelSize))) ; half a y-pixel down from Ymax (YPixelSize is negative) ; ----------------------------------------- ; write ESRI world file (rename as needed later) ; use default extension .mfw for Windows Metafile (rename to .jfw for .jpeg world file ; or .tfw for .tiff world file) (setq MyFullDwgName (getvar "DWGNAME")) ; drawing name without '.dwg' extension (setq MyDwgNameOnly (substr MyFullDwgName 1 (- (strlen MyFullDwgName) 4))) (setq Myfilename MyDwgNameOnly) (setq Myfilename (getfiled "Save World File As" Myfilename "mfw" 1)) (setq file (open Myfilename "w")) ; Line 1: Pixel size in the x-direction (drawing units/pixel) (princ (rtos XPixelSize 2 6) file) (princ "\n" file) ; Line 2: Rotation about y-axis (not used) (princ (rtos 0.0 2 6) file) (princ "\n" file) ; Line 3: Rotation about x-axis (not used) (princ (rtos 0.0 2 6) file) (princ "\n" file) ; Line 4: Pixel size in the y-direction (drawing units/pixel), almost always negative (princ (rtos YPixelSize 2 6) file) (princ "\n" file) ; Line 5: X coordinate of centre of upper left pixel (screen x=0 y=0) (princ (rtos XUL_CTR 2 6) file) (princ "\n" file) ; Line 6: Y coordinate of centre of upper left pixel (princ (rtos YUL_CTR 2 6) file) (princ "\n" file) (close file) (princ) ) ; end function (prompt "\nWMF_World - write ESRI world coordinates file for Windows Metafile export.")(princ)
Do you mean this post which has some good non LIsp tips from 2010?
I wrote a short Autolisp routine a while back to export a ESRI world coordinates file from the current Autocad viewport. It also draws a polyline around the viewport limits, which you can select and export along with your background map linework if you wish. Autolisp code is attached below, with copious display of variables and comments.
Just copy and paste into a text file, appload within autocad, and type 'wmf_world' (no quotes) in the acad command line.
Just rename the .mfw file to .jpw if using a .jpeg (raster) image (or .tfw for .tiffs, though we can't use this in SWMM5 or EPANET (yet?)). The ESRI world file is a standard format (lookup using Wikipedia), only the filename extension changes to conform to the image format (.wmf, .jpeg/.jpg, .tiff, .png, etc).
Exporting a Windows Metafile (vector) from Autocad (using Export or WMFOUT commands, or .jpeg or .bmp) will export the current viewport rectangle, including any surrounding whitespace. It's best to make the acad viewport window approximately the same aspect ratio as your SWMM5 or EPANET map window.
I guess that was the post, but unfortunately the post didn't include the source code. I must be mixing it up with an EPANET-USERS post from a few years earlier (I'm suffering from old guy syndrome; I remember doing something, but don’t remember where I put it.)
No matter, the latest version of the AutoLisp .wmf writer was attached. The code was slightly mangled by the email system (CR/LF's added after 80 characters, etc), but one of the nice features of LISP code is that it is relatively immune to adding or deleting carriage returns or line feed characters.
AutoCAD Map will convert closed polylines to polygons (see below) and export drawing objects as ESRI shape files. You can then use PCSWMM's tools to import the shape files and create the bones of your SWMM model.
You will have to convert the subcatchments' closed polylines to polygons because the shape file object created from a polyline is a line, irrespective of whether the CAD object is open or closed.