Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Civil 3D 2013 Net CogoPointCollection

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Edoc13
680 Views, 12 Replies

Civil 3D 2013 Net CogoPointCollection

Okay so what am I'm doing wrong.

 

                Dim CompPt As New Point3d(Easting, Northing, Elevation) 'Easting, Northing, Elevation declared as Double

                MsgBox(CompPt.X) 'Valid Message
                MsgBox(CompPt.Y) 'Valid Message
                MsgBox(CompPt.Z) 'Valid Message

 

                Dim i As Integer = CogoPoints.Count
                MsgBox(i) 'Yes that's how many points i.e. confirms link to collection.

 

                Dim pointId As ObjectId = CogoPoints.Add(CompPt) ' ***** CRASH!!! *******

 

Any help whatsoever would be appreciated.

Thanks in advance.

 

Civil 3D 2013 SP1

Win7

12 REPLIES 12
Message 2 of 13
Ed.McGriskin
in reply to: Edoc13

Not sure if the CogoPoint.Add() returns an object ID. Maybe try this

 

CogoPoints.Add(CompPt)

Dim pointID as ObjectID = CogoPoints(i).ObjectID

Ed McGriskin, P.Eng.
Project Engineer @ HUSSON
Remember to accept the solution so others can find the solution also.
Message 3 of 13
Jeff_M
in reply to: Edoc13

What is the error given? Have you tried to enclose it in a Try/Catch to trap the error so you can get an idea why?

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 13
Jeff_M
in reply to: Jeff_M

Just as a quick test, I tried this very simple code snip (sorry, c#) but it works fine in 2013 SP1. So my guess is there is something else in your code affecting this.

 

        [CommandMethod("TestAddPt")]
        public void testaddpt()
        {
            CivilDocument doc = CivilApplication.ActiveDocument;
            AcDb.ObjectId ptId = doc.CogoPoints.Add(new Autodesk.AutoCAD.Geometry.Point3d(0.0, 10.0, 5.0));
        }

 

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 13
Edoc13
in reply to: Jeff_M

Well I don't believe it's my code.
I tried both of the following and after MsgBox(i) of "2" (two points in my test.dwg) AutoCAD crashes.
I added MsgBox("Test") to confirm it wasn't an error further down the road.

 

                MsgBox(i)
                Try
                    CogoPoints.Add(CompPt)
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
                MsgBox("Test")
    
    
    MsgBox(i)
                Try
                    CogoPoints.Add(CompPt)
                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    MsgBox(ex.Message)
                End Try    
       MsgBox("Test")

Message 6 of 13
Ed.McGriskin
in reply to: Edoc13

Would definitely be easier to diagnose the problems if we saw more of the code. I am guessing you are running a loop of some kind to add some points to your drawing. 

Ed McGriskin, P.Eng.
Project Engineer @ HUSSON
Remember to accept the solution so others can find the solution also.
Message 7 of 13
Edoc13
in reply to: Ed.McGriskin

    Private Sub Button_COMP_Click(sender As Object, e As EventArgs) Handles Button_COMP.Click
        Dim m_doc As CivilDocument = Nothing
        Dim m_trans As Transaction = Nothing
        Dim m_Database As Database = Nothing
        Dim m_Editor As Editor = Nothing
        Dim docCol As Autodesk.AutoCAD.ApplicationServices.DocumentCollection = Application.DocumentManager
        m_Database = docCol.MdiActiveDocument.Database
        m_Editor = docCol.MdiActiveDocument.Editor
        m_doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument()

        Dim CogoPoints As CogoPointCollection = m_doc.CogoPoints
        'Confirmed as valid link to CogoPointCollection

        Dim oAlignments As ObjectIdCollection
        oAlignments = m_doc.GetAlignmentIds

        Dim b As Boolean
        b = False
        Dim s As String

        Dim oAlignment As Alignment = Nothing  'Alignment used for comps.
        Dim oProfile As Profile = Nothing 'Profile for 3D comps (see b2D_Comps)
        Dim b2D_Comps As Boolean = False

        Dim dSta As Double
        Dim sRawSta As String

        Dim Northing As Double
        Dim Easting As Double
        Dim Elevation As Double

        Dim dOffset As Double 'Offset for point calculations i.e. Alignment + Hub Offset
        If TextBox_ALIGNOFF.Text = "" Then
            TextBox_ALIGNOFF.Text = "0.00"
        End If
        If TextBox_HUBOFF.Text = "" Then
            TextBox_HUBOFF.Text = "0.00"
        End If
        dOffset = Double.Parse(TextBox_ALIGNOFF.Text) + Double.Parse(TextBox_HUBOFF.Text)

        Dim dElevMod As Double
        If TextBox_ELEV_MOD.Text = "" Then
            TextBox_ELEV_MOD.Text = "0.00"
        End If
        dElevMod = Double.Parse(TextBox_ELEV_MOD.Text)

        m_trans = m_Database.TransactionManager.StartTransaction()

        'Set oAlignment
        For Each ObjId As ObjectId In oAlignments
            oAlignment = m_trans.GetObject(ObjId, OpenMode.ForRead)
            If oAlignment.Name = ComboBox_ALIGN.Text Then
                b = True
                Exit For
            End If
        Next

        If b = False Then
            MsgBox("Alignment not defined.", MsgBoxStyle.Exclamation)
            Exit Sub
        End If

        'Set oProfile or b2D_Comps
        If ComboBox_Profiles.Text = "" Then
            s = "Profile NOT Set." + vbCrLf + "Points are 2D?"
            Dim Answer As MsgBoxResult = MsgBox(s, MsgBoxStyle.YesNo)
            If Answer = MsgBoxResult.Yes Then
                b2D_Comps = True
            Else
                Exit Sub
            End If
        Else
            b = False
            Dim oProfiles As ObjectIdCollection
            oProfiles = oAlignment.GetProfileIds
            For Each ObjIdPro As ObjectId In oProfiles
                oProfile = m_trans.GetObject(ObjIdPro, OpenMode.ForRead)
                If oProfile.Name = ComboBox_Profiles.Text Then
                    b = True
                    Exit For
                End If
            Next
        End If

        'Left side comps
        If RadioButton_L.Checked = True Or RadioButton_B.Checked = True Then

            Dim dOffsetL As Double
            dOffsetL = dOffset * (-1)

            For Each row In DataGridView_STAOFF.Rows
                dSta = Double.Parse(row.Cells(0).Value)
                sRawSta = row.Cells(1).Value
                If RadioButton_B.Checked = True Then
                    sRawSta = sRawSta.Replace("L_R", "L")
                End If

                oAlignment.PointLocation(dSta, dOffsetL, Easting, Northing)

                If b2D_Comps = True Then
                    Elevation = 0
                Else
                    Elevation = oProfile.ElevationAt(dSta) + dElevMod
                End If

                Dim CompPt As New Point3d(Easting, Northing, Elevation)
                'MsgBox(CompPt.X)
                'MsgBox(CompPt.Y)
                'MsgBox(CompPt.Z)

                Dim i As Integer = CogoPoints.Count
                MsgBox(i) '************************************************CRASHES AFTER THIS*************************

                Try
                    CogoPoints.Add(CompPt)
                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    MsgBox(ex.Message)
                End Try
                MsgBox("Test")

                'Dim cogoPoint As CogoPoint = TryCast(pointId.GetObject(OpenMode.ForWrite), CogoPoint)
                'cogoPoint.RawDescription = sRawSta


            Next
        End If 'Left side comps

 

Message 8 of 13
Edoc13
in reply to: Edoc13

Transactions are kindof new to me so maybe that is my problem.

 

Message 9 of 13
Jeff_M
in reply to: Edoc13

Transactions must be disposed. THe best way to handle them is to place them in a Using block:

Using m_trans As Transaction
  ....your code
  m_trans.Commit()
End Using

 However, I'm not so sure that is the issue with your code. I changed the sample Iposted to add 10 points and it does so without issue, so there must be something occurring when you code is execting that you aren't seeing. If you could provide a working solution (so I don't have to recreate your form) and a test drawing, I would be willing to help you track it down.

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 13
Edoc13
in reply to: Jeff_M

Okay, I modified the WinForm so you don't have to select a alignment or profile if you use the drawing included.

On the right hand size:

Enter a zero in the RichTextBox, press the Add Stations button and then press the COMPUTE POINTS button.

 

Okay, I can't attach a 647KB zip file.

Message 11 of 13
Jeff_M
in reply to: Edoc13

You can email it to me if you like: jeffm AT quuxsoft DOT com

 

Jeff_M, also a frequent Swamper
EESignature
Message 12 of 13
Jeff_M
in reply to: Edoc13

OK, not sure why I didn't think of this before. When manipulating the drawing's database from inside a Modeless dialog you must Lock the Document. Again, this is easiest done with a Using block. I removed the m_trans DIm from above then modified the code like so and it works without crashing:

        Using doclock As DocumentLock = docCol.MdiActiveDocument.LockDocument()

            Using m_trans As Transaction = m_Database.TransactionManager.StartTransaction()

                'Set oAlignment
                For Each ObjId As ObjectId In oAlignments
                    oAlignment = m_trans.GetObject(ObjId, OpenMode.ForRead)
                    If oAlignment.Name = ComboBox_ALIGN.Text Then
                        b = True
                        Exit For
                    End If
                Next

                If b = False Then
                    MsgBox("Alignment not defined.", MsgBoxStyle.Exclamation)
                    Exit Sub
                End If

                'Set oProfile or b2D_Comps
                If ComboBox_Profiles.Text = "" Then
                    s = "Profile NOT Set." + vbCrLf + "Points are 2D?"
                    Dim Answer As MsgBoxResult = MsgBox(s, MsgBoxStyle.YesNo)
                    If Answer = MsgBoxResult.Yes Then
                        b2D_Comps = True
                    Else
                        Exit Sub
                    End If
                Else
                    b = False
                    Dim oProfiles As ObjectIdCollection
                    oProfiles = oAlignment.GetProfileIds
                    For Each ObjIdPro As ObjectId In oProfiles
                        oProfile = m_trans.GetObject(ObjIdPro, OpenMode.ForRead)
                        If oProfile.Name = ComboBox_Profiles.Text Then
                            b = True
                            Exit For
                        End If
                    Next
                End If

                'Left side comps
                If RadioButton_L.Checked = True Or RadioButton_B.Checked = True Then

                    Dim dOffsetL As Double
                    dOffsetL = dOffset * (-1)

                    For Each row In DataGridView_STAOFF.Rows
                        dSta = Double.Parse(row.Cells(0).Value)
                        sRawSta = row.Cells(1).Value
                        If RadioButton_B.Checked = True Then
                            sRawSta = sRawSta.Replace("L_R", "L")
                        End If

                        oAlignment.PointLocation(dSta, dOffsetL, Easting, Northing)

                        If b2D_Comps = True Then
                            Elevation = 0
                        Else
                            Elevation = oProfile.ElevationAt(dSta) + dElevMod
                        End If

                        Dim CompPt As New Point3d(Easting, Northing, Elevation)
                        'CompPt is valid!

                        'MsgBox(CompPt.X)
                        'MsgBox(CompPt.Y)
                        'MsgBox(CompPt.Z)

                        Dim i As Integer = CogoPoints.Count
                        MsgBox(i)

                        'Dim pointId As ObjectId = cgPoints.Add(CompPt, sRawSta)
                        'Dim pointId As ObjectId = CogoPoints.Add(CompPt) '**************************Doesn't like it!

                        Try
                            CogoPoints.Add(CompPt)
                        Catch ex As System.Exception
                            MsgBox(ex.Message)
                        End Try
                        MsgBox("Test")

                        'Dim cogoPoint As CogoPoint = TryCast(pointId.GetObject(OpenMode.ForWrite), CogoPoint)
                        'cogoPoint.RawDescription = sRawSta


                    Next
                End If 'Left side comps
                m_trans.Commit()
            End Using ''disposes Transaction
        End Using ''disposes DocumentLock

 

Jeff_M, also a frequent Swamper
EESignature
Message 13 of 13
Edoc13
in reply to: Jeff_M

Thanks Jeff Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report