Sunday, October 26, 2008

Start VBA Programming in Civil 3D 2009 Today!

I have been asked many times about "how do I start programming in Civil 3D?" or "I wish I knew VBA"... This is my first posting that addresses the basic request to start. This is my "Hello World" solution to VBA programming in AutoCAD Civil 3D 2009.


Download the Civil 3D Developers Guide Here:
http://images.autodesk.com/adsk/files/civil3ddevelopersguide.pdf

Download the following Sample Application Here:

www.civil3dsolutions.com/downloads/code/mycivil3dapp.zip

Quick Start

Using VBAMAN, select the Load button and browse for the downloaded sample application. Now select the Visual basic editor button the get started. Once you are within the VBAIDE or programming environment. You will be able to see either the form design and the code behind it.


Setting AECC References
For every Civil 3D related project you will need to check the "references" option in the sample application. This is where we can tell VBA that we intend on accessing the AECC Object Model. Select "Tools" menu option and then pick "References". In the sample application we have pre-selected the object models for AEC Base 5.7 Application and Object Library, and the AECC Civil Engineering Land and UILand Object Libraries. You will need to select other libraries for Pipes and Road Corridor programming.



Code Review


Setting Public Variables in the UserForm
These are the AECC objects set for the form to use.


Loading the UserForm
We need to connect with the Civil 3D object model using the GetInterfaceObject Method in AutoCAD. Then we can go ahead and set the public variables for AECCApp, AECCDb , AECCDoc.



Getting some Information from AutoCAD and Civil 3D
This basic code snippet will get information from both AutoCAD and Civil 3D. Note that in VBA, the user has access to all the objects, their properties and methods. This is just a small sample of what we can pull out of the object model...but it's a start.



Your First Application!
When you press F5 key or Run Program, you should see the formload. By selecting the "Get Information" button, you can see the list boxes fill with properties from both AutoCAD and Civil 3D.




1 comment:

Anonymous said...

link doesnt work by HARHM.org