Last year at AU, I presented a class about COM/.NET Interoperability. The class demonstrated how to use the Civil 3D COM API from a .NET Civil 3D extension. In general, you will want to use the .NET API when writing applications for Civil 3D, but there are times when a certain API is not available through .NET, and it is only exposed in COM. This was the case with AutoCAD Civil 3D 2011 and the Surfaces API back then. Today, the Surfaces API is available in .NET, and you should start planning to port your code.
It should be no secret, by now, that when I prepared my AU class, I knew the Surfaces .NET API will ship in the next release of Civil 3D.My ultimate goal in the presentation was to show how to encapsulate the surface functionality, so when the .NET API became available, the code was easy to port.
Now, the Surfaces .NET API is publicly available, so I ported the code, which you can download from here. The ‘SurfacesDemo’ solution contains two projects that implement the same set of commands. The COM project uses the Surfaces COM API. In the .NET sample, all COM related code and references have been removed, and the code has been ported to the .NET API.
If you do a delta of both projects, you will see how the majority of the changes happen in the surface wrapper class ‘CivilTinSurface’. This was the goal when the code was written; to insure an easy port of the code from COM to .NET.
It might be helpful to go through my AU class materials to understand the concepts I explained in the presentation. I posted the materials, which contain the source code in C# and VB.NET, as well as the class presentation and handout. I hope you enjoy reviewing the materials, and that you send me any feedback you might have.
Isaac,
I try to find .net functions similar to IAeccSurface.ExtractBorder and IAeccSurface.ExtractContour, but without success. I see in Demo you use SurfaceDisplayStyleType class wich also contains components that can be extracted http://docs.autodesk.com/CIV3D/2012/ENU/filesCUG/GUID-8CEA1A8B-4433-4B18-9185-1EE3D5E29BA-886.htm
But SurfaceDisplayStyleType is for styles, is there any class for extracted objects?
Posted by: quiz | 06/28/2011 at 03:35 AM
Hi quiz,
There were some issues that prevented us from implementing that functionality in .NET. We are working on resolving those issues, so we can provide that functionality.
As it is right now, you will still have to use the COM interfaces to access the functionality. You can still use .NET for that through the interops, and the 'Surface' object should have an 'AcadObject' property that returns a COM instance of the object that can be casted to an IAeccSurface from which you can access the methods you need.
Posted by: Isaac Rodriguez | 06/28/2011 at 05:45 AM
I spent the time converting our existing Civil 3D surface code from COM to NET. The one missing method I use a lot is SampleElevations on the COM surface object. I asked ADN if I missed something and I ask you as well. Is this functionality there but different?
Posted by: Rex | 06/28/2011 at 09:11 AM
Thank you for you answer, Isaac!
I recently discovered a strange behavior of IAeccSurface.ExtractContour function. I'm trying to find intersection of two surfaces, for this I'm building volume surface and extract contour from 0 level. When set first surface for 'base' and second for 'comparison' I have for example 2 contours, when set second surface for 'base' and first for 'comparison' I have only 1 contour. Is this connected with your issue?
Posted by: quiz | 06/29/2011 at 02:09 AM
Rex,
The SampleElevations functionality was also taken out of scope because of change in the requirements. Basically, we wanted to provide a new interface that solved the issues we had with the COM API. In reality, the current interface exposes the necessary functionality to implement the feature, but I think that if it is a widely used feature, it should be provided by the API.
Posted by: Isaac Rodriguez | 06/29/2011 at 11:42 AM
quiz,
The results should be the same no matter what base you are using. If you can send me your data set, I can take a look at it to see why you are getting different results. Send me a direct e-mail with your drawing attached and the subject prefixed with 'BLOG:', and we will research this issue if we can reproduce it.
It may take a while though.
Posted by: Isaac Rodriguez | 06/29/2011 at 11:45 AM
Isaac,
I send you email with example drawing, source code with IAeccSurface.ExtractContour usage, compiled bundle and output files (BlackSurface-RedSurface.txt and RedSurface-BlackSurface.txt).
Posted by: quiz | 06/30/2011 at 04:18 AM