Ad

Tuesday, March 31, 2009

EG Surface Creator – Part Three

In this last post of this series of posts I’ll create a function that creates a TIN surface for an EG surface. The first part will get the drawing’s database and create a transaction. Also added is the basic error catching framework.

image

Next I’ll add the variables for a TIN surface and a variable for the AeccTinCreationData. The TIN creation data object contains all of the information Civil 3D needs to create a surface. It is pretty much all of the information contained in the dialog box when you create a surface in Civil 3D.

image

Since one of the items needed is a layer that the surface will go on I’ll see if it exists and if it doesn’t I’ll add the surface. Once the layer is created I’ll set the layer color to 9, I could also set all of the other properties of the label, but haven’t.

image

Next I’ll add the required information to the TinCreationData object. The base layer name is a string value along with the description, layer and name.

image

The next required information for the TinCreationData is the surface style that is going to be used. In this case I have a style in particular that I want to use. I’ll check to see if it exists in the drawing, if it does then I’ll use it. If the surface style does not exist then I’ll use the first one in the list. I could create the style, but have chosen not to. Then I’ll add the surface style to the TinCreationData as a string with the style’s name.

image

So now I’ll finally create the surface, commit the changes and return the surface.

image

So that completes the code necessary to do the task at hand. The compiled code may be found here. Download the file and unzip it. Type Netload at the command line and then CreateEGSurface. You may also find the TIN works also which toggles on/off the TIN triangles of a surface style. You can also add it to a toolbar. A video without sound is below.

Sunday, March 29, 2009

Civil 3D 2010 – vb.NET Samples

This is one of those what new posts. I don’t particularly like doing them, but I have goals and these posts prove really popular with Google searches. One of the new features of Help, more specifically AutoCAD Civil 3D Developer Help, is AutoCAD Civil 3D .NET API Reference.

image

Also included is a link to the Developer Center, while the site isn’t new the link to the site in Help is.

Probably the best part of the new help is the vb.NET samples. The vb.NET samples appear to be the VBA samples that shipped with previous version of Civil 3D, but ported over to vb.NET.

I found the Civil 3D .NET API Reference total Greek and not very user friendly for those not in the know of everything about .NET. So for it to be useful you definitely need to know the terms for .NET.

Saturday, March 28, 2009

EG Surface Creator – Part Deux

In the last post I went over one way to create a formwork for an automated routine to create and EG Surface. In this post I’ll cover how to create a Point Group for all of the EG related point groups to be added to the surface definition. This would be helpful since you wouldn’t need to have the point group exist in your template or a have a template specifically for an EG surface. The first thing that needs to be done is to create a Private Function that will create the point group. I also added code to start a transaction with the drawing’s database and the error catching framework.

image

Next I need to create variables for a PointGroups object, name string, and PointGroup Object. I’ll use the global Civil 3D object to assign the PointGroups variable to and set the name string equal to “EG Surface Point Group” which is the name I want to call the new point group. Creating a point group just takes using the add method of the PointGroups Object, which requires the name of the point group. Lastly I’ll add the description of the PointGroup.

image

Next we’ll be using the Query Builder portion of the PointGroup Object. To do this I’ll add a Query Statement to the Query Builder using the Add method. Once the line is added we can add the components that make up the query statement.

image

Well the above is kind of verbose, lets see if I can reduce it. By adding some more imports to the top of the code I can reduce the length of the code and get it to fit across the blog page.

image

So what does the Item Properties mean? Well the picture below illustrates what they do. In the code I went alphabetically, but it would probably make more sense to go in the order of they show up in in the Query Builder.

image

I then recreated each and every line for the Query Builder using the same type of code above. Each Query Statement you add gets the next numerical number. So the next line would be 1, the one after it 2 and so on. In the picture below you can see that I ended up going up to 19. You could also have the code get the information from a database or text document so it would be easier to change rather than going into the code each time. If you run the code and get a parse error message after the code is run, that indicates you did something wrong in the code. For instance I forgot to add the Right Parenthesis to end the Query Builder and was getting that error. Next I’ll update the PointGroup Object to refresh it and then commit the changes to the drawing’s database and finally return the PointGroup to code that was done in the last post.

image 

In the next post I’ll go over how to create a TIN surface, which should end this series of posts.

Thursday, March 26, 2009

EG Surface Creator – Part 1

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:

  1. Check to see if a Point Group called "EG Surface Point Group" exists, if it doesn’t the code will create it.
  2. Create an EG surface and add the Point Group to the surface definition.
  3. 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.

image

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.

image

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.

image

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.

image

Next I’ll check to see if Civil 3D is running, if it’s no the code will end.

image

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.

image

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.

image

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.

image

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

Monday, March 23, 2009

Round Down Expressions

Civil 3D provides math functions to Round numbers. The rounding is the just the normal rounding, but what if you wanted to round down? This is possible using an expression similar to the one below:

TRUNC({Parcel Area}/5)*5

The expression rounds a parcel area down to an interval of 5. To round down to 10 just divide the parcel area by 10 and then multiply the truncated result by 10. You may want to add If/Then statements to account for a situation where the parcel area is 4.999 when the parcel area label precision is 2. Your unrounded area label will show 5, but the round down value will show 0.

LinkWithin

Blog Widget by LinkWithin

Ad