Ad

Friday, January 30, 2009

Point Inquiry - VBA

This post will go through the steps to get point information from a point and send the information to the command line.

The first thing we want to do is to make sure Civil 3D is running. To do this open the SurfacePoints example that comes with Civil 3D and export the Base Objects code. The sample code is located at:

C:\Program Files (x86)\AutoCAD Civil 3D 2009\Sample\Civil 3D API\Vba\SurfacePoints

image

Next go create a new VBA project through the VBAMAN command and then import the module into the new file.

image

image

Now go insert a new module into the ACADProject.

image

Next make sure the Land references are included, from the Menu: Tools > References

image

Now add Option Explicit at the top of the newly created module and Sub PointInfo(), the End Sub should automatically be created. The Option Explicit requires you to use DIM all of the variables used in the code, otherwise VBA assumes that value and that may cause problems if you want a specific type of object.

image

Now go into the subroutines module of the SurfacePointsSample and copy the lines that check to see if Civil 3D is running and gets the Civil 3D application and document.

image

Now paste it into the PointInfo() sub. This will make sure Civil 3D is running, if it's not the sub will be ended and an error message will be given to the user.

Now that we've done the housekeeping we can start to write the code to get a point using the ThisDrawing.Utility.GetEntity.

image

The AcadEntity is just a generic AutoCad entity and the vPoint is a variant. A variant is kind of like a junk entity, it will store almost anything, in this case it stores three number values representing the location the user selected. So now that we hopefully have the point from the user we need to make sure the user selected the point using the If/Then and TypeOf to make sure the user selected a point.

image

If it is we create a variable for an Aeccpoint and set it equal to the oAcadObj. We'll also add an Else to tell the user what he did wrong.

image

So now have the point we'll send the point information to the command line using the prompt Method of the Utility object.

image

So that's almost it. Just add some error catching, maybe an "On Error Resume Next" at the top or an "On Error Resume Next" above the GetEntity line and an "On Error Go to 0" to turn it off in case the user doesn't select an object and around the Description line if the point doesn't have a description assigned which will also cause an error.

The completed VBA may be found on this page: http://style.civil3dreminders.com/programming

3 comments:

Anonymous said...

I know this is "old school" at this point, but for some of us, its a comfort zone issue.
Can someone explain why I cannot query the point number, its style, its label style?
We are just starting on our Civil 3D journey and with all of the survey point styles and label styles, the users need to be able to quickly find some of these values. Most will need to control point display through layers. Since we are starting with a new layers standard, it will take time for them to get used to these and turning on and off point layers requires one to be able to quickly see the layers involved.
BTW, I need to have this in 2009 and newer as we have projects in all versions.

Anonymous said...

I know this is "old school" at this point, but for some of us, its a comfort zone issue.
Can someone explain why I cannot query the point number, its style, its label style?
We are just starting on our Civil 3D journey and with all of the survey point styles and label styles, the users need to be able to quickly find some of these values. Most will need to control point display through layers. Since we are starting with a new layers standard, it will take time for them to get used to these and turning on and off point layers requires one to be able to quickly see the layers involved.
BTW - This is need in 2009-2013 as we have projects in all versions.

Christopher Fugitt said...

It might be best to embrace point groups to help show or hide the points instead of layers.

LinkWithin

Blog Widget by LinkWithin

Ad