It has been a long time since my last post due to, go figure, all the work we are doing for our next release. It is very hard to keep the weekly post and do my actual work during times like this. I still want to complete the series and I ask you to be patient if I miss some week. There are some more topics to cover, which I think are very interesting.
This week I will like to talk about extracting a grid from a TIN surface. This functionality exists in the application and has been exposed through the API. The API for this functionality is very simple. You just need to get a TIN surface and invoke its ‘ExtractGridded()’ method. The method takes a ‘SurfaceExtractionSettingsType’, which can have a value of ‘Model’ or ‘Plan’. This directly corresponds to 2d or 3d (We use ‘Model’ in the example, which is 3d).
Once the polylines that create the grid are extracted, you can manipulate them as any other object. In the example, we just change their color so you can distinguish them, but you can do whichever manipulation you like. Some people will not want to keep the polylines around, in which case, you can extract the information you want and not commit the transaction, so the polylines are not added to the drawing.
Here is the entire source, which you can also get from the Civilized Development repository at BitBucket.
public void CDS_ExtractGrid()
ObjectId surfaceId = promptForTinSurface();
if (surfaceId == ObjectId.Null)
write("\nNo TIN Surface selected.");
using (Transaction tr = startTransaction())
TinSurface surface = surfaceId.GetObject(OpenMode.ForRead)
ObjectIdCollection ids = surface.ExtractGridded(
foreach (ObjectId id in ids)
Polyline3d polyline =
id.GetObject(OpenMode.ForWrite) as Polyline3d;
if (polyline != null)
AutoCAD.Colors.Color.FromRgb(255, 0, 0);
private ObjectId promptForTinSurface()
PromptEntityOptions options = new PromptEntityOptions(
"\nSelect a TIN Surface: ");
"\nThe selected object is not a TIN Surface.");
PromptEntityResult result = _editor.GetEntity(options);
if (result.Status == PromptStatus.OK)
return ObjectId.Null; // Indicating error.
Public Sub CDS_ExtractGrid()
Dim surfaceId As ObjectId = promptForTinSurface()
If surfaceId = ObjectId.Null Then
write(vbLf & "No TIN Surface selected.")
Using tr As Transaction = startTransaction()
Dim surface As TinSurface =
Dim ids As ObjectIdCollection = surface.ExtractGridded(
For Each id As ObjectId In ids
Dim polyline As Polyline3d =
If polyline IsNot Nothing Then
polyline.Color = AutoCAD.Colors.Color.FromRgb(255, 0, 0)
Private Function promptForTinSurface() As ObjectId
Dim options As New PromptEntityOptions(vbLf & _
"Select a TIN Surface: ")
options.SetRejectMessage(vbLf & _
"The selected object is not a TIN Surface.")
Dim result As PromptEntityResult = _editor.GetEntity(options)
If result.Status = PromptStatus.OK Then
' Everything is cool; we return the selected
' surface ObjectId.
' Indicating error.