Reply

Performance issue getting assembly structure

[ Edited ]

Hi all,

I'm trying to write a function which will preprocess an assembly structure and add pointers to each unique document to a map for faster access later in the data processing. This performs well for most assemblies, even large one-level assemblies, but takes exponentially longer for very large subassemblies. For instance, if I have a top assembly largeAsm with 1200 parts (4 unique parts repeated 300 times), I can create the map in ~6 seconds. If my toplevel assembly contains nothing except largeAsm as a subassembly, the preprocessing takes over two hours. The difference between the code paths in these two instances is whether I'm processing an OccurrencesPtr or a SubOccurrencesPtr... and it seems the performance hit comes just from asking SolidEdge for the next SubOccurrencePtr in the list. I'll include the current code below, and mark the point where my logging indicates most of the time is taken. Can anyone suggest what I'm doing wrong or a better-performing way to access each document in the structure of an assembly?

/*** Searches the occurrences (SolidEdgeAssembly namespace) gathering references to the each.** @param occurs - The occurrences to traverse.* @param pos_data - map of unique documents in structure*/void searchOccurrences(SolidEdgeAssembly:ccurrencesPtr occurs, PositionData &pos_data, int draft_pos){if (occurs != NULL){OccurrencePtr occur;for (long i=1; iGetCount(); i++){try{occur = occurs->Item(i);if (occur != NULL){wstring occur_name = (const wchar_t*)occur->GetName();

int index=0;if ((index = occur_name.find_last_of(L":")) != wstring::npos){occur_name.erase(index);}//get the reference key for this occurrenceSAFEARRAY* ref_key_array = NULL;occur->GetReferenceKey(&ref_key_array);

OccurData od = { draft_pos, OCCUR, ref_key_array };  

//add occurrence name and occurrence data to mapPositionData::iterator it = pos_data.find(PositionData::key_type(occur_name));if ( it == pos_data.end()){pos_data.insert(PositionData::value_type(occur_name, od));}

//if this is an assembly, traverse its occurrencesif (occur->Subassembly != VARIANT_FALSE){searchSubOccurrences(occur->GetSubOccurrences(), pos_data, draft_pos);occur->}}}catch(...){LoggingService::getInstance()->logDebug(Logger::LevelBasic, "%s", "An exception occurred in searchOccurrences!");}}}}

/*** Searches the suboccurrences (SolidEdgeAssembly namespace) gathering references to the each.** @param occurs - The suboccurrences to traverse.* @param pos_data - map of unique documents in structure*/void CADSystemSolidEdge::searchSubOccurrences(SolidEdgeAssembly:Smiley FrustratedubOccurrencesPtr occurs, PositionData &pos_data, int draft_pos){if (occurs != NULL){SubOccurrencePtr occur;for (long i=1; iGetCount(); i++){try{//According to my logging, this next statement takes the bulk of the time for the large subassembly caseoccur = occurs->Item(i);if (occur != NULL){wstring occur_name = (const wchar_t*)occur->GetName();

int index=0;if ((index = occur_name.find_last_of(L":")) != wstring::npos){occur_name.erase(index);}

//get the reference key for this occurrenceSAFEARRAY* ref_key_array = NULL;occur->GetReferenceKey(&ref_key_array);

OccurData od = { draft_pos, SUB_OCCUR, ref_key_array };  

//add occurrence name and occurrence data to mapPositionData::iterator it = pos_data.find(PositionData::key_type(occur_name));if ( it == pos_data.end()){pos_data.insert(PositionData::value_type(occur_name, od));}

if (occur->Subassembly != VARIANT_FALSE){searchSubOccurrences(occur->GetSubOccurrences(), pos_data, draft_pos);}}}catch(...){LoggingService::getInstance()->logDebug(Logger::LevelBasic, "%s", "An exception occurred in searchSubOccurrences!");}}}}

 

Posted by: Zach Hummel
Post date: 12/3/2010 7:04:56 AM

1 REPLY

RE: Performance issue getting assembly structure

[ Edited ]

Hi zdhummel,

 

i use the Solid Edge Revision Manager API to explore the complete structure of an opened Solid Edge assembly, which allows getting a list of all (unique) component documents very fast by using the LinkedDocuments property recursively on all returned assembly documents.

 

 

 

Posted by: Wolfgang Kunert
Post date: 12/13/2010 11:13:39 PM