Python loop to convert 3dm to SHP

Hi,
So sorry to ask what is likely a trivial issue, but I cannot find working modules.
I have Googled, Bard’d and searched Rhino Python examples :frowning:

I need to iterate through folders, loading one by one many .3dm files and export them to .shp format.
Iterating through the os.walk() is not the problem.

What rhino 7 module do I use to do the equivalent of:

rhino_object = **rs.read_3dm_file**(pathTo3dm) 
shapefile_path = os.path.splitext(pathTo3dm)[0] + ".shp"
**rs.3dmtoshape**(rhino_object, shapefile_path)

Thanks in advance,
Zoltan

The most reliable way, that allows you to control everything, is to import PyShp, iterate over the Rhino files, pick a shape type, iterate over the objects in each Rhino file to be added to its shapefile, get a nested list of floats from each Rhino geometry object, and add those using shapefile.Writer (along with a null record if necessary, or call the fix all method when you’re done).

There are plug-ins for this in Grasshopper. There’s a shapefile Writer component in sDNA_GH (which uses my fork, IronPyShp, that unlike PyShp hopefully correctly supports unicode in the data part (.dbf) of the shapefile on IronPython). I think sDNA_GH only supports Polylinez shapefiles at the moment.

I believe Hiteka’s Ghshp works, but installation requires to copying the PyShp file to a special Rhino Iron Python directory.

There are others too, such as ShrimpGIS, Heron, @it and MeerkatGIS, if you can get them working. People do use ShrimpGIS. I noticed Heron tries to convert a Rhino Earth Anchor point into a .prj file (or a wkt text string) which might be useful if the Rhino file includes location info or uses geographical co-ordinates.

1 Like

Hi James,
Apologies I have taken so long to respond.

I am currently side-swiped with oither Rhino related needs, so will work through your suggestions “soon”

Many thanks for your effort.

Kind regards,
Zoltan