SelectSet.Copy() issue

Hi all,

 

VC++2010, ST4 MP12

 

I'm having a problem with the Copy() method of SolidEdgeDraft.SelectSet. What I'm doing is replacing out-of-date drawing frames with the current version, so I'm deleting everything from all the background sheets of the working draft (which works just fine), and then opening up the template file and copying everything from the background sheets there across to the corresponding background sheet of the working draft, one sheet at a time.

 

This works just fine for the first sheet, but on the second loop through, the call to Copy() causes exceptions and crashes. The SelectSet object contains the correct number of items, and at the moment I cannot see what is causing the problem.

 

Here is the section of code that is giving me grief:

 

[code type=cpp]

SolidEdgeDraft:Smiley FrustratedectionsPtr ptSections = pTemplate->Sections;

SolidEdgeDraft:Smiley FrustratedectionPtr ptBackground = ptSections->BackgroundSection;

SolidEdgeDraft:Smiley FrustratedectionSheetsPtr ptSheets = ptBackground->Sheets;

SolidEdgeDraft:Smiley FrustratedheetPtr ptSheet = NULL;

 

SolidEdgeDraft::BlockOccurrencesPtr ptBlockOccs = NULL;

SolidEdgeFrameworkSupport::TextBoxesPtr ptTextBoxes = NULL;

 

 

for (long i = 1; i <= pSheets->Count; ++i) {

 

pTemplate->Activate(); // pTemplate is type SolidEdgeDraft:Smiley Very HappyraftDocumentPtr

ptSheet = ptSheets->Item(i);

 

ptSheet->Activate();

 

SolidEdgeFramework:Smiley FrustratedelectSetPtr ptSelectSet = pTemplate->SelectSet;

 

 

ptBlockOccs = ptSheet->BlockOccurrences;

for (long j = 1; j <= ptBlockOccs->Count; ++j) {

SolidEdgeDraft::BlockOccurrencePtr ptBlockOcc = ptBlockOccs->Item(j);

ptSelectSet->Add(ptBlockOcc);

ptBlockOcc = NULL;

}

 

ptTextBoxes = ptSheet->TextBoxes;

for (long j = 1; j <= ptTextBoxes->Count; ++j) {

SolidEdgeFrameworkSupport::TextBoxPtr ptTextBox = ptTextBoxes->Item(j);

ptSelectSet->Add(ptTextBox);

ptTextBox = NULL;

}

 

long check = ptSelectSet->Count; // verify there are items selected (8 of them, as expected, on second loop)

 

ptSelectSet->Copy(); // Place the selection in the system clipboard

// This works for the first loop only - subsequent loops cause exceptions

 

 

 

// Paste onto the corresponding background sheet of the working document...

pDraft->Activate();

pSheet = pSheets->Item(i);

pSheet->Activate();

 

SolidEdgeFramework::WindowsPtr pWindows = pDraft->Windows;

SolidEdgeDraft:Smiley FrustratedheetWindowPtr pWindow = pWindows->Item(1);

 

pWindow->Activate();

pWindow->Paste();

 

ptSelectSet->RemoveAll();

ptSelectSet = NULL;

 

 

// Local Cleanup

ptTextBoxes = NULL;

ptBlockOccs = NULL;

 

}

[/code]

 

So, can anyone see what I'm doing wrong??

 

 

The debug output is:

[code type=cpp]First-chance exception at 0x000007fefd649e5d in Edge.exe: Microsoft C++ exception: _com_error at memory location 0x00a2a0d0..

First-chance exception at 0x7763fd5c in Edge.exe: 0xC015000F: The activation context being deactivated is not the most recently activated one.[/code]

 

Posted by: Paul Dobson
Post date: 7/4/2013 10:54:42 AM

1 REPLY

SelectSet.Copy() issue

OK, as is typical with these things, you ask the question and then almost immediately answer it yourself! Just on the off chance that anyone else encounters this, there is nothing wrong with the code per se... the cause of the exceptions was a BlockOccurrence object with no Block reference.

 

After adding a couple of lines to check that the current block occurrence has a block reference before adding it to the SelectSet, all the background sheets copy across perfectly. (Solid Edge Spy is damned useful!)

 

Posted by: Paul Dobson
Post date: 7/5/2013 4:09:46 AM