Much of the design process is repetition. A survey is performed, the survey points are inserted into a drawing and then a surface is built from the surface. This post will go over how to program a solution that will:
- Check to see if a Point Group called "EG Surface Point Group" exists, if it doesn’t the code will create it.
- Create an EG surface and add the Point Group to the surface definition.
- Set the surface to use the exclude minimum elevation and set the value to 0.
in order to reduce the number of repetitive steps.
I’ll be using the same vb.net project that I used for the Toggle Tin Triangles post. To help organize it I’m going to add a folder to the Solution Explorer.
I probably didn’t need the folder, but it was something new to try. Next I’ll add a new class to the folder and call it EGSurface. I’ll now add the Imports to the class, this will make available all of the objects of Autocad and Civil 3D.
The Imports aeccLandLib = Autodesk.AutoCAD.Interop lets you a shortcut instead of the long version. Next add the Command Method which will be the command used to run the command in Civil 3D which then runs the EGCreate Sub. The next line starting with Dim db As Database makes sure the active document is used when the code is run. If you don’t do this the code could be run on another drawing that is open, which can be fun if you like gambling, but probably wouldn’t be a good thing. The Transaction Manager interacts with the drawing’s database, adding, modifying and deleting items from it through the transaction.
Evidently there is a better way to catch errors that what I used for the Triangles post. The basic layout is shown below. Essentially you try to do something (the code goes between the Try and the Catch) if something goes wrong the error is caught by the Catch and the transaction is aborted. The Finally disposes of the transaction and from what I understand it happens both if everything goes correct and if things go drastically wrong.
Next I’ll check to see if Civil 3D is running, if it’s no the code will end.
Next I’ll add the code to do the first part of the first item on the list, making sure the point group exists. The variables for the PointGroups and PointGroup are created. A Boolean variable is also added as a tool to see if the point group exists. There’s probably a better way to do it. The code then loops through all of the point group objects in the point groups object. If the point group exists then the oPointGroup is assigned to the Point Group. If it is not then the CreatePointGroup Sub is called to create the point group that I’ll cover in another post.
So now it’s on to the second task, creating the surface. There’s not much here for this post, I’ll go over how to create a surface in another post. The oSurface variable is an AeccTinSurface, which is the type I want and is set equal to the CreateEGSurface sub which creates the surface. Unlike in VBA where you have to Set objects equal to somehting, in vb.net you don’t have to do that. Once the surface is created the PointGroup is added to the surface’s collection of Point Group Objects. The surface is then rebuilt to make sure it’s up to date. For some reason it doesn’t work all of the time, but it’s easy enough to rebuild the surface once the code is finished running.
The last step is to make sure the Exclue Elevations Less Than is set to true and make sure the value is 0. The trans.Commit() saves the surface and any other changes made while the code was running.
In the next posts I’ll go over how to create the point group and the surfaces. I’m still learning how to program in vb.net, so hopefully I haven’t done anything drastically wrong.
Part Deux