Reply

Explode .asm from .net

[ Edited ]

Hi, I have to get all parts and sub assemblies listed from a solid edge assembly (.asm). Is there an other way then using SolidEdgeFramework.Application which is consuming a lot of machine ressources.

I am trying to use revision manager but i can't get the proper SolidEdgeAssembly.AssemblyDocument which allow me to use occurences and subOccurences to list all parts.

 

here is the code i'm using with SolidEdgeFramework.Application which works

Dim objApp As SolidEdgeFramework.Application = Nothing

Dim objAssembly As SolidEdgeAssembly.AssemblyDocument = Nothing

Dim objType As Type

Try

' Get the type from the Solid Edge ProgID

objType = Type.GetTypeFromProgID("SolidEdge.Application")

' Start Solid Edge

objApp = Activator.CreateInstance(objType)

' Make Solid Edge visible

objApp.Visible = False

' Turn off alerts. Weldment environment will display a warning

objApp.DisplayAlerts = False

REM ouvrir le fichier de l'assemblage

objApp.Documents.Open("E:\Assy\Machine a balais 2008.asm")

objAssembly = DirectCast(objApp.ActiveDocument, SolidEdgeAssembly.AssemblyDocument)

REM créer la liste des composantes

Dim lstParts As New List(Of Composante)

REM y ajouter l'assemblage de tête

lstParts.Add(New Composante(objAssembly.Name, "E:\Assy\Machine a balais 2008.asm", objAssembly.Name))

REM lister chacun des sous assemblages et composantes de l'assemblage de tête

For Each occ As SolidEdgeAssembly.Occurrence In objAssembly.Occurrences

Dim compOcc As New Composante(occ.Name.Split(":")(0), occ.OccurrenceFileName, objAssembly.Name)

If Not lstParts.Contains(compOcc) Then

lstParts.Add(compOcc)

End If

Dim objSubOccurrences As SolidEdgeAssembly.SubOccurrences = Nothing

REM pour chacun de ces sous assemblages lister chacun de ses composantes

REM vérifier si ce sont des assemblages, si oui utiliser une méthode récursive pour en lister les composantes

objSubOccurrences = DirectCast(occ.SubOccurrences, SolidEdgeAssembly.SubOccurrences)

If objSubOccurrences IsNot Nothing AndAlso objSubOccurrences.Count > 0 Then

For Each subOcc As SolidEdgeAssembly.SubOccurrence In objSubOccurrences

Dim comp As New Composante(subOcc.Name.Split(":")(0), subOcc.SubOccurrenceFileName, occ.Name.Split(":")(0))

If Not lstParts.Contains(comp) Then

lstParts.Add(comp)

End If

Dim subO As SolidEdgeAssembly.SubOccurrences = Nothing

subO = DirectCast(subOcc.SubOccurrences, SolidEdgeAssembly.SubOccurrences)

If subO IsNot Nothing AndAlso subO.Count > 0 Then

listeSubOccurences(subOcc, lstParts)

End If

Next

End If

Next

lstParts.Sort(AddressOf Composante.OrdonnancerComposantesParAssemblage)

For Each c As Composante In lstParts

Console.WriteLine(c.Nom & " " & c.NomFichier & " Assemblage: " & c.NomParent)

Next

Console.WriteLine("Total: " & lstParts.Count)

 

Catch ex As Exception

Console.WriteLine(ex.Message & ControlChars.CrLf & ex.StackTrace & ControlChars.CrLf)

Finally

objApp.Quit()

If Not (objApp Is Nothing) Then

Marshal.ReleaseComObject(objApp)

objApp = Nothing

End If

End Try

End Sub

 

Private Sub listeSubOccurences(subOccurence As SolidEdgeAssembly.SubOccurrence, ByRef lstParts As List(Of Composante))

Try

Dim subOccurences As SolidEdgeAssembly.SubOccurrences = Nothing

subOccurences = subOccurence.SubOccurrences

For Each subOcc As SolidEdgeAssembly.SubOccurrence In subOccurences

REM ajouter la composante a la liste

Dim comp As New Composante(subOcc.Name.Split(":")(0), subOcc.SubOccurrenceFileName, subOccurence.Name.Split(":")(0))

If Not lstParts.Contains(comp) Then

lstParts.Add(comp)

End If

REM vérifier si c'est un assemblage, si oui réappeller la méthode

Dim objSubOccurrences As SolidEdgeAssembly.SubOccurrences = Nothing

objSubOccurrences = subOcc.SubOccurrences

If objSubOccurrences IsNot Nothing AndAlso objSubOccurrences.Count > 0 Then

For Each subO As SolidEdgeAssembly.SubOccurrence In objSubOccurrences

listeSubOccurences(subO, lstParts)

Next

End If

Next

Catch ex As Exception

Console.WriteLine(ex.Message & ControlChars.CrLf & ex.StackTrace & ControlChars.CrLf)

End Try

End Sub

 

here is what i'm trying to do with revisionManager

Dim objApp As RevisionManager.Application = Nothing

Dim objAssembly As SolidEdgeAssembly.AssemblyDocument = Nothing

Dim doc As RevisionManager.Document = Nothing

Try

' Create new instance of the Revision Manager Application object

objApp = New RevisionManager.Application

' Open a file

doc = DirectCast(objApp.Open("E:\Assy\Machine a balais 2008.asm"), RevisionManager.Document)

I'm stuck here because i can't get occurences

 

Posted by: Pierre Côté
Post date: 3/8/2012 12:55:10 PM

1 REPLY

Re: Explode .asm from .net

[ Edited ]

Bonjour Pierre,

 

when using the RevisionManager object for traversing the structure of an opened assembly file, you don't work with collections of type Occurrences. Instead you use the collection LinkedDocuments of the opened root RevisionManager.Document, which gives you access to all directly linked documents (link type normal). This allows you to recursively traverse the whole assembly structure. Each RevisionManager.Document object gives you access to its physical filename by its property FullName.

 

Posted by: Wolfgang Kunert
Post date: 3/11/2012 3:16:40 AM