Saturday, June 26, 2010

Extension Methods

Have you ever wished the Civil 3D API had additional methods? If you have you might want to check out extensions. If your an amateur programmer like myself you probably don’t have much of a clue what an extension method is. Essentially .NET programming lets you take an existing object or class and extend it with additional methods or properties. An example of how to create an extension is in the Free Version of the SincPac. As well as a good example of how to create it, the extension methods may be used to shorten your programming tasks.

For instance you may have a routine that asks the user to select a surface. Of course you don’t want the user to try to select a surface if one isn’t available. Using the SincPac we can use the AeccDatabase Extension to see if a surface exists. We don’t have to recreate the code to see if a surface exists. By using extensions we can reduce the amount of code we have to come up with.

Imports Autodesk.Civil.Roadway.DatabaseServices
Imports Autodesk.AECC.Interop.Land
Imports Quux.C3DUtilities.Extensions
Imports Quux.C3DUtilities
Imports Autodesk.Civil.DatabaseServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices

Public Class SincPacExtensionExample
Public Sub SincPacExtensionExample()
Dim aeccConn As New AeccAppConnection
If aeccConn.AeccDb.DrawingContainsSurfaces Then
' Do something
End If
End Sub
End Class

Taking a look at the SincPac code we can see the code is relatively simple for the method being accessed in this case; others included are more involved.


So hopefully you’ll find the extensions available in the SincPac useful; either as an example for creating your own or using the ones already included.

No comments:


Blog Widget by LinkWithin