Author Topic: how to control when switch out to other drawing (c++ object arx)  (Read 1578 times)

0 Members and 1 Guest are viewing this topic.

binh_nx

  • Guest
Hi.
I'm a new member, I have a issue and need your help:
I'm working on drawing1.dwg. And I want that when user switch out to other drawing (drawing2.dwg) or create a new drawing,
application will show "yes/no" option for user.

If Yes, drawing2.dwg will be activated.

If No, keep working on drawing1.dwg.

Please tell me, how can I do?

Thank.

MickD

  • Gator
  • Posts: 2948
  • I don't need a job, I need Money!!
Re: how to control when switch out to other drawing (c++ object arx)
« Reply #1 on: March 16, 2016, 04:48:22 pm »
Changing drawings is more of an Application thing rather than a Database event as you are changing Document instances.

Have a look into the AcApDocManagerReactor Methods in the ARX reference doc's, the AcApDocManagerReactor::documentToBeActivated may be what you are looking for.

Welcome to The Swamp :)
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

binh_nx

  • Guest
Re: how to control when switch out to other drawing (c++ object arx)
« Reply #2 on: March 17, 2016, 03:04:32 am »
Hi MickD,
I have tried as you say, but it doesn't seems to work.
Do I have some mistake ?

This is my Code:

// show "yes/no" question to user
void AsdkDataManager::documentToBeDeactivated(AcApDocument* doc)
{
   // show message      
   m_bSwitchOutToOtherDrawing = true;
   m_sFileNameBeDeactivated = _T("\0");
   CString sMsg = _T("Do you want to switch to other drawing?");
   if(AfxMessageBox(sMsg, MB_YESNO | MB_ICONQUESTION) == IDYES)
   {
      m_bSwitchOutToOtherDrawing = true; // switch to other drawing
   }
   else
   {
      m_bSwitchOutToOtherDrawing = false; // don't switch
      m_sFileNameBeDeactivated = doc->fileName();
   }
}
// reactivate previous drawing
void AsdkDataManager::documentToBeActivated(AcApDocument* doc)
{
   if (m_bSwitchOutToOtherDrawing) // switch to other drawing
   {
   }
   else //
   {
      if (!m_sFileNameBeDeactivated.IsEmpty())
      {
         AcApDocument* pDocReActive = NULL;
         getDocFromFilename(m_sFileNameBeDeactivated, pDocReActive);
         if (pDocReActive)
         {
            Acad::ErrorStatus es;
            m_bSwitchOutToOtherDrawing = true;
            m_sFileNameBeDeactivated = _T("\0");
            es = acDocManager->activateDocument(pDocReActive); // reactivate previous drawing
         }
      }
   }
}

MickD

  • Gator
  • Posts: 2948
  • I don't need a job, I need Money!!
Re: how to control when switch out to other drawing (c++ object arx)
« Reply #3 on: March 17, 2016, 04:06:05 am »
Have you tried any other reactors to test that your reactor is getting added to the doc manager?

I'm not really set up to do any testing, if I get time tomorrow I'll take a closer look.
Someone with more C++ experience will probably pop in before then, it's been a long while since I've used it :)
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

MickD

  • Gator
  • Posts: 2948
  • I don't need a job, I need Money!!
Re: how to control when switch out to other drawing (c++ object arx)
« Reply #4 on: March 17, 2016, 04:11:19 am »
Also, it might be worth trying to run your code in the documentActivated method, it will achieve the same result I think.
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

binh_nx

  • Guest
Re: how to control when switch out to other drawing (c++ object arx)
« Reply #5 on: March 17, 2016, 09:44:06 pm »
I have tried with documentActivated method. It works when switch drawing but it still doesn't work when create new drawing.


nullptr

  • BricsCAD
  • Needs a day job
  • Posts: 6736
  • AKA Daniel
Re: how to control when switch out to other drawing (c++ object arx)
« Reply #6 on: March 18, 2016, 12:11:51 am »
I think documentActivated is more of a windows focus event, are you looking for documentBecameCurrent?

binh_nx

  • Guest
Re: how to control when switch out to other drawing (c++ object arx)
« Reply #7 on: March 19, 2016, 09:10:08 am »
i have tried with documentBecameCurrent. But it is complex to control the loop.
Because documentBecameCurrent method is called in activating process. So it makes the loop between activate document and Deactivate document.
Do you have any comment to control this lop?
I think  previous document should be reactivated after current document is activated. But i don't know the way to do this. OMG !!!