Reply

ADDIN: Assembly - Activate an istance, generate an AfterDocumentOpen event

[ Edited ]

 

Hi,

when a user activate an istance in assembly, SolidEdge fire an AfterDocumentOpen event.

But in this case, the document isnt really "opened", the window is not displayed and

is not listed in Application.Documents.

As a result, I get two edgebarpages added by the addin to the partent assembly.

One correct, for the parent assembly.

The second edgebar, wrong, created by the AfterDocumentOpen, after activating the istance.

Questions:

1. How to avoid the second edgebarcreation?

2. How ro check if a document is "really" opened or just activated?

Thanks in advance for the info.

Best Regards

Massimo

 

 

Posted by: Massimo Magris
Post date: 6/11/2009 9:10:31 PM

5 REPLIES

RE: ADDIN: Assembly - Activate an istance, generate an AfterDocumentOpen event

[ Edited ]

Hi Massimo,

 

you'll always get this event fired for activated parts - the problem is that they are opened 'internally' for geometry access etc.

The easiest solution is to run through the open documents collection and compare the pointers

e.g.

 

for (long current = 1; current Documents->Count; ++current)

{

if (theDocument == se->Documents->Item(current))

{

/* Add EdgeBarPage */

break;

}

}

 

 

You might have to check the SolidEdgeDocument::InPlaceActiivated property as well. In-place activated docs are not in the documents collection (the top-level document is though).

 

Hope this helps

Calum

 

Posted by: Calum McLellan
Post date: 6/11/2009 9:26:01 PM

RE: ADDIN: Assembly - Activate an istance, generate an AfterDocumentOpen event

[ Edited ]

 

Hi Calum,

thanks.

I tried this, and this what happen.

 

1. The edgebar is not added to the Parent Assembly (this is ok!, thanks)

2. But than, if from the parent assembly, I open the previous activated istance, the

edgebar is not added anymore! (Wrong , maybe you know why?)

 

I check the behaviour using the AddIn Example of Jason.

Regards

Massimo

 

Posted by: Massimo Magris
Post date: 6/11/2009 9:43:30 PM

RE: ADDIN: Assembly - Activate an istance, generate an AfterDocumentOpen event

[ Edited ]

Hi Massimo,

 

the problem is that the document was already open... I'm not sure what the best solution is here. You could monitor the commands for in-place activation and opening from an assembly and then check the active document, or you could keep a list of all the documents that have had the edgebar page added and then check each document on a window change (you would have to make sure that the documents are removed from the list when they are closed, but I'm assuming you remove the edgbar page at the same time.

 

I would tend towards the second option as you can be sure that only one (and always one) page will be added to each document (as long as you check the InPlaceActivated property). It would also be easier to keep all your code in AddEdgeBarPage and RemoveEdgeBarPage helper methods so you have less code scattered all over your add-in.

 

Let me know how you get on.

Calum

 

Posted by: Calum McLellan
Post date: 6/11/2009 10:01:15 PM

RE: ADDIN: Assembly - Activate an istance, generate an AfterDocumentOpen event

[ Edited ]

 

Hi Callum,

thanks, I will do what you suggest.

 

To me what is strange is that this check, is something similar to what you suggest,

check if a document already have a pEdgeBarPage.

 

 if (!m_EdgeBarMap.Lookup(pDocument, pEdgeBarPage)) 

    hr = pEdgeBarPage->CreatePage(m_pAddin, pDocument);

 

BUT it create the EdgeBarPage ON THE PARENT DOCUMENT,

not on the pDocument passed!

 

WHY?

It is a bug?

Thanks, regards

Massimo

---------------------------

HRESULT CEventManager::AddEdgeBarPage(SolidEdgeDocumentPtr pDocument)

{

 HRESULT hr = S_OK;

 CEdgeBarPage* pEdgeBarPage = NULL;

 

 CString FullName ;

 FullName = (LPCSTR)pDocument->FullName ;

 if (!m_EdgeBarMap.Lookup(pDocument, pEdgeBarPage))

 {

  pEdgeBarPage = new CEdgeBarPage;

  hr = pEdgeBarPage->CreatePage(m_pAddin, pDocument);

  if (hr == S_OK)

  {

   m_EdgeBarMap.SetAt(pDocument, pEdgeBarPage);

  }

 }

 return hr;

}

 

 

Posted by: Massimo Magris
Post date: 6/12/2009 12:02:11 AM

RE: ADDIN: Assembly - Activate an istance, generate an AfterDocumentOpen event

[ Edited ]

Hi Massimo,

 

if the document is in-place activated then I don't think it has its own edgebar, at least the Pathfinder is the same instance (for pre ST versions this only applies to assemblies).

 

The easiest way to check would be if you have a workstation with V20 installed - then you could see if there is a difference between IPA parts and IPA assemblies (the pathfinder is the same instance for asms, but for parts there are seperate instances for the part and asm pathfinders).

 

Of course I'm really just guessing... The code looks OK but it's hard to tell what's going on without debugging...

 

I'f you can't figure it out then you could strip done your code to a bare minimum (adding an empty edgebar page) and post it.

 

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 6/12/2009 12:43:08 AM