Reply

Active Environment Control

[ Edited ]

I seem to be running into trouble with the active environment when opening and closing SE docs. One of the last steps of my addin's process is to put the SE session into a particular state (opening a particular file(s) or possibly closing all files). Most of the time these calls seem to work fine, but some times SE doesn't seem to be able to properly shift between environments (to the Part/Assembly/Detail environment when I'm opening and to the Application environment if I'm closing everything). The end result varies any where between

 

1. The title bar says that a file is open but the graphics area is just stale artifacts. Refreshing it makes the graphics area look like the Application environment, but the title and tool bars still look like the part is open.

 

and

 

2. The API call seems to complete without exception but the file is not actually opened, SE remains in the Application environment.

 

Is there something else I should be doing to help SE transfer between environments?

 

Posted by: Adam Brenneis
Post date: 2/9/2007 6:33:11 AM

3 REPLIES

RE: Active Environment Control

[ Edited ]

Adam,

 

Without seeing your code it is going to be difficult to help you. Can you post a reply with at least sample code of what you're trying to do? Thanks.

 

Posted by: Jason Newell
Post date: 2/9/2007 6:38:31 AM

RE: Active Environment Control

[ Edited ]

I can't say there's a particular piece of code that I having trouble with. I guess the question is really just is there more to opening and closing files than I am aware of?

 

//get the collection

DocumentsPtr pDocs = _pApp->GetDocuments();

 

//get the file

SolidEdgeDocumentPtr pDoc = pDocs->Item("my_file.par");

 

//especially the case where my_file.par was the only file in session

//this means SE needs to revert back to the "Application" environment

//but I don't see any way to make sure it does that

pDoc->Close(VARIANT_FALSE); //forced no save

 

//open another file

//this could also be trouble if the app is not already in the "Part"

//environment, SE needs to switch over to it.

SolidEdgeDocumentPtr pOtherDoc = pDocs->Open(L"c:\my_other_file.par");

 

It really seems pretty random as far as whether or not the files open and close properly (though it certainly favors working properly). The discrepancy between the file in question and the resultant environment makes me think there's more I should be doing.

 

Posted by: Adam Brenneis
Post date: 2/9/2007 9:36:11 AM

RE: Active Environment Control

[ Edited ]

Adam,

 

I guess the main thing that I would suspect is timing in the event chain. Where exactly is your suspect code executing? i.e. What event\proc triggers it?

 

Here is a small example from my VS.NET 2005 templates that seems to work. Notice that this code executes upon an addin command. Here I have 2 buttons.

 

 

HRESULT CEventManager::XAddInEvents::raw_OnCommand( long nCmdID )

{

HRESULT hr = S_OK;

DocumentsPtr pDocuments;

SolidEdgeDocumentPtr pDocument;

 

pDocuments = this->m_pEventManager->m_pApplication->Documents;

 

switch (nCmdID)

{

case 0:

pDocuments->Add(L"SolidEdge.AssemblyDocument");

pDocuments->Add(L"SolidEdge.DraftDocument");

pDocuments->Add(L"SolidEdge.PartDocument");

pDocuments->Add(L"SolidEdge.SheetMetalDocument");

pDocuments->Add(L"SolidEdge.WeldmentDocument");

pDocuments->Open(L"C:\\Part1.par");

break;

case 1:

for (long i = 1; i Count; i++)

{

pDocument = pDocuments->Item(i);

hr = pDocument->Close(VARIANT_FALSE);

}

 

// Alternate method.

//hr = this->m_pEventManager->m_pApplication->Documents->Close();

break;

}

 

return hr;

}

 

 

Posted by: Jason Newell
Post date: 2/9/2007 10:09:19 AM