Having a table update dynamically when contents are moved using .NET

Having a table update dynamically when contents are moved using .NET

QNashJSRL8
Contributor Contributor
733 Views
8 Replies
Message 1 of 9

Having a table update dynamically when contents are moved using .NET

QNashJSRL8
Contributor
Contributor

If I move an alignment that is in the alignment table, C3D will adjust the table values based on how the alignment moved.

(*EDIT NOTE: For clarity this first pair of images is what happens when clicking and dragging an alignment with the mouse. I want to emulate this behavior when moving an alignment autonomously using .NET. The second set of images shows, below the VB .NET code I have given, shows the alignment has been transformed by the code, but the table did not auto update itself to the alignments new values)

 

QNashJSRL8_0-1739230262701.png

Above table pre move
Below table post move

QNashJSRL8_1-1739230321175.png


So if I move the alignment the table updates. I want the table to be updated when moved from code. I.e) when I adjust the alignment in any way. 

Currently I have this. Basically I look through everything, find the alignment and transform it then I want to update the table.

 

 

'Globals initlaized else where but so you know what they are
m_docCol = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
m_doc = m_docCol.MdiActiveDocument
m_oDB = m_doc.Database

Using trans As Transaction = m_oDB.TransactionManager.StartTransaction()

    Dim currentSpace As BlockTableRecord = TryCast(
        trans.GetObject(m_oDB.CurrentSpaceId, OpenMode.ForRead), BlockTableRecord
        )

    For Each objId As ObjectId In currentSpace
        Dim ent As Autodesk.AutoCAD.DatabaseServices.Entity = TryCast(
            trans.GetObject(objId, OpenMode.ForRead),
            Autodesk.AutoCAD.DatabaseServices.Entity
            )

        If TypeOf ent Is Alignment Then
            Dim test As Alignment = TryCast(
                ent, Alignment
                )

            ' Create a transformation matrix for the move
            Dim moveVec As New Vector3d(100, 200, 0) ' Change these values to your desired X,Y,Z offset
            Dim transform As Matrix3d = Matrix3d.Displacement(moveVec)

            test.TransformBy(transform)


        End If

        If TypeOf ent Is Autodesk.Civil.DatabaseServices.Table Then
            Dim table As Autodesk.Civil.DatabaseServices.Table = TryCast(
                ent, Autodesk.Civil.DatabaseServices.Table
                )

            ' Check for specific table types
            Select Case True
                Case TypeOf table Is PointTable
                    m_doc.Editor.WriteMessage(vbCrLf & "Found Point table: " & table.Description)

                Case TypeOf table Is ParcelTable
                    m_doc.Editor.WriteMessage(vbCrLf & "Found Parcel table: " & table.Description)

                Case TypeOf table Is AlignmentTable
                    m_doc.Editor.WriteMessage(vbCrLf & "Found Alignment table: " & table.Description)

            End Select
        End If
    Next

    trans.Commit()

End Using

 

 

 

 Here is the current outcome
QNashJSRL8_0-1739230262701.png
above is pre code, below is post code. The tables are identical even though the alignment has been altered.

QNashJSRL8_2-1739230557536.png

The alignment is moved, but the table is not changed.

Is there a way to get the outcome I am looking for.

Again, I want to be able to move items that are linked to tables and have the table auto update, which is currently what happens when moving items within cad itself. However, I want to get that same behavior when the alignment is modified in code.

0 Likes
Accepted solutions (1)
734 Views
8 Replies
Replies (8)
Message 2 of 9

Jeff_M
Consultant
Consultant

The pre and post code images are different...you said they are identical...so it appears the table does update as one would expect.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 9

QNashJSRL8
Contributor
Contributor

Are you looking at the second set of images? 

I believe you may have only saw the first set of images which was moving the alignment with mouse. The second set of images has identical tables with different alignments.

I edited my original post to make it clearer.

0 Likes
Message 4 of 9

hippe013
Advisor
Advisor

