.NET

Reply
Active Contributor
Fredrik.Larsen
Posts: 46
Registered: ‎11-28-2012
Message 1 of 7 (440 Views)
Accepted Solution

Cancel change active document

440 Views, 6 Replies
01-24-2013 06:19 AM

Hi

How can I stop changing active document?

 

I was thinking I could use this, but I don't know how to cancel it in the event handler:

 

AcadApp.DocumentManager.DocumentToBeActivated += new DocumentCollectionEventHandler(DocumentManager_DocumentToBeActivated);

static void DocumentManager_DocumentToBeActivated(object sender, DocumentCollectionEventArgs e)
{
    // Messagebox to ask if user are sure
    bool AreYouSureYouWantToChangeActiveFile = MessageBox....

    if(!AreYouSureYouWantToChangeActiveFile)
        //cancel change active file somehow...???
}

 

1. You can disable switching of Document's at all if you call:

AcadApp.DocumentManager.DocumentActivationEnabled = false;

 but not in handler of event of DocumentToBeActivated.

2. If you have to prevent switching in a handler of event of DocumentToBeActivated you have to:

a) save previous Document and set flag of switching in this handler.

b) in command reactor switch Document back to previous Document and clear flag of switching.

 

Moderator
Alexander.Rivilis
Posts: 1,452
Registered: ‎04-09-2008
Message 2 of 7 (427 Views)

Re: Cancel change active document

01-24-2013 01:47 PM in reply to: Fredrik.Larsen

DocumentCollection.DocumentActivationEnabled property can help you


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Contributor
Fredrik.Larsen
Posts: 46
Registered: ‎11-28-2012
Message 3 of 7 (413 Views)

Re: Cancel change active document

01-25-2013 12:06 AM in reply to: Alexander.Rivilis

Hi

I could not get it to work. When I set the property you mentioned the active document has already changed. And if I set the property to false at a earlier stage I will never come to the listener. Any ideas?

static void DocumentManager_DocumentToBeActivated(object sender, DocumentCollectionEventArgs e)
{
            DialogResult dialogResult = MessageBox.Show("You are changing the active drawing. Continue?", "Active drawing change", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                AcadApp.DocumentManager.DocumentActivationEnabled = true;
                RemoveDocumentToBeActivatedListener();
            }
            else if (dialogResult == DialogResult.No)
            {
                AcadApp.DocumentManager.DocumentActivationEnabled = false;
            }
}

 

Moderator
Alexander.Rivilis
Posts: 1,452
Registered: ‎04-09-2008
Message 4 of 7 (409 Views)

Re: Cancel change active document

01-25-2013 01:23 AM in reply to: Fredrik.Larsen

1. You can disable switching of Document's at all if you call:

AcadApp.DocumentManager.DocumentActivationEnabled = false;

 but not in handler of event of DocumentToBeActivated.

2. If you have to prevent switching in a handler of event of DocumentToBeActivated you have to:

a) save previous Document and set flag of switching in this handler.

b) in command reactor switch Document back to previous Document and clear flag of switching.

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 5 of 7 (382 Views)

Re: Cancel change active document

01-28-2013 01:22 AM in reply to: Fredrik.Larsen

Perhaps you can explain why you want to prevent a document from being activated?

Active Contributor
Fredrik.Larsen
Posts: 46
Registered: ‎11-28-2012
Message 6 of 7 (378 Views)

Re: Cancel change active document

01-28-2013 01:29 AM in reply to: DiningPhilosopher

I have created an application that scans and does something with the active document and I haven't implemented support for what happens when active document is changed. So for my demo version I thought I could just prevent the user from changing the document.

Moderator
Alexander.Rivilis
Posts: 1,452
Registered: ‎04-09-2008
Message 7 of 7 (374 Views)

Re: Cancel change active document

01-28-2013 01:45 AM in reply to: Fredrik.Larsen

While command with CommandFlags.Modal is active user can not switch active document. More precisely when switching to another document, the command will paused and wait for switch back.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.