OPEN SWMM
KNOWLEDGE
CODE
RESEARCH
RESOURCES
SWMM Knowledge Base
Menu About SEARCH LOGIN
SWMM Knowledge Base
Find and share solutions.
Software
Tap in to water management modeling that excels. PCSWMM is flexible, easy to use and streamlines your workflow – saving you time and resources.
Training
Beginner or seasoned user, our flexible training options help you understand and master the full capabilities of both EPA SWMM5 and PCSWMM.
Community
There's a whole community to support you - find solutions, view code and more.
OPEN SWMM
OPEN EPANET
Journal
Our peer-reviewed, open-access Journal of Water Management Modeling. Expand your knowledge, get insights and discover new approaches that let you work more effectively.
Conference
The International Conference on Water Management Modeling. Meet your colleagues, share your experiences and be on the forefront of advances in our profession.
Consulting
Not sure how to solve a complex water management issue? Put our experience, knowledge, and innovation to work for you.
  • ABOUT OPEN SWMM
  • KNOWLEDGE
  • SEARCH
  • CODE
  • RESEARCH
  • RESOURCES
    Software
    Training
    Community
    OPEN SWMM
    OPEN EPANET
    Journal
    Conference
    Consulting

Login

Verifying credentials  Don't have an account?
Forgot your password?
https://www.openswmm.org/Topic/4532
14-Jun-2013


Importing data from AutoCAD

Lisa Lauver

[Original email]

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?


Alexander Wilson

[Original email]

Short of third party software, our typical approach would be to

  • export the DWG in WMF format,
  • scale the image in SWMM (there is a LISP routine in CAD you can use to create world files to automatically georeference your WMF),
  • redraw the subcatchments, nodes and pipes in SWMM (it is usually fairly quick)

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.


Kirby McRae

[Original email]

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...

https://www.openswmm.org/topic/4134/rescaling

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)
 

Robert Dickinson

[Original email]

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.

Steps are:

  1. Zoom and pan to get the best view for your background map.
  2. Run the included lisp routine.
  3. Don't change the viewport limits, zoom, pan, etc!
  4. use acad commands EXPORT or WMFOUT to write the .wmf file (include boundary polyline if you like)
  5. Open SWMM5 and choose menu items \view\backdrop\load
  6. Select both the Windows Metafile.wmf and the ESRI world coordinates file.mfw
  7. Done. Compare some coordinates between Acad and SWMM5/EPANET.

Kirby McRae

[Original email]

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.


Chris Brooker

[Original email]

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.

email print link
facebook twitter linkedin
Permanent link:

SWMM code viewer
DAYS TO NEXT CONFERENCE:   240
MARCH 1-2, 2023
International Conference on Water Management Modeling

Register today for the preeminent annual meeting of water management modelers.



Connect With Us

  info@openswmm.org

147 Wyndham St. N., Ste. 202
Guelph, Ontario, Canada, N1H 4E9
About Open SWMM

Mission and intent

Digital curation

Disclaimer

Terms of use

Join Open SWMM

SWMM-USERS list server

How to subscribe

Conditions for subscribing

Guidelines for posting

Site map

Home

About

Knowledge Base

Code Viewer

Search


Copyright 2022 by CHI