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: 

DocumentToBeDeactivated Event

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
joantopo
504 Views, 6 Replies

DocumentToBeDeactivated Event

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
6 REPLIES 6
Message 2 of 7
Jeff_M
in reply to: joantopo

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
Message 3 of 7
joantopo
in reply to: Jeff_M

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
Message 4 of 7
joantopo
in reply to: joantopo

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
Message 5 of 7
joantopo
in reply to: joantopo

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
Message 6 of 7
joantopo
in reply to: joantopo

@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
Message 7 of 7
Jeff_M
in reply to: joantopo

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

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report