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: 

Showing a Form makes objects locked.

2 REPLIES 2
Reply
Message 1 of 3
RodWing
238 Views, 2 Replies

Showing a Form makes objects locked.

I checked off the solution on my previous post too soon. This really shouldn't be that difficult, but this has still got me stumped.

 

I've posted another code sample below.

 

When I use the sub StartMacro1 to launch my app everything appears to work fine. Using StartMacro2 displays a form with a single button whose click event calls the ProcessAllAlignments function. Calling the function via the button's click event  causes the trans.GetObject(objID, OpenMode.ForWrite) statement to throw a Locked expection.

 

Any ideas why that is happening?

 

I would also like to perform a trans.Commit() after each alignment object is updated rather than at the end of the For loop. I get an access violation and Civil 3D crashes on me when I try to do that.

 

Thanks.

Rod

 

Public Sub StartMacro1()
ProcessAllAlignments()
End Sub

Public Sub StartMacro2()
myForm.Show()
End Sub

 

Public Function ProcessAllAlignments() As Boolean
Dim objCol As Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection
Dim objID As Autodesk.AutoCAD.DatabaseServices.ObjectId

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

 

ProcessAllAlignments = False

 

Try
objCol = CivilApplication.ActiveDocument.GetAlignmentIds()
Using trans As Transaction = db.TransactionManager.StartTransaction
For Each objID In objCol
Dim algNet As Alignment = trans.GetObject(objID, OpenMode.ForWrite)

 

If algNet.SuperelevationCriticalStations.Count > 0 Then
If Not UpdateSuper(algNet) Then
Exit Function
End If
End If
Next

 

trans.Commit()
trans.Dispose()
End Using

 

ProcessAllAlignments = True
Catch ex As Exception
MsgBox(ex.Message, vbExclamation)
End Try
End Function

 

2 REPLIES 2
Message 2 of 3
Jeff_M
in reply to: RodWing

If you are using a modeless form then you will need to lock the document, this will prevent the eLockViolation. I don't use VB enough to be able to post sample code for you.

 

If you wish to commit after each alignment change, you will need to start a new transaction for each one.

 

 

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 3
MarkPendergraft
in reply to: RodWing

    Public Sub StartMacro1()
        ProcessAllAlignments()
    End Sub

    Public Sub StartMacro2()
        myForm.Show()
    End Sub



    Public Function ProcessAllAlignments() As Boolean
        Dim objCol As Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection
        Dim objID As Autodesk.AutoCAD.DatabaseServices.ObjectId

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

        ProcessAllAlignments = False

        Try
            objCol = CivilApplication.ActiveDocument.GetAlignmentIds()
            Using docLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument


                Using trans As Transaction = db.TransactionManager.StartTransaction
                    For Each objID In objCol
                        Dim algNet As Alignment = trans.GetObject(objID, OpenMode.ForWrite)



                        If algNet.SuperelevationCriticalStations.Count > 0 Then
                            If Not UpdateSuper(algNet) Then
                                Exit Function
                            End If
                        End If
                    Next



                    trans.Commit()
                    trans.Dispose()
                End Using
            End Using

            ProcessAllAlignments = True
        Catch ex As Exception
            MsgBox(ex.Message, vbExclamation)
        End Try
    End Function

 

 

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report