@QNashJSRL8 You may want to post your code in its entirety. You may not think something is pertinent to your question, when in fact in might be the cause of the issue. How are you invoking your code? Are you using a dialog box? Winform or WPF? Is it modal or modeless? Or are you invoking from a command? I just tested editing the geometry of an Alignment using .NET and my table updated, as expected, without any additional calls to update or regen the table.

Message 5 of 9

QNashJSRL8
Contributor
Contributor

It is being invoke with a Command Method. 

We have a .dll that is loaded into cad. And when giving a command line argument.

 

Public Sub InitializeCivilDrv()

    m_oDocument = CivilApplication.ActiveDocument()
    m_docCol = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
    m_doc = m_docCol.MdiActiveDocument
    m_oDB = m_doc.Database
    m_tm = m_doc.Database.TransactionManager
    m_ed = m_doc.Editor

End Sub 


<CommandMethod("Banana")>
 Public Sub Banana()
     'TODO learn things

     InitializeCivilDrv()

     Using trans As Transaction = m_oDB.TransactionManager.StartTransaction()

         Dim currentSpace As BlockTableRecord = TryCast(
             trans.GetObject(m_oDB.CurrentSpaceId, OpenMode.ForRead), BlockTableRecord
             )

         For Each objId As ObjectId In currentSpace
             Dim ent As Autodesk.AutoCAD.DatabaseServices.Entity = TryCast(
                 trans.GetObject(objId, OpenMode.ForRead),
                 Autodesk.AutoCAD.DatabaseServices.Entity
                 )

             If TypeOf ent Is Alignment Then
                 Dim test As Alignment = TryCast(
                     ent, Alignment
                     )

                 ' Create a transformation matrix for the move
                 Dim moveVec As New Vector3d(100, 200, 0) ' Change these values to your desired X,Y,Z offset
                 Dim transform As Matrix3d = Matrix3d.Displacement(moveVec)

                 test.TransformBy(transform)


             End If

             If TypeOf ent Is Autodesk.Civil.DatabaseServices.Table Then
                 Dim table As Autodesk.Civil.DatabaseServices.Table = TryCast(
                     ent, Autodesk.Civil.DatabaseServices.Table
                     )

                 ' Check for specific table types
                 Select Case True
                     Case TypeOf table Is PointTable
                         m_doc.Editor.WriteMessage(vbCrLf & "Found Point table: " & table.Description)

                     Case TypeOf table Is ParcelTable
                         m_doc.Editor.WriteMessage(vbCrLf & "Found Parcel table: " & table.Description)

                     Case TypeOf table Is AlignmentTable
                         m_doc.Editor.WriteMessage(vbCrLf & "Found Alignment table: " & table.Description)

                        
                 End Select
             End If
         Next

         trans.Commit()

     End Using

 End Sub

 

 

0 Likes
Message 6 of 9

hippe013
Advisor
Advisor
Accepted solution

The problem is that you are opening all of the entities for read. You then cast your entity to an alignment and you make changes to it without upgrading it to open. And although the changes you make do get committed you didn't open it up for write. 

 

Add the following prior to making changes to the alignment.

test.UpgradeOpen;

 

Message 7 of 9

QNashJSRL8
Contributor
Contributor

Thank you, sir! That worked.

It is often something small that is missing.

0 Likes
Message 8 of 9

Jeff_M
Consultant
Consultant

@QNashJSRL8 It appears that the new forum is the culprit here. I could not read the images inline in the post so I clicked on the bottom one to get a larger view of it. I then clicked the left side arrow to get to the previous image, which should have been the one just above it. Evidently the images are arranged by name or something, and not as they are displayed in the post, since I was seeing the identical image as I went back and forth between them. Sorry for questioning it...

Jeff_M, also a frequent Swamper
EESignature
Message 9 of 9

hippe013
Advisor
Advisor

@Jeff_M same thing happened to me. I clicked on one image and then tried to use the arrows to navigate the images. I got lost as to where I was.