Friday, 14 November 2014

Making of PacEdge Part 04

...continued from part 3

The user starts browsing the folder and finally picks a assembly file to create a package from which the FileOpen dialog internally stores in it FileName property. We assign this to the sFile variable of our program:

sFile = dlgOpen.FileName

Chances are user might as well cancel the dialog by clicking the X mark in the top-right corener or by clicking the Cancel button in which case the FileName property stores and empty string which we check as below:

If sFile <> String.Empty Then

If the sFile is not an empty string meaning the user did pick an assembly file, the assembly filename with the extension and its full path are added to the list of Solid Edge files:


After this RevisionManager Application object is created:

oApp = CreateObject("RevisionManager.Application")

where, oApp is declared at the Form level as:

Dim oApp As RevisionManager.Application

The Revision Manager opens in silent mode meaning its interface is not displayed.

After this, the assembly document is opened in the Revision Manager and stored as oDocA

oDocA = oApp.Open(sFile)

oDocA is declared at Form level as:

Dim oDocA As RevisionManager.Document

Subsequently the TraverseAssembly function is called to which the oDocA document is passed as an argument:


The TraverseAssembly function is a recursive function meaning it is called from within its own function body creating a seemingly infinite loop which is broken with a condition which checks if there are no more occurrences in the main assembly or in a sub-assembly beneath up to any number of levels.

Inside the TraverseAssembly call, all linked documents i.e. the components of the assembly are gathered into the oDocs collection:

oDocs = Document.LinkedDocuments

oDocs is declared at Form level as:

Dim oDocs As RevisionManager.LinkedDocuments

Then a For Each loop iterates through all the linked documents in the oDocs collection:

For Each oDoc As RevisionManager.Document In oDocs

  sFile = oDoc.FullName

  If Not FileExistInList(sFile, ListOfSolidEdgeFiles) Then


  End If

  If oDoc.Occurrences > 0 Then


  End If


With each linked document in the Linked Documents collection:

1. If the full name of the linked document is not already listed in the ListOfSolidEdgeFiles, then it is added to the list.

2. The document is again traversed if its Occurrences property which is an integer count of the sub-occurrences beneath is greater than zero.

The FileExistInList function takes two arguments: a file name and a list and checks if the string is already contained in the list:

Inside the function, a flag or Boolean variable bExist is assumed to be False i.e. as assumption that the said file does not exist in the collection.

Then a For Each loop iterates through the file collection and tries to match the said file with each member in the collection and if a member matches, the flag is raised to True with bExist = True.

Private Function FileExistInList(ByVal sFileNameToCheck As String, ByVal FileList As List(Of String)) As Boolean

  Dim bExist As Boolean = False

  For Each s As String In FileList

    If s.CompareTo(sFileNameToCheck) = 0 Then

      bExist = True

      Exit For

    End If


  Return bExist

End Function

Outside the For Each loop, the state of the flag is returned as True if the said file was indeed found or False if it was not there even after thoroughly checking in the existing collection that was passed for checking.

Back to the Assembly PacEdge button’s Click event, the Revision Manager application is terminated in the hidden mode by calling oApp.Quit()

The Solid Edge files collection finally goes for processing to the ProcessSolidEdgeFiles() function.

The ProcessSolidEdgeFiles() function adds four more nodes under the Solid Edge node as below:

nodeASM = nodeSE.Items.Add("Assembly Files", 2)

nodePAR = nodeSE.Items.Add("Part Files", 3)

nodePSM = nodeSE.Items.Add("Sheetmetal Files", 4)

nodeDFT = nodeSE.Items.Add("Draft Files", 6)

Continued to part 5... 

Index of all Solid Edge Tips, Tutorials and Videos...