How to store Assembly/Drawing Occurance Structure

Pioneer
Pioneer

Hi All,

 

How to get and store a occurance Structure from a Drawing/Assembly,

I am trying a recurssive loop to iterate, but its affecting the performance. But i am still able to get all the occurance, The problem/confussion is how to store the occurance in some form of Data Structure.

 

 

Is there any bettwr way to get the occurance and store the Occurance Structure.

 

My Current Scenario:

  1. Check Active Document is Drawing/Assembly/Part.
  2. If Drawing/Assembly then get iterate through its occurance and store the occurece it in a Data Structure.

 

Regards,

Santosh

Regards,
Santosh
7 REPLIES

Re: How to store Assembly/Drawing Occurance Structure

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

"How to get and store a occurance Structure from a Drawing/Assembly,"

From reading the rest of your question, it sounds like you've got a handle on how to walk the occurrence tree. You say "store a occurrance" but what exactly does that mean?

 

"I am trying a recurssive loop to iterate, but its affecting the performance."

You haven't shown any code but I can deduce that you're connecting to a running instance of Solid Edge. If that's the case, there are a few tricks you can use that may help.

 

  • Application.DelayCompute = True
  • Application.DisplayAlerts = False
  • Application.Interactive = False
  • Application.ScreenUpdating = False

 

If you set these, you need to make sure that you put them back to their original values after your code executes.

 

The reason that you're seeing performance issues is because behind the scenes, Solid Edge is having to load the occurrence documents (depending on how you interact with the API) which takes time. You can verify this with Spy for Solid Edge by going to the Event Monitor tab, executing your code and seeing that Solid Edge is doing. You'll see a lot of AfterDocumentOpen events being raised as your code walks the tree.

 

"The problem/confussion is how to store the occurance in some form of Data Structure."

What are you wanting to store? I would assume the path to the occurrence but you don't specify. Regarding data structures, the sky is the limit. What are your requirements? XML, JSON, etc.

 

Without seeing any code, we can only guess. Your question does give me an idea for creating a BOM Extractor sample for GitHub.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: How to store Assembly/Drawing Occurance Structure

Pioneer
Pioneer

Hi Jason,

 

Sorry i wasn't clear... Below is the piece of the code to iterate throught the occurance

 

public static void traverseMainAssembly(SolidEdgeAssembly.AssemblyDocument sldAsmDoc)
{
      Messagebox.Show(sldAsmDoc.DisplayName.ToString());
      // Call the function that does the recursion.
      traverseAssembly(sldAsmDoc.Occurrences, 1);
}

public static void traverseAssembly(SolidEdgeAssembly.Occurrences sldAsmOccs, int level)
{            
     // Iterate through all of the occurrence in this collection.
     // This represents the occurrences at the top level of an assembly.
     foreach (Occurrence oOcc in sldAsmOccs)
     {
         // Print the name of the current occurrence.
         MessageBox.Show(oOcc.OccurrenceFileName.ToString() + "     " + level * 3);

         // Check to see if this occurrence represents a subassembly
         // and recursively call this function to traverse through it.
         SolidEdgeDocument sldDoc = (SolidEdgeDocument)oOcc.OccurrenceDocument;
         if (sldDoc.Type == DocumentTypeConstants.igAssemblyDocument)
         {
             SolidEdgeAssembly.AssemblyDocument sldAscSubDoc =  (SolidEdgeAssembly.AssemblyDocument)oOcc.OccurrenceDocument;
                  
             traverseAssembly(sldAscSubDoc.Occurrences, level + 1);
         }
    }
}

I above code gives me all the occurances. As you said i can see the AfterDocumentOpen Event, i shall try your suggesstion and use then below

  • Application.DelayCompute = True
  • Application.DisplayAlerts = False
  • Application.Interactive = False
  • Application.ScreenUpdating = False

I ll also use the Spy for Solid Edge for better understanding.

 

Now i need to store the Occurance Structure(i.,e parent Child relationship between assembly, Parts and sub-assemblies "First i thought of generating a XML file")

 

I am not sure how to do, as the object where the relationship is maintained will be the input to another 3rd party application which will be used to generate a document based on the Relationship structure...

 

Regards

Santosh

Regards,
Santosh

Re: How to store Assembly/Drawing Occurance Structure

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Ok. I'm writing a sample BOM extractor now and will have it up on GitHub shortly. I'll demonstrate various ways to serialize the structure in different formats.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: How to store Assembly/Drawing Occurance Structure

Pioneer
Pioneer
OK.. What would be a suitable object to use ?
Regards,
Santosh

Re: How to store Assembly/Drawing Occurance Structure

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I created an ExtractStructure sample.

While working on this, I realized there are really two different scenarios.

  1. BOM extraction
  2. Structure extraction

Depending on which one you're after, you're code will vary. If you are truly after BOM information, then I would direct you to:

The main differece is that BOM information interrogation is always going to be slower because we need to access properties from the occurrence document which forces Solid Edge to load the document behind the scenes. For example:

 

// Filter out certain occurrences.
if (!occurrence.IncludeInBom) { continue; }
if (occurrence.IsPatternItem) { continue; }
if (occurrence.OccurrenceDocument == null) { continue; }

If you're just needing structure information, then the ExtractStructure sample will work fine.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: How to store Assembly/Drawing Occurance Structure

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I went ahead and created a ExtractBOM sample.

 

As I was saying, the main difference is that interrogating BOM information is slower as this sample demonstrates. So it all boils down to what information you're after.

 

If someone knows of a way to speed up my code in this sample, let me know and I'll update it.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: How to store Assembly/Drawing Occurance Structure

Pioneer
Pioneer

Hi Jason,

I wanted only the Assembly Structure. Used your sample, modified the code with my reqirements.

Regards,
Santosh