Profile Data From Points

I’m pro-customization, although I think some think it is a four letter word. Sometimes you have some work to do and Civil 3D can’t do the task out of the box. A recent poster on the discussion group has this problem. Here is quick way to make is job easier in creating a profile from points. While it could be done better, it should save him some time for the task at hand and be quicker than doing it manually.

Since I want to get the job done quickly and don’t want to spend a lot of time writing the code, I will be doing the bare minimum in creating the VBA routine. The routine will have the user select an alignment then process all of the points in the drawing, exporting the Station and Offset data to an Excel spreadsheet. The information can be processed in Excel and then imported into Civil 3D as a profile.

Since its best to start with some previously written code to reduce the work we will start with the C:\Program Files\AutoCAD Civil 3D 2008\Sample\Civil 3D API\Vba\Pipe\PipeSample.dvb file that ships with the product. Copy the file before you go further.

See my previous post on how to load a VBA file.

We are going to use the ExcelFuntions module and the ExportToExcel ModuleToUsesub. The first thing we need to do is declare some more objects that we will be using with the routine. The point object is declared as an AeccPoint and the alignment is AeccAlignmnet. We will also declare some data values to store the Northing and Easting of a point. The entbasepnt variable is to help select an alignment in the routine. Add the lines below (without the numbers and 🙂 under the other Dim’s:

   1: Dim dPointX As Double
   2: Dim dPointY As Double
   3: Dim dOffset As Double
   4: Dim dStation As Double
   5: Dim entbasepnt As Variant

Next we will have to select an alignment to use to get the Station and Offset information. The code to select an object is below along with some coding to make sure the object is an alignment and then setting the oAlignment variable to the alignment that was selected. You will want to put this portion of code right after the Dim values you added above.

   1: ThisDrawing.Utility.GetEntity oAcadObject, entbasepnt, "Select an alignment: "
   2:
   3:     If (TypeOf oAcadObject Is AeccAlignment) Then
   4:          Set oAlignment = oAcadObject
   5:     End If

Now we will cycle through all of the points in the drawing. To do this make the changes in this picture:

PointInfo

Here is the code mentioned in the picture:

   1: dPointX = oPoint.Easting
   2: dPointY = oPoint.Northing
   3:  
   4: oAlignment.StationOffset dPointX, dPointY, dStation, dOffset
   5:  
   6: ' add the values
   7: sheetPipes.Cells(iRowPipes, 1).Value = dStation
   8: sheetPipes.Cells(iRowPipes, 2).Value = oPoint.Elevation
   9: sheetPipes.Cells(iRowPipes, 3).Value = dOffset

Now just hit the Play button in the Visual Basic Editor (or run the command using VBARUN). You will probably need to switch back into Civil 3D to select the alignment. Excel should open and populate the worksheet. Sort (to separate the left and right offsets and delete any information you don’t want (such as the points with 0 offset and 0 station and the offset column). Save the data into two separate files, one for the left and one for the right offset, in an ASCII text file with the data separated by spaces. Use the Create Profile from File command from the menu to bring the profile into the file and select the desired alignment to attach the data to.

The above sample is quick and to the point with no error catching that would make the program run problem free. For instance if you select an object that is not an alignment the debugger will come up. Just choose to End the program and try again. You could also sort the data into two separate worksheets for left and right, delete any entries with a station and offset values of 0. But these improvements would only be worth the time if you planned on doing this often.

A final copy of what I came up with may be found here. Its under the 10-21-07 date (PipeSample-Profile.dvb).

2 comments

  1. Antonio Llanos says:

    I could really use a routine to create a profile from points along an alignment in C3D 2009. Following this post I loaded the dvb provided by the link. However when I run it the following error comes up:

    Compile error:
    Cant find project or library

    Debugger points to

    Public Sub ExportToExcel()
    Dim oAcadObject As AcadObject
    >>>>Dim oPipe As AeccPipe

    Im not too fluent in VB, but would really like to get this running, any ideas?
    Thanks
    Antonio

  2. Antonio this post was done utilizing Civil 3D 2008 and the references need to be changed in order for it to work in 2009, to update the references to 2009 take a look at this post: http://blog.civil3dreminders.com/2008/09/updating-references.html