Ad

Sunday, May 19, 2019

Export Civil 3D Table to CSV

A long desired feature is the ability to convert Civil 3D tables to a useable format. Whether it be an AutoCAD Table or Export to Excel. By long desired I mean over a decade.

I guess we don't matter, as customers, if it takes a decade to do something I'm able to do in an afternoon while I procrastinate. I'm even doing it the hard way. It would be way easier if Autodesk provided an API method of grabbing the Civil 3D Table's contents (along with Civil 3D Labels) or include the command in Civil 3D so I wouldn't have to write this stupid blog post.

This post covers how to export a Civil 3D table to a CSV file. The steps are similar if you want to export to Excel. The Title row would need to be taken care of. This could be done by looking at the Table Style and seeing if it has a Title Row included. That's for another possible blog post.

The first step is to have the user get the table. I've written the table for an Alignment Tag Label Table, you'll have to add the other types you want to run the code on.


Then we need to explode the table into its individual components. The FullExplode method handles that task. After exploding, the objects are sorted into vertical lines, horizontal lines, and MTexts.


Then the range of vertical and horizontal lines are gotten, these will be used to identify where the rows and columns are located. The Distinct() is used because the exploded tables end up having lines for each row and column.


Next the row data is processed by columns and written to the csv file.


After the data is collected the file is opened and the objects collected disposed of.

Add caption
















This code is more of a proof of concept on how to export to csv. More work would be needed to make it perfect. If the table is split, then each table section would need to be exported separately.

The code may be found here: https://1drv.ms/u/s!AqAPKXdBD3fOnE6C8F-hhCnFi3nH

No comments:

LinkWithin

Blog Widget by LinkWithin

Ad