Formatting Stations with .NET Extension

By Augusto Goncalves

Format stations like Civil 3D using, for instance, 3+1.00 for a number like 61.00, can be easy with .NET, and even more easier with .NET Extensions. Here it is: first define a module class that contains your utility functions, something like

Public Module Utils   <System.Runtime.CompilerServices.Extension()>   Public Function ToStationString(station As Double) As String     Dim fractionPart As Double = station Mod 20    Dim integerPart As Double = (station - fractionPart) / 20    Return String.Format("{0:0}+{1:0.00}", integerPart, fractionPart)  End FunctionEnd Module

The above code assumes the distance between stations as 20 and, for simplicity, this number was hard coded. Note the Extension attribute that does the trick to add it for all doubles. Now we can use like:

Dim stationDouble As Double = ' some number here
Dim stationString As String = stationDouble.ToStationString()

Isn’t that nice?

Hope you enjoyed.

Important: this simple code is not taking Civil 3D styles into consideration, but can be a nice addition to it.


Comments

2 responses to “Formatting Stations with .NET Extension”

  1. How do i make use of the C3D station format, i.e. string to raw and raw to string for stations.
    Where can i download the complete running code so i can test this code also. Thank you.

  2. Hi,
    In fact this code is not intended to run as an independent project, but used whenever you need to write (output) station data. If is there any specific scenario, I can try something…
    Regards,
    Augusto Goncalves

Leave a Reply to Augusto GoncalvesCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading