Ad

Sunday, May 31, 2009

How to Create Civil 3D Points for Each DEM Vertex - VBA

In a previous post I went over the steps to create COGO Points from a TIN surface without having to go in and turn on points and then extracting the points from the surface. I used the generic AeccSurface object to do this, which should have worked for other types of surfaces as well. There is a problem in the code when used with DEM surfaces. DEM surfaces tend to have a large amount of points and I was using an integer value when storing the number of points that needed to be added to the drawing. Well an integer value only goes up to 32767 in VBA, which as mentioned previously is easily exceeded with a DEM file. To fix the code the variable type needs to be changed that allows a larger number. In this case I’m going to go with a Double value which goes up to 1.79769313486232 E 308. So just change the Integer to Double and the code should work with DEM files.

image

Saturday, May 30, 2009

Add Point to Point Group – Part III

The last item do in this series of posts is to add the command to the right click menu. The first step is to get the dll file to be loaded or be demand loaded when Civil 3D is run. One way to do this is to add the dll to the registry. I got most of the information from Through the Interface blog. The completed text that I used on my machine is below:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.0\ACAD-8000:409\Applications\C3DRemindersPack]
"DESCRIPTION"="Civil3DRemindersPack"
"LOADCTRLS"=dword:0000000c
"MANAGED"=dword:00000001
"LOADER"="C:\\Program Files (x86)\\AutoCAD Civil 3D 2010\\C3DRemindersPack.dll"

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.0\ACAD-8000:409\Applications\C3DRemindersPack\Commands]
"TIN"="TIN"
"CreateEGSurface"="CreateEGSurface"
"AddPointToPointGroup" = "AddPointToPointGroup"

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.0\ACAD-8000:409\Applications\C3DRemindersPack\Groups]
"ASDK_CMDS"="ASDK_CMDS"

Add the text to a text file and give it an extension of “.reg”. Change the “LOADER” location to match where you put the dll file, making sure to the path has the “\\” instead of “\”. Double click the file and it will add it to the registry. Editing the Windows registry can be dangerous, so beware. I did something wrong when testing it out and had to reinstall the Civil 3D.

Next we need to modify the cui to add the command to the shortcut menu. I unfortunately couldn’t find where to do that in a fresh install. So I downloaded David Garrigues Double and Right Click CUI on the Civil Engineering Community site (additional comments canned regarding this site) and added the right click customization. Follow the directions in the download to add the right click items. David did an excellent job creating them for Civil 3D objects. I believe he did this for Civil 3D 2007, so some of the commands won’t work in Civil 3D 2010.

Once completed go in and add a command to the CUI and it to the Shortcut Menu for the AECC_COGO_POINT.

image

I’ve added some of the other vb.NET posts to the dll file and gave the Pack it’s own webpage:

http://style.civil3dreminders.com/civil3dreminderspack

You can do the same steps above for the Surface Right Click Shortcut Menu, using the TIN and AECC_TIN_SURFACE shortcut. I didn’t set it up for the first pick option, so unfortunately the user will have to reselect the surface.

Friday, May 29, 2009

New CAD Blog

There's a new blog out there, check out: http://cadable.blogspot.com/
Add the blog to your RSS feeder and keep up with all of Andy's posts.

Thursday, May 28, 2009

Add Point to Point Group – Part II

In the last post I provided code on the main part of the code to add a point to a point group. In this post I’ll post some of the steps to create a form that prompts the user for which point group they want to use. The first thing to do is create the form by going to Project on the Menu bar and choosing Add Windows Form.

image 

Then take items from the Toolbox and put it into the form. In my form I used a combo box to hold the list of point groups in the drawing. The button is used to give the user an opportunity to create a new point group.

image

Double clicking any of the buttons lets you go and modify the code. Each part of the form can get some code to do something. The code for this example is below:

   1: Public Class FrmPointGroup



   2:  



   3:     Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click



   4:         g_sName = ComboBox1.Text



   5:         Me.DialogResult = System.Windows.Forms.DialogResult.OK



   6:         Me.Close()



   7:     End Sub



   8:  



   9:     Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click



  10:         Me.DialogResult = System.Windows.Forms.DialogResult.Cancel



  11:         g_sName = "Canceled Entered Into Value"



  12:         Me.Close()



  13:     End Sub



  14:  



  15:     Private Sub FrmPointGroup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



  16:  



  17:     End Sub



  18:  



  19:     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



  20:         Dim sName As String



  21:         sName = GetPointGroupName()



  22:         ComboBox1.Items.Add(sName)



  23:         ComboBox1.SelectedText = sName



  24:     End Sub



  25: End Class



Some of the code that fills up the combo box was in the other post. So now the code is compiled and is ready to go on the programming side. The compiled code may be downloaded here. In the next post I’ll add it to the right click menu in the cui.

Add Point to Point Group – Part I

Sometimes adding a point to a point group can be a bit of pain since you have to go into the Point Group Properties and add it in the Include Tab. This series of posts will go over how to add functionality where you can select a point, right click and have an option to add the point to a point group.
This post used a lot of code from Through The Interface which allows the code to run on a selected object. If an object is not selected then the user is prompted to select a point. The code starting on Line 151 creates a point group in the drawing. This is used in this code to create a point group if a point group does not exist and in a later post when the user selects the Point Group the point should go in.
If you want to try it out before I finish the posts, you can download the compiled file here, type Netload to load the file and type AddPointToPointGroup at the command line to run the code. This code will only work in Civil 3D 2010. I still have to figure out how to modify the right click customization in the cui, so that part won’t work yet.
   1:  



   2: Imports System.Runtime.InteropServices.Marshal



   3: Imports Autodesk.AutoCAD.Runtime



   4: Imports Autodesk.AutoCAD.ApplicationServices



   5: Imports Autodesk.AutoCAD.DatabaseServices



   6: Imports Autodesk.AutoCAD.EditorInput



   7: Imports Autodesk.AutoCAD.Geometry



   8: Imports Autodesk.Civil.DatabaseServices.Styles



   9: Imports Autodesk.Civil.ApplicationServices



  10: Imports Autodesk.Civil.Land.DatabaseServices



  11: Imports AeccLandLib = Autodesk.AECC.Interop.Land



  12: Imports AeccLandUi = Autodesk.AECC.Interop.UiLand



  13: Imports AcadCom = Autodesk.AutoCAD.Interop



  14: Imports System.Security



  15:  



  16: 



  17: Public Class PointGroup



  18:     Implements Autodesk.AutoCAD.Runtime.IExtensionApplication



  19:  



  20:     Private m_doc As CivilDocument = Nothing



  21:     Private m_trans As Transaction = Nothing



  22:     Private m_Database As Database = Nothing



  23:     Private m_Editor As Editor = Nothing



  24:     Private Shared g_oCivil3DDoc As AeccLandUi.AeccDocument = Nothing



  25:  



  26:     Public Shared g_sName As String



  27:  



  28:     Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize



  29:  



  30:     End Sub



  31:  



  32:     Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate



  33:  



  34:     End Sub



  35:  



  36:     Public Sub GetCivilObject()



  37:         Dim docCol As Autodesk.AutoCAD.ApplicationServices.DocumentCollection = Application.DocumentManager



  38:         m_Database = docCol.MdiActiveDocument.Database



  39:         m_Editor = docCol.MdiActiveDocument.Editor



  40:         m_doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument()



  41:         Dim oAcad As AcadCom.AcadApplication



  42:         Dim ACAD_VER As String = "AutoCAD.Application.18"



  43:         Dim CIVIL3D_VER As String = "AeccXUiLand.AeccApplication.7.0"



  44:         oAcad = GetActiveObject(ACAD_VER)



  45:         Dim oCivil3D As AeccLandUi.AeccApplication



  46:         oCivil3D = oAcad.GetInterfaceObject(CIVIL3D_VER)



  47:         If oCivil3D Is Nothing Then



  48:             MsgBox ("Error")



  49:         End If



  50:         g_oCivil3DDoc = oCivil3D.ActiveDocument



  51:     End Sub



  52:  



  53:     <CommandMethod("AddPointToPointGroup", CommandFlags.UsePickSet Or CommandFlags.Redraw Or CommandFlags.Modal)> _



  54:     Public Sub cmdAddPoint()



  55:  



  56:         Dim sName As String



  57:         Try



  58:             'Get Civil 3D application, document and database



  59:             GetCivilObject()



  60:             m_trans = m_Database.TransactionManager.StartTransaction()



  61:             Dim oDoc As Document = Application.DocumentManager.MdiActiveDocument



  62:             Dim ed As Editor = oDoc.Editor



  63:             Try



  64:                 Dim selectionRes As PromptSelectionResult = ed.SelectImplied()



  65:                 If selectionRes.Status = PromptStatus.Error Then



  66:                     ' Ask the user to select points.



  67:                     Dim selectionOpts As New PromptSelectionOptions()



  68:                     selectionOpts.MessageForAdding = vbLf & "Select point to add to Point Group: "



  69:                     selectionRes = ed.GetSelection(selectionOpts)



  70:                 Else



  71:                     ' If there was a pickfirst set, clear it.



  72:                     ed.SetImpliedSelection(New ObjectId(-1) {})



  73:                 End If



  74:  



  75:                 ' If the user hasn't cancelled.



  76:                 If selectionRes.Status = PromptStatus.OK Then



  77:                     ' Take the objects one by one.



  78:                     Dim tr As Transaction = oDoc.TransactionManager.StartTransaction()



  79:                     Try



  80:                         Dim objIds As ObjectId() = selectionRes.Value.GetObjectIds()



  81:                         For Each objId As ObjectId In objIds



  82:                             Dim ent As Entity = DirectCast(tr.GetObject(objId, OpenMode.ForRead), Entity)



  83:                             ' Check to see if the entity is a point.



  84:                             If TypeOf ent Is PointEntity Then



  85:                                 Dim oPointGroups As AeccLandLib.AeccPointGroups



  86:                                 Dim oPoint As PointEntity



  87:                                 oPoint = ent



  88:                                 Dim frm As New FrmPointGroup



  89:                                 oPointGroups = g_oCivil3DDoc.PointGroups



  90:                                 Dim i As Integer



  91:                                 ' Fill out the form with the point group names.



  92:                                 For i = 0 To oPointGroups.Count - 1



  93:                                     If oPointGroups.Item(i).Name = "_All Points" Then



  94:                                         ' Don't do anything



  95:                                     Else



  96:                                         frm.ComboBox1.Items.Add(oPointGroups.Item(i).Name)



  97:                                     End If



  98:                                 Next



  99:                                 If oPointGroups.Count = 1 Then



 100:                                     sName = GetPointGroupName()



 101:                                     frm.ComboBox1.Items.Add(sName)



 102:                                 End If



 103:  



 104:                                 ' Set the combobox to the first item on the list.



 105:                                 frm.ComboBox1.SelectedIndex = 0



 106:                                 Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm)



 107:                                 ' Add the selected point to the indicated point group.



 108:                                 If g_sName = "Canceled Entered Into Value" Then



 109:                                     ' Don't do anything since the user cancled out of the dialog.



 110:                                 Else



 111:                                     Dim oPointGroup As AeccLandLib.AeccPointGroup



 112:                                     oPointGroup = oPointGroups.Item(g_sName)



 113:                                     Dim sIncludeNumbers As String



 114:                                     sIncludeNumbers = oPointGroup.QueryBuilder.IncludeNumbers



 115:                                     If sIncludeNumbers = "" Then



 116:                                         sIncludeNumbers = oPoint.PointNumber



 117:                                     Else



 118:                                         sIncludeNumbers = sIncludeNumbers & "," & oPoint.PointNumber



 119:                                     End If



 120:                                     oPointGroup.QueryBuilder.IncludeNumbers = sIncludeNumbers



 121:                                 End If



 122:  



 123:  



 124:                             End If



 125:                         Next



 126:                         tr.Commit()



 127:                     Catch ex As Autodesk.AutoCAD.Runtime.Exception



 128:                         ed.WriteMessage(ex.Message)



 129:                         tr.Abort()



 130:  



 131:                     End Try



 132:                 End If



 133:             Catch ex As Autodesk.AutoCAD.Runtime.Exception



 134:                 ed.WriteMessage(ex.Message)



 135:             End Try



 136:  



 137:             m_trans.Commit()



 138:  



 139:         Catch ex As Exception



 140:             If m_trans IsNot Nothing Then m_trans.Abort()



 141:         Finally



 142:             If m_trans IsNot Nothing Then m_trans.Dispose()



 143:  



 144:         End Try



 145:  



 146:  



 147:     End Sub



 148:  



 149:  



 150:  



 151:     Public Shared Function GetPointGroupName() As String



 152:         Dim oDoc As Document = Application.DocumentManager.MdiActiveDocument



 153:         Dim ed As Editor = oDoc.Editor



 154:         Try



 155:             ' GetCivilObject()



 156:             Dim pr As PromptResult



 157:             pr = ed.GetString(vbCrLf & "Enter Point Group Name: ")



 158:             If pr.Status = PromptStatus.OK Then



 159:                 Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database



 160:                 Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager



 161:                 

Using myt As Transaction = tm.StartTransaction()

 162:                     Dim oPointGroups As AeccLandLib.AeccPointGroups



 163:                     oPointGroups = g_oCivil3DDoc.PointGroups



 164:                     oPointGroups.Add(pr.StringResult)



 165:                     db.Dispose()



 166:                     myt.Commit()



 167:                 End Using



 168:             End If



 169:             Return pr.StringResult



 170:             Exit Function



 171:             GetPointGroupName = pr.StringResult



 172:         Catch ex As Autodesk.AutoCAD.Runtime.Exception



 173:             ed.WriteMessage(ex.Message)



 174:             GetPointGroupName = "DefaultPointGroupName"



 175:         End Try



 176:         GetPointGroupName = "DefaultPointGroupName"



 177:     End Function



 178: End Class


http://blog.civil3dreminders.com/2009/05/add-point-to-point-group-part-ii.html

LinkWithin

Blog Widget by LinkWithin

Ad