# Exporting object data to SDF/SHP

I want to create a Dynamo script that can export object geolocation and attribute data to either an SDF or SHP file. The objects could be polylines, blocks, points, etc. Basically, I want to have the same functionality as the MAPEXPORT command so that I can automate the process of selecting different objects on different layers and saving them out as separate SDF/SHP files.

I tried to create a Python node but didn’t get it to work (I’m not strong with Python). Does anyone have any ideas?

I’m not aware of any method for this in Dynamo (although could exist)

An alternative is to use the OGR2OGR utility, which is part of ‘GDAL’- basically a set of opensource GIS applications.

The following sample would export to a shapefile

• OGR2OGR will work with a myriad of formats- https://gdal.org/drivers/vector/index.html
However, SDF being an Autodesk format- this isn’t one of them
• It will work with some DWG files- but sensitive to versions and geometry type etc. Certainly would not work with C3D objects such as alignments. The most reliable option would be to first export from C3D as a DXF
• Shapefiles have a number of limitations- depending what you are doing, a geodatabase of some kind is probably better

ogr2ogr -where "OGR_GEOMETRY='LINESTRING' AND LAYER='LAYER1'" -f "ESRI Shapefile" c:\temp\out.shp c:\temp\in.dxf

2 Likes

That’s very interesting! I’ve never heard of GDAL before. I’m still hoping to find a way to accomplish this with Dynamo, but I haven’t made any progress yet. Thank you for your idea, I appreciate it.

If you want to invest time in GDAL, you better look at the APIs in Civil 3D. It is default available and you don’t need other libraries.

It’s not easy, when you don’t have experience with Python or other language, but GDAL isn’t either.

@mzjensen Have you found any solution for exporting lines from Civil as shp or sdf ? Im also looking for a solution but i think Im stuck for the moment

Not really…my solution for now is a Python node that sends a string of inputs to the command line for the -MAPEXPORT command (i.e. without the dialog box). Not very elegant, but it works for now.

@mzjensen

Do you maybe have a screencast from your workflow today?
We would alos like to export the SHP files via Dynamo. But maybe it is more convenient to provide this via FME.

I spoke last week with Mohsen Assaqqaf about exporting SHP out of Civil 3D via Dynamo.
We currently see 2 possibilities:

1. Export shp files with DynaMaps (@Mostafa_El_Ayoubi) if it is possible?
https://dynamobim.org/dynamaps/

2. To do it in just Dynamo with Zero-Touch nodes and work with the API that Civil 3D provides.
https://github.com/DotSpatial/DotSpatial

Do you have another idea or agreement with the above?

Python

2 Likes

@Paolo_Emilio_Serra1

Do you have tips to start with this?

MAPEXPORT is the easiest- but it depends if you have specific requirements that this command does not address.

Shapefiles are widespread and reliable- but fairly old technology with some limitations- such as only storing a single geometry type.
Generally speaking, spatial databases such as Spatialite or SDF (a flavour of spatialite), or full-blown databases such as Postgres/PostGIS are more flexible- but it depends what you want to achieve.

@Andrew_Hannell

What we currently want to achieve is the following:
C3D (polygones) -> Dynamo (SHP) -> Infraworks (SHP)

Maybe DynaMaps can help us to get the polygones in Dynamo, in Dynamo we need to provide a Python node that can export the data to SHP format (as indicated by @Paolo_Emilio_Serra1) .

1 Like

I’d start here: https://pypi.org/project/pyshp/

C3D is irrelevant as you learn how to use that. Just write a few polygons or whatever out to SHP. Then transition to D4C3D and a real data set. Then work on the import step.

1 Like

You might be over-complicating it. If all you want to do is export stuff to a shapefile- MAPEXPORT will do just that.

I would do the following:

1. Carry out an initial export of polygon geometry to a SDF file
2. Load this SDF file back into C3D, and add any attributes etc, or use C3D to edit the data- either geometry or attributes. You can certainly query this data with Dynamo & it looks like you can modify it too, using nodes such as SetProperyValueByName- but I have not tried this
3. Load the SDF file into Infraworks. This does work pretty well- you make an edit in C3D then hit refresh in Infraworks

Hope this helps

Do you have experience with this Drbohlav?

No, Sorry.

This is my method as well. I’ve found that MAPEXPORT is the easiest, but the problem is that I typically want many separate SDF files to import into InfraWorks as coverage areas because then they will show up separately in the surface layers window. That way you can toggle the visibility on/off for individual layers. With MAPEXPORT you can export multiple features along with their CAD layer attribute to a single file, but then in InfraWorks you only have one data source and therefore lose the visibility control.

Hence the need to automate. Here’s a screen recording of my current solution, which I don’t really like, but it works. It basically just builds up a big string to send to the command line and execute the MAPEXPORT command multiple times. Eventually I want a more direct export method via the Map API, but for now this works.

MapExportTest.dwg (386.5 KB)
MapExportByLayer.dyn (61.3 KB)

3 Likes

@mzjensen

Is it true that we still miss the output (Python node)?

Fig. 1

Fig. 2

@j.boonen I’m not sure why it’s like that, it doesn’t do that on my end. Anyway, here is the code, it’s just a few lines to send a string to the command line.

import System
from System import *

output = "Error"
inputList = IN[0]

OUT = "Success"