Author Topic: C3D Survey Figures - sample code?  (Read 8891 times)

0 Members and 1 Guest are viewing this topic.

surveyor_randy

  • Guest
C3D Survey Figures - sample code?
« on: July 24, 2014, 08:22:55 AM »
Good Morning Everyone,
I've googled and googled and I can't find any sample code on working with survey figures in the survey database.  In particular, I'm trying to delete a selected figure from the database and I'd also like to know how to toggle the "breakline" attribute for a selected survey figure.

Does anyone have any code they would like to share or could you send me a link to some sample code?  I would greatly appreciate it!

Thanks!

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: C3D Survey Figures - sample code?
« Reply #1 on: July 24, 2014, 09:20:33 AM »
I think Survey Figures are kind of Featurelines and for that there is no (or almost no) API.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

surveyor_randy

  • Guest
Re: C3D Survey Figures - sample code?
« Reply #2 on: July 24, 2014, 09:41:32 AM »
You are correct, they are essentially feature lines.  And I can cast or ctype selected survey figures to feature lines but that doesn't help me with manipulating the survey database.

sdunn

  • Newt
  • Posts: 90
Re: C3D Survey Figures - sample code?
« Reply #3 on: July 24, 2014, 11:12:01 AM »
I think you are looking for the IsBreakline property of the figure in the database.  You would need to get the figure collection, then the individual figure to set the property.

I haven't found an example for this, but you could do something similar to these:

http://adndevblog.typepad.com/infrastructure/2013/11/how-to-access-the-autocad-civil-3d-survey-database-in-net-application.html

http://adndevblog.typepad.com/infrastructure/2013/08/accessing-survey-database-points-using-autocad-civil-3d-com-api.html

surveyor_randy

  • Guest
Re: C3D Survey Figures - sample code?
« Reply #4 on: July 24, 2014, 02:38:55 PM »
Well, here is what I've tried (by using the samples I've found and using piecework code):
Code: [Select]
Public Sub ChangesSurveyFigureToNonBreakline()
            Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Dim oAcadApp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
            Dim oAeccSurveyApp As Autodesk.AECC.Interop.UiSurvey.AeccSurveyApplication = Nothing
            Dim oAeccSurveyDoc As Autodesk.AECC.Interop.UiSurvey.AeccSurveyDocument = Nothing
            Dim oAeccSurveyDB As Autodesk.AECC.Interop.Survey.AeccSurveyDatabase = Nothing
            Dim opt1 As New PromptEntityOptions(vbCrLf & "Select survey figure to change to non-breakline: ")
            opt1.SetRejectMessage(vbCrLf & "error!")
            opt1.AppendKeywordsToMessage = False
            opt1.AddAllowedClass(GetType(SurveyFigure), True)

            Dim Res1 As PromptEntityResult = ed.GetEntity(opt1)

            If (Res1.Status = PromptStatus.OK) Then 'single item picked
                Using trans As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
                    Try
                        If oAcadApp Is Nothing Then
                            oAcadApp = GetObject(, "AutoCAD.Application")
                        End If

                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        ed.WriteMessage(ex.Message)
                    End Try

                    Try
                        oAeccSurveyApp = oAcadApp.GetInterfaceObject("AeccXUiSurvey.AeccSurveyApplication.10.3")
                        oAeccSurveyDoc = oAeccSurveyApp.ActiveDocument
                        oAeccSurveyDB = oAeccSurveyApp.ActiveDocument.Database

                        Dim ent As Autodesk.AutoCAD.DatabaseServices.Entity = trans.GetObject(Res1.ObjectId, OpenMode.ForRead)
                        Dim oFigure As IAeccSurveyFigure = TryCast(ent, IAeccSurveyFigure)

                        oFigure.IsBreakline = False
                        oFigure.Save()

                        trans.Commit()

                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        ed.WriteMessage("Error : ", ex.Message & vbCrLf)
                    End Try
                End Using
            End If
        End Sub

This doesn't work, I get a fatal exception error at the point I try to set the IsBreakline property.  I'm sure I'm not handling the interop properly.  Any suggestions?  Thanks for all the replies guys!  :-)

surveyor_randy

  • Guest
