I found in my last point I needed a starting point if I’m going to post little VBA macros. Asking to delete a bunch of lines from other projects seems a bit more difficult than it should be. After the jump lets create a starting point for future VBA posts.
The first step is to create a new project, to do this type VBAMAN at the command line. This will bring up the VBA Manager. In the VBA Manager choose the New button and then select the newly created project and choose Save As to a convenient location. Next use the Load button to get some code from the samples that come with Civil 3D. For Civil 3D 2010, in Windows 7 64 bit, the samples are located at:
C:\Program Files (x86)\AutoCAD Civil 3D 2010\Sample\Civil 3D API\COM\Vba\
The samples for other operating systems and versions are similar. The project used in this post is the AlignmentSample.dvb. If asked press the Enable Macros button. The last item for the VBA Manager is to press the Visual Basic Editor button to bring up the Visual Basic Editor. Once in the Visual Basic Editor double click on the BaseObjects Modules in the AlignmentSample project.
This will bring up window that contains the BaseObjects code. Instead of copying the code, drag the module into the ACADProject, similar to the method used when transferring styles between drawings in Civil 3D. Now create a new module by right clicking on the ACADProject and choosing the Insert > Module option.
At the top of the newly created module type “Option Explicit”. On the next line type “Sub Civil3DRemindersMacro” and then press enter. Visual Basic Editor should then add the “End Sub”. The code should look similar to this:
The Option Explicit checks to make sure all of the variables declared are assigned a value. The Sub contains the code for the macro. Next open the Subroutines module from the AlignmentSample and copy the highlighted code below and paste it into the Module created above.
This code calls a macro in the BaseObjects modules and makes sure Civil 3D is running, it returns true or false depending on if Civil 3D is running or not. Now add the global constants which the code will use to pass
The last thing to do is to add the Civil 3D References to the Project. Make sure you are in the ACADProject and go to Tools > References on the Menu Bar. Press B on the keyboard, while in the References list, and it should get you close to the Civil 3D References, then scroll up till they are found. The References that need to be added are shown below:
Each version of Civil 3D has their own references differentiated by the version number. Civil 3D 2010’s version number is 7.0, Civil 3D 2009 is 6.0.
Now save the project and a starting point has been established for future posts. The finished project may be found at this link.