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.

Sunday, March 22, 2009

Pipe Network As-Builts

I’ve read some posts in the discussion groups about wanting to do pipe as-builts from survey shots taken in the field or plans. While it is easy enough to layout pipes in Civil 3D its not always easy to enter data at an exact elevation or slope. It gets a bit frustrating going into each pipe or structure and change the information. I was thinking about this for a local project that we didn’t get, I thought I’d share some of my thoughts on ways I was thinking about:

  1. Create a tool for editing pipes and structures similar to the Quick Elevation Edit tool for feature lines. This wouldn’t be that hard, depending on the complexity wanted. I may do a rudimentary post on how to do it at a later date.
  2. Create a program that imports the pipe network from an Excel spreadsheet. I guess you could also use a third party software. I haven’t used it, but I understand Steltman Software Solutions provides such a product.
  3. Create a Custom Pipe Rule that prompts you to enter the pipe slope, invert, rim elevation, etc. as you layout the pipe network. You could also use a cover value to set the invert of the pipe, if needed. You can check out the AU session I did in 2007, the various posts I’ve done or my VBA book for Civil 3D for the steps on how to create your own custom rules to do this.
  4. Use the pipe list and structure list in Prospector. I find this difficult since I don’t always know which pipe/structure I’m changing.

Thursday, March 19, 2009

Parcel Area – Comma – Correction

If you downloaded the area label style, you may find that it has problems when the area is less than 100, in that it will show the leading zeroes. To fix it just change the hundreds text label component to use the plain parcel area  instead of the expression that was used. The area label style on the Style site has been updated.

Parcel Area – Commas

The work around for commas in Parcel Area Labels has been around for quite a while. Dana had the first post or one of the first posts regarding adding commas to Parcel Labels and Being Civil posted their own version last month. So why am I having a post on it? Well both posts require you to have more than one style, in other words it will only work for a certain range for each style. In this post I’ll go over how with a few more expression we can incorporate the different styles into one.

The extra expressions that are needed are to control the height of the components of the label. I’m going to call mine HundredsSize, ThousandsSize and MillionsSize.

HundredsSize, makes the label size the correct size or makes the label component really small if it is larger than 1,000.

image

ThousandsSize checks to to see if the area is larger than 1000 and not larger than a million.

image

MillionsSize checks to see if the area label is larger than a million.

image

If you want to go into the billions you’ll have to add another expression for that and modify the MillionsSize to account for it.

Now make a text component in the label for Hundreds, Thousands and Millions. Set the text component size with the expressions made above.

image

So now the label will show the correct text component depending on the area of the parcel.

The parcel area label that I created for this post may be found here.

Monday, March 16, 2009

vb.Net Toggle TIN Triangle Visibility

In the last post I added a class to the project, in this post I'll finish the code.

The first thing that needs to be done is to make sure Civil 3D is running and get the Civil 3D objects. To do this I downloaded the dataset from this AU class. Since the AU class was done in Autocad 2008 I had to change the references to Civil 3D 2009. I also add the lines of code that called the class that was used from the AU class.

image

image

Now that we are sure Civil 3D is running and I have the Civil 3D document I can convert it to something that Civil 3D can modify/use.

image

So now that it’s been converted, I can see if the object is a surface object. You’ll notice the line of code is a tad bit more complicated than what it was in VBA. If it is then I’ll create a new surface variable and set the variable equal to the object selected.

image

So now that we know that the object is a surface I can toggle the TIN Triangle visibility, the same way that it was done in VBA.

image

So now that we made the change we need to commit the changes back to the drawings database. This is an important part of the code because if you don’t the changes won’t be reflected in the drawing. The line of code is highlighted below. Also I added an Else statement to notify the user if they didn’t select a surface.

image

Also note that the End Using line was added and this ends the use of the object. So now the code has been translated from VBA to vb.net. It’s a bit more complicated than VBA, but does have some advantages. One advantage (while not really applicable for this example) is the speed at which the code should work. It’s also a bit easier for the user to use since the code gives the command to use, in this case TIN. No need to add the command to the CUI. The completed dll file can be downloaded here. To run it type netload at the command line and select the file. Then type TIN at the command line to run the program. It will only run in Civil 3D 2009, so if you want it in another version you’ll either need to do the coding for your version yourself or making a compelling argument on why I should do it for you.

Saturday, March 14, 2009

Distance Before Bearing, Never Been Wronger. Bearing before Distance, you’re in the clear

Some people are rather particular about their parcel/line labels. One example of this is wanting to always have the Bearing portion of a label before the Distance label, or vice-versa. They also want a gap between them or on either side of a direction arrow (so putting them in the same text component won't work). This doesn't always work as one would expect because the labels rotate to match the view. An example of this is in the image below. 

image 

All of the labels above are of the same style and anchored to the direction arrow. As you can see the items on the left hand side are showing correctly and the ones on the right have them swapped. One way to achieve the labels being the same is to use a text component and set it's visibility to false and anchor the bearing and distance labels to it. The picture below shows the results that we are looking for.

image

So this is one way to get the bearing and distance label components to always be in the correct location. A sample drawing with the style may be found on this page. Use the link for the second drawing, the first one didn't work correctly when the view was twisted.

Monday, March 09, 2009

vb.NET Adding a Class

In this post I'm going to try to add a Class to the VBDotNetClientSample from the last post. To add the Class right click on the project heading in Solution Explorer and choose Add and Class.

image

image

Next I need to add Acdbmgd.dll and Acmgd.dll to the project's References.

image

image 

Next we need to set up the various items needed to run code with vb.NET. There is a lot of extra things that need to be done usually done with Imports.

image

Now we can copy the code from the VBA Toggle TIN code.

image

The underlined items indicate errors in the code. Clicking the underlined words the Visual Studio (VS) gives you options on how to correct the code. In this case I'm choosing the option that the arrow is pointing to.

image

ThisDrawing doesn't have any suggestions. To get what it should be download the ObjectARX from the Autodesk website and then open the sample code provided for getting user input.

image

The sample code is in a C# file, you may need to download the Microsoft Visual Studio version for C# to open it up. The file name and location is \ObjectARX\samples\dotNet\Prompts\prompts.cs Since we are using the GetEntity do a search for it using Ctrl+F. Select the code and go to a site that will convert C# code to vb.NET. One site may be found here. As you can see below the code has grown quite a bit from the VBA version. I've commented out the code I haven't updated yet.

image

To comment out the code you can select the code and then use a button from a Toolbar in VS.

image 

Next change the Application type to Class Library. This will change the output from VS to a .dll file from an .exe.

image

Now I can compile the code and try it out in Civil 3D. The command to load the application is Netload and the typing TIN runs the program how it is currently created. I'm not sure if this will work, but you can download the dll and see if it works.

In the next post I'll try to finish the code. As you can see doing programming in vb.NET is a bit more complicated than using VBA.

Sunday, March 08, 2009

Moving from VBA to vb.NET

VBA appears to be on the way out, it's not even going to be shipping with the base AutoCAD 2010 product (but it will ship with Civil 3D 2010). There is some rumors that VSTA will be provided for AutoCAD 2010 sometime this year. I think it may be time to put VBA to down and pick up vb.NET.

The first thing that I need to do is get a separate program to work with. Microsoft provides a free version called Microsoft Visual Studio Express (VS), make sure to download the vb.net version if you go with this option. I'm going to spend some extra cash and get the full blown version. I've used both in the past and if you do program more than occasionally I've found the extra money for the full blown version can be worth it. You can try the full version for 90 days. I think you can also use other programs, but I'm not familiar with any of them.

The next step is setting up VS to program with it to work with Civil 3D. While we could spend all of the work setting it up to work with Civil 3D it's probably easier to use the sample that comes with Civil 3D. To do this open up the solution (.sln) file in the following folder:

C:\Program Files (x86)\AutoCAD Civil 3D 2009\Sample\Civil 3D API\VB_NET\VbDotNetClient

If your using Vista you may want to copy the VB_NET folder to a location that will let you freely modify the code.

Next Build, or compile, the code by going to the Build Menu and choose Build VBDotNetClientSample.

image

VS will create an EXE file in the bin folder for the project. Double click it and it will open a dialog box asking you what to do, press the Launch Autodesk Civil 3D and Civil 3D should start up.

image

Once Civil 3D starts up the Project Details button should become available. Pressing the Project Details provides the number of Point Groups and Surfaces in the drawing.

image

I don't know about you, but I usually don't have much reason to create program to open Civil 3D up. I find the icons on the desktop sufficient. I guess that the Developers figure if your using vb.NET you already know how to create a program that runs within the program.

In the next posts I'll go over some resources that have more examples on how to run the commands within Civil 3D and use them to bring the Toggle TIN Triangle Visibility code to vb.NET.

Saturday, March 07, 2009

Steering Wheel

Have you seen the Steering Wheel? I'd seen the feature but hadn't really used it since it's not in your face in Civil 3D. In the base Autocad product when you right click you get the option to use the Steering Wheel. image

I think it has some value after using it a little bit and want to add it to the default right click menu. Once way to do it may be found in a video on this page:

http://style.civil3dreminders.com/CUISteeringWheel.html

There's no sound and it's kind of small.

Thursday, March 05, 2009

Add Command Alias

Open the the following file:

C:\program files (x86)\AutoCAD Civil 3D 2009\Support\acad2009.lsp

Add the lisp to the file:

image

Open the following file:

C:\Users\MicrosoftExcel\AppData\Roaming\Autodesk\C3D 2009\enu\Support\acad.pgp

Add the following to the end of the file:

image

Close Civil 3D if open, then reopen.

Not sure why it repeats the command though.

image

LinkWithin

Blog Widget by LinkWithin