Re: C3D Survey Figures - sample code?
« Reply #5 on: July 24, 2014, 04:07:52 PM »
This code works, although only on a hardcoded figure item:

Code: [Select]
Public Sub ChangesSurveyFigureToNonBreakline()
            Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Dim oAcadApp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
            Dim oAeccSurveyApp As Autodesk.AECC.Interop.UiSurvey.AeccSurveyApplication = Nothing
            Dim oAeccSurveyDoc As Autodesk.AECC.Interop.UiSurvey.AeccSurveyDocument = Nothing
            Dim oAeccSurveyDB As Autodesk.AECC.Interop.Survey.AeccSurveyDatabase = Nothing
            Dim opt1 As New PromptEntityOptions(vbCrLf & "Select survey figure to change to non-breakline: ")
            opt1.SetRejectMessage(vbCrLf & "error!")
            opt1.AppendKeywordsToMessage = False
            opt1.AddAllowedClass(GetType(SurveyFigure), True)

            Dim Res1 As PromptEntityResult = ed.GetEntity(opt1)

            If (Res1.Status = PromptStatus.OK) Then 'single item picked
                Using trans As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
                    Try
                        If oAcadApp Is Nothing Then
                            oAcadApp = GetObject(, "AutoCAD.Application")
                        End If

                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        ed.WriteMessage(ex.Message)
                    End Try

                    Try
                        oAeccSurveyApp = oAcadApp.GetInterfaceObject("AeccXUiSurvey.AeccSurveyApplication.10.3")
                        oAeccSurveyDoc = oAeccSurveyApp.ActiveDocument
                        oAeccSurveyDB = oAeccSurveyApp.ActiveDocument.Database

                        Dim oProjects As AeccSurveyProjects = CType(oAeccSurveyDB.Projects, AeccSurveyProjects)

                        Dim z As AeccSurveyProject = oProjects.Item(0)
                        Dim oSurveyFigure As AeccSurveyFigure = z.Figures.Item(1)

                        oSurveyFigure.IsBreakline = False
                        oSurveyFigure.Save()
                        oSurveyFigure.Reload()

                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        ed.WriteMessage("Error : ", ex.Message & vbCrLf)
                    End Try
                End Using
            End If
        End Sub

is there any way to determine what the item number would be for a selected entity?  I could search for a name but I use the same name for multiple survey figures (ex: EP, TBC)

I thought of casting the selected entity to a survey figure and getting the ID of the entity, but I don't think that has any relation to the ITEM key.

surveyor_randy

  • Guest
Re: C3D Survey Figures - sample code?
« Reply #6 on: July 25, 2014, 09:37:19 AM »
This code does what I want, although it iterates through all of the figures instead of just using the figure I select:

Code: [Select]
Public Sub ChangesSurveyFigureToNonBreakline()
            Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Dim oAcadApp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
            Dim oAeccSurveyApp As Autodesk.AECC.Interop.UiSurvey.AeccSurveyApplication = Nothing
            Dim oAeccSurveyDoc As Autodesk.AECC.Interop.UiSurvey.AeccSurveyDocument = Nothing
            Dim oAeccSurveyDB As Autodesk.AECC.Interop.Survey.AeccSurveyDatabase = Nothing
            Dim opt1 As New PromptEntityOptions(vbCrLf & "Select survey figure to change to non-breakline: ")
            opt1.SetRejectMessage(vbCrLf & "error!")
            opt1.AppendKeywordsToMessage = False
            opt1.AddAllowedClass(GetType(SurveyFigure), True)

            Dim Res1 As PromptEntityResult = ed.GetEntity(opt1)

            If (Res1.Status = PromptStatus.OK) Then
                Using trans As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
                    Try
                        If oAcadApp Is Nothing Then
                            oAcadApp = GetObject(, "AutoCAD.Application")
                        End If

                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        ed.WriteMessage(ex.Message)
                    End Try

                    Try
                        oAeccSurveyApp = oAcadApp.GetInterfaceObject("AeccXUiSurvey.AeccSurveyApplication.10.3")
                        oAeccSurveyDoc = oAeccSurveyApp.ActiveDocument
                        oAeccSurveyDB = oAeccSurveyApp.ActiveDocument.Database

                        Dim oEnt As Autodesk.AutoCAD.DatabaseServices.Entity = trans.GetObject(Res1.ObjectId, OpenMode.ForRead)
                        Dim TmpFigure As SurveyFigure = TryCast(oEnt, SurveyFigure)

                        Dim oSF As SurveyFigure = nothing

                        Dim oCurrentProject As AeccSurveyProject = oAeccSurveyDB.CurrentProject

                        For i As Integer = 0 To oCurrentProject.Figures.Count - 1
                            Dim oSurveyFigure As AeccSurveyFigure = oCurrentProject.Figures.Item(i)

                            Dim FigureId As ObjectId = New ObjectId(New IntPtr(oSurveyFigure.GetObjectId))
                            oSF = TryCast(trans.GetObject(FigureId, OpenMode.ForRead), SurveyFigure)

                            If oSF.Id = TmpFigure.Id Then
                                oSurveyFigure.IsBreakline = False
                                oSurveyFigure.Save()
                            End If

                        Next

                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        ed.WriteMessage("Error : ", ex.Message & vbCrLf)
                    End Try
                End Using
            End If
        End Sub

I'm still at a loss with deleteing a figure from the database though.  I see the erase method in the .net SurveyFigure object but it only appears to erase it from modelspace and not the database?

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: C3D Survey Figures - sample code?
« Reply #7 on: July 25, 2014, 10:05:06 AM »
If you debug, can you read the properties of the TmpFigure to see if there is a database connection id or something?
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

surveyor_randy

  • Guest
Re: C3D Survey Figures - sample code?
« Reply #8 on: July 25, 2014, 11:46:59 AM »
unfortunately, I'm using VB 2010 Express and don't have the start option to allow debugging.  :-(

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: C3D Survey Figures - sample code?
« Reply #9 on: July 25, 2014, 12:43:02 PM »
Yes you do :-)

I've used VB.NET Express in the past and you can debug. See here for more details: http://through-the-interface.typepad.com/through_the_interface/2006/07/debugging_using.html
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

surveyor_randy

  • Guest
Re: C3D Survey Figures - sample code?
« Reply #10 on: July 25, 2014, 01:23:26 PM »
Cool, thanks for the tip.  I was unaware of that!  :-)

I looked at the properties of TmpFigure and see database (Autodesk.Autocad.DatabaseServices.database) but I do not see any connection ID or anything under that.  The only thing I see even close to it is a BlockTableID.

Thanks for you help!

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: C3D Survey Figures - sample code?
« Reply #11 on: July 25, 2014, 01:56:49 PM »
I don't know if you can find information in the Survey Figure. I think Civil 3D compares the handle or Id with records in the database. If I snoop a figure I can not find any relevant information. I only see some info in Civil 3D if I have a database open (or available). If I delete a database, even Civil 3D is not able to show me where it came from.

The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

surveyor_randy

  • Guest
Re: C3D Survey Figures - sample code?
« Reply #12 on: July 25, 2014, 02:22:24 PM »
I agree...  I don't think the objects in the drawing are directly connected to the database.  When you make a change in the database, it probably looks for the survey figure in the drawing and updates it.  If I iterate through the items in the survey database, I can find it by comparing object IDs but I don't think the method to remove it is exposed.  My guess would be the only way to delete them from the survey database would be to create a msSQL hook into the database and purge it that way.
« Last Edit: July 25, 2014, 03:16:04 PM by surveyor_randy »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C3D Survey Figures - sample code?
« Reply #13 on: July 25, 2014, 03:20:09 PM »
Randy, I'm on vacation without a lot of time to play around with this, but.....
If you get the ObjectID (the COM ID, I think) from the selected figure in the drawing, then loop through the AeccSurveyFigures collection in the Survey Database and use the IsInDrawing() and GetObjectId() methods to compare the selected ObjectId with. Then you can get the ID to use in the AeccSurveyFigures.Remove(ID) method.

Hope that helps!

surveyor_randy

  • Guest
Re: C3D Survey Figures - sample code?
« Reply #14 on: July 25, 2014, 03:25:46 PM »
There he is!  Thanks Jeff, I'll look at that later today.  Have a great vacation!  :-)