This post comes from a suggestion from Matt:
“Here is another little tool idea for you.
When some drawings get inserted by others when they make a mistake, the default Civil 3d renaming is to tag a .1 value to the group name. It’s a pain to remove, does the API have a way to remove groups that match those values?”
In this post I’m going to do the down and dirty of getting it the duplicated point groups removed. If you for some reason use “.1” behind the point groups this post won’t work or you’ll have to modify the code to work with how you work.
The code started with the SurfacePointsSample.dvb file that comes with Civil 3D. I deleted most of the items I didn’t need and then added the code below.
The first thing that needs to get done is to cycle through all of the point group objects in the drawing. Next I got the number of characters in the name of the point group, using len function. With this information I can then use the InStr to see if the “.1” is the last two characters of the name of the point group. To do this I use the length of the name string minus 2. This will start the InStr function before last two characters of the point group name. If the name contains the “.1” as the last two characters then cPos will have a value greater than 0. If the condition is met then the point group is deleted.
The only problem with this is that the Toolspace doesn’t refresh. To get the point groups to show up correctly you’ll need to refresh the point groups in the Toolspace.
Sub AddPointsToSurfaceTest()
' Always get the objects again since MDI is supported.
If (GetGlobalCivilObjects() = False) Then
MsgBox "Error accessing root objects."
Exit Sub
End If
Dim oPointGroup As AeccPointGroup
For Each oPointGroup In g_oDocument.PointGroups
Dim sName As String
sName = oPointGroup.Name
Dim cLength As Double
cLength = Len(sName)
Dim cPos As Double
cPos = InStr(cLength - 2, sName, ".1")
If cPos > 0 Then
oPointGroup.Delete
End If
Next
End Sub
Here’s the code in action: http://screencast.com/t/ZWIzYWIxO
If you want to save yourself some time you can purchase the completed code for $5 that works with Civil 3D 2010 and can be easily modified for prior versions using this post.
If you have any problems with getting the file after buying, Email me.
No comments:
Post a Comment