Sunday 30 November 2014

Making of PacEdge Part 08

...continued from part 7

Also when both PAR and PSM check boxes are un-checked, there is no use displaying the file or folder dialogs for selection. Hence in the CheckedChange event for the two CheckBoxes, the Enabled property for the PAR+PSM PacEdge button is controlled as below:

Private Sub chkPAR_CheckedChanged(ByVal sender As System.Object,) Handles...


End Sub

The EnableDisablePPPacEdge function checks if both the PAR and PSM check boxes are un-checked and if so, disables the PAR+PSM PacEdge button.

Private Sub EnableDisablePPPacEdge()

  If chkPAR.Checked = False And chkPSM.Checked = False Then

    btnPSPacEdge.Enabled = False


    btnPSPacEdge.Enabled = True

  End If

End Sub

Each time the user picks a bunch of files from the Multiselect file dialog, they are stored in the array which is iterated as below and each file in the array is added to the global ListofSolidEdgeFiles after verifying that there are no duplicates.

If sParAndPsmFiles.Count > 0 Then

  For Each sFile As String In sParAndPsmFiles

    If Not FileExistInList(sFile, ListOfSolidEdgeFiles) Then


    End If


End If

On to the other file selection mode i.e. Pick Folder,

ElseIf FSelMode = FileSelectionMode.AllFromFolder Then

The dlgFolder which is a separate contrl of type called FolderBrowserDialog is set with a Description property and is displayed to the user using its ShowDialog method.

dlgFolder.Description = "Pick folder for Solid Edge Part and Sheetmetal files."


sFolder = dlgFolder.SelectedPath


The sFolder variable holds the folder that the user browsed to and picked.

Another mode called SearchOption determines whether Solid Edge files from only the folder selected are picked or the sub-folders up to any depth are also picked automatically


What follows next is an array of nested If and For statements. I have never before written so many nested levels of If and/or For.

If sFolder <> String.Empty Then

  If chkPAR.Checked = True Then

    Dim sParFiles() As String = Directory.GetFiles(sFolder, "*.par", soMode)

    If sParFiles.Count > 0 Then

     For Each sFile As String In sParFiles

        If Not FileExistInList(sFile, ListOfSolidEdgeFiles) Then


       End If


    End If

End If

If #1 - A folder was indeed selected by user i.e. the user did not click the Cancel button or the X mark in the top-right corner of the Folder dialog.

If #2 - the PAR CheckBox is checked, then the filter is set to *.par and the GetFiles function of the Directory class of the System.IO namespace is called with the first argument being the folder name, second argument the filter for Part files and the last being the File SearchOption mode.

When set to AllDirectories, the soMode searches not just the sub-folders immediately below the selected folder but also all sub-folders up to the deepest level.

If #3 - If the Count property is greater than zero meaning if any files were at all found under those folders.

For #4 - Iterate through each of the files in the array sParFiles and

If #5 - Check each file if it already exist in the ListOfsolidEdgeFiles and if not add to the list.

Similarly the Sheetmetal files are also added to the ListOfsolidEdgeFiles.

Continued to part 9... 

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

No comments:

Post a Comment