Best way to extract data from .asm and .par

Experimenter
Experimenter

Hi guys,

 

I'm totally new to Solid Edge and its API but I do have experience in programming (java, vb, c++).  

 

I'm looking for a way to extract (via script/API but not manually) the information from a .asm and/or .par document.

 

In other words, I'd like to choose a .asm file and to be able to extract (into an xml file as instance) the information about this assembly and its content.  And if the assembly contains sub-assemblies, then to perform the same recursive algorithm in order to get to all parts.  

 

I want to be able to display the assembly tree like this (with all the informations (part#, qty, description, ...)):

-ASM1

      - PART1

      - PART2

      - SUB_ASM1

            - PART3

            - PART4

      - SUB_ASM2

            - PART5

      -PART6

 

I guess I'm not the first one that needs to do such a thing.  What would be the best way to do so according to you?

 

Thank you very much..

6 REPLIES

Re: Best way to extract data from .asm and .par

Phenom
Phenom

Hi Rick,

 

Welcome to the Solid Edge forums.

 

I'd suggest you should post this in the SE Developer forum.

This is a seperate forum for Solid Edge API queries.

 

What you are looking for is recursive programming.

You may want to have a look at this post which has an example on usage of recursive programming.

 

Regards,

Tushar Suradkar

www.SurfAndCode.in

 

Re: Best way to extract data from .asm and .par

Experimenter
Experimenter

Thank's a lot for your response.

 

I understand recursive programming and I agree that it'll needed in order to perform what I want.

 

From other threads I found since yesterday, it seems that the solution is to use the Revision Manager API in order to open .asm files and then to programmatically do the job myself.  Nothing exists already that'll do that for me.

 

Am I right?

Re: Best way to extract data from .asm and .par

Phenom
Phenom

Both Solid Edge API and the Revision Manager API can recursively traverse an assembly.

 

1) SE API:

Dim oApp As SolidEdgeFramework.Application
Dim oDoc As SolidEdgeAssembly.AssemblyDocument

Dim i As Integer

Sub Main()
    Set oApp = GetObject(, "SolidEdge.Application")
    Set oDoc = oApp.ActiveDocument
    
    Debug.Print oDoc.FullName
    Call ShowAssemblyStructure(oDoc, 1)
End Sub

' This subroutine determines all of the occurrences
' Each occurrence is written to the debug window
' If a occurrence is an assembly file,
' this function is recursively called to get the occurrences within

Private Sub ShowAssemblyStructure(Document As SolidEdgeAssembly.AssemblyDocument, AssemblyDepth As Integer)
    Dim i As Integer
    Dim oOccs As SolidEdgeAssembly.Occurrences
    Set oOccs = Document.Occurrences
    
    For i = 1 To oOccs.Count
        Debug.Print Space(AssemblyDepth * 8) & oOccs(i).OccurrenceFileName
        
        If oOccs(i).Subassembly = True Then
            Call ShowAssemblyStructure(oOccs(i).OccurrenceDocument, AssemblyDepth + 1)
        End If
    Next i
    
    Set oOccs = Nothing
End Sub

 

2) RM API:

 

Dim oDocs As RevisionManager.LinkedDocuments

 

Private Sub TraverseAssembly(ByVal Document As RevisionManager.Document)
        oDocs = Document.LinkedDocuments

        For Each oDoc As RevisionManager.Document In oDocs
            sFile = oDoc.FullName
            Debug.Print(sFile)

            If oDoc.Occurrences > 0 Then
                TraverseAssembly(oDoc)
            End If
        Next

        oDocs = Nothing
    End Sub

 

Note: Important difference - Occurrences is a collection in the SE API whereas Occurrences is an integer count in RM API.

 

Hope that is helpful.

 

www.SurfAndCode.in

 

Re: Best way to extract data from .asm and .par

Experimenter
Experimenter

Thank's a lot for your answer, I thinkI get it.

 

Just one little thing, when you do this:

    Set oApp = GetObject(, "SolidEdge.Application")
    Set oDoc = oApp.ActiveDocument

 

Is SolidEdge opened? I guess it is, otherwise, what would ActiveDocument refer to...

 

But if I don't want SolidEdge to be opened?  Let's say, I have a folder with all my .asm and .par and I wanna loop into all of them (like a batch script)?

 

How would I open the document?  Is there a method like this?

    Set oDoc = oApp.GetDocument("c:\SolidEdge\assembly1234.asm")

 

Thank's.

Re: Best way to extract data from .asm and .par

Phenom
Phenom

The Revision Manager API example can be done without launching Solid Edge. 

 

To search through all files in a folder, you could do something like this:

 

Dim di As New IO.DirectoryInfo(FolderPath)
Dim dilist As IO.FileInfo() = di.GetFiles("*.asm")
Dim dra As IO.FileInfo

 

For Each dra In dilist

    Do stuff

Next

 

The variable FolderPath you would have the user input through a form. As another example, a lot of my projects with VB have me launching them from within Solid Edge with a document open, so I pull the path from the open document to skip user input.

 

Tushar will probably be along shortly to give you better advice. Smiley Wink

-Dylan Gondyke

Re: Best way to extract data from .asm and .par

Phenom
Phenom

Dylan, you guessed it right. I was here 8 hrs back and Rick continued this post on the SE Dev Forum. Me and Jason are trying to help solve this, both pointing to external links of our work.

Pls join us there and add your valuable inputs Smiley Happy

 

BR,

~Tushar