DocumentToBeDeactivated Event

DocumentToBeDeactivated Event

joantopo
Mentor Mentor
1,105 Views
6 Replies
Message 1 of 7

DocumentToBeDeactivated Event

joantopo
Mentor
Mentor
Hi. I want to use this Event: AcadApp.DocumentManager.DocumentToBeDeactivated += callback_documentToBeDeactivated; In this Event, I want to GetAlignments() from active document, although I get this exception within GetAlignments() method. Autodesk.Civil.ApplicationServices.CivilDocument civDoc = default(Autodesk.Civil.ApplicationServices.CivilDocument); civDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument; //obtener el documento de Civil Debugger throws in "civDoc" line: System.NullReferenceException.
Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
0 Likes
Accepted solutions (1)
1,106 Views
6 Replies
Replies (6)
Message 2 of 7

Jeff_M
Consultant
Consultant

I'm pretty sure the CivilApplication's ActiveDocument is released prior to the AutoCad DocumentToBeDeactivated Event fires, this is why you are seeing that exception. The CivilDocument doesn't have any Events to tie to for this.

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

joantopo
Mentor
Mentor
Thanks Jeff. I thought the same. However, with "ToBeDestroyed" event I don´t get that exception. With this event works fine until it must execute Commit(). using (DocumentLock docLock = doc.LockDocument()) { using (Transaction trans = db.TransactionManager.StartTransaction()) { Alignment align = trans.GetObject(alineacion.Id, OpenMode.ForWrite) as Alignment; align.Description = cadenaTotal; trans.Commit(); } //final transmit } //final Lock
Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
0 Likes
Message 4 of 7

joantopo
Mentor
Mentor
but in this case I don´t get any exception. Debugger stop in "transmit()" method.
Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
0 Likes
Message 5 of 7

joantopo
Mentor
Mentor
Hi Jeff. Now, it works fine. There is no problem with ToBeDeactivated unless you close the drawing, but I only wanted it to change between activated document and it works fine. I use other events as: -documentCreated to add for each open drawing or created drawing-->beginSave event. Then,If I save drawing, I can modify before description alignment.
Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
0 Likes
Message 6 of 7

joantopo
Mentor
Mentor

@Jeff_M  hello!

 

I am reviewing this post because I am in the same scenario in my new app.

 

I use both events: DocumentActivated   &   DocumentToBeDeactivated.

 

I have a break point in both events, so when I change the current document, it seems that "DocumentToBeDeactivated" is fired before, but if I have a transaction in that event, I get the exception = NullReferenceException, 

 

  using (Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())

The parameter WorkingDataBase = Null.

 

 

So, it just happens this for Civil Documents? not in AutoCAD documents?

 

I don´t know how to solve this.

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
0 Likes
Message 7 of 7

Jeff_M
Consultant
Consultant
Accepted solution

Have you tried using the Document's database instead?

 

 

        static void DocumentManager_DocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e)
        {
           using (Transaction trans = e.Document.Database.TransactionManager.StartTransaction())
           {
              ;;your code
           }
         }

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes