Friday, 21 November 2014

Making of PacEdge Part 06

...continued from part 5

The Path class is a member of the System.IO namespace which has been imported:

Imports System.IO

The last SubItem Yes/No is added using the function DraftYesNo which takes the file name sFile as an argument and returns a string “Yes” or “No” which can be directly used in the column.

Inside the DraftYesNo function, the File.Exists from the System.IO checks if adraft file exists in the same folder as the Part or Sheetmetal file. This is done by using another simple function called ChangeExtension which takes a full file name with path of a file and replaces just the extension and returns the new name. So, “C:\Program Files\Solid Edge\Training\Anchor.par” returns “C:\Program Files\Solid Edge\Training\Anchor.dft” when the second argument to ChangeExtension is provided a “dft”.

Private Function DraftYesNo(ByVal sFileName As String) As String

  Dim sDraftFile As String = Path.ChangeExtension(sFileName, "DFT")

  Dim sDraftExist As String = "No"

  If File.Exists(sDraftFile) Then

    sDraftExist = "Yes"

  End If

  Return sDraftExist

End Function

Next, if the SubItem is a Yes, the Draft file needs to be added under the Draft sub-node so it can ultimately be added to the PacEdge if the Include Draft CheckBox is checked ON.

For this, the Draft Exist? node‘s BackColor is first set to green. You can later set this as a user-defined color by providing an Options dialog in your own version of PacEdge.

If n.SubItems(4).Text.ToUpper = "YES" Then

n.SubItems(4).BackColor = Color.Green

and the variable n is immediately set to a new node under the Draft node. This is called variable re-use or variable recycling and was quite popular in ancient times when computer memory was a premium.

n = nodeDFT.Items.Add(sFileName, 6)

n.SubItems.Add("")

n.SubItems.Add(sPath)

n.SubItems.Add(GetFileSize(sPath + "\" + sFileName + ".DFT"))

End If

In case of an Assembly PacEdge, there would be several assembly files listed under the Assembly tree node in which case we want to distinct the main assembly in the package from the sub-assemblies. This is done by highlighting the main assembly with a different ForeColor and BackColor.

If ActivePacEdgeMode = PacEdgeMode.AssemblyPacEdge Then

  nodeASM.Items(0).BackColor = Color.DodgerBlue

  nodeASM.Items(0).ForeColor = Color.Gold

End If

Note how safely it is assumed that the first i.e. 0th item under the Assembly node is the main assembly.

This is my retro-style procedural programming way of making things work Smile

Make sure you make your own version of PacEdge using modern and trendy fashions like OOPS, 3-Tier architecture or perhaps store it in the cloud.

I am a mechanical engineer of the 90’s and believe in getting things done with hammer blows.

Finally it’s time to fill in the counts. This is done using the numbers in the count column:

nodeASM.SubItems.Add(nodeASM.Items.Count.ToString())

nodePAR.SubItems.Add(nodePAR.Items.Count.ToString())

nodePSM.SubItems.Add(nodePSM.Items.Count.ToString())

nodeDFT.SubItems.Add(nodeDFT.Items.Count.ToString())

Finally, the grand total for the Solid Edge Files node is calculated as below:

nodeSE.SubItems.Add(((nodeSE.ChildrenCount) - 4).ToString())

The -4 is perfomed to deduce the 4 child-nodes for Draft, Part, Sheetmetal and Assembly themselves.

Part+Sheetmetal PacEdge: This is different from the Assembly PacEdge in that the PAR+PSM PacEdge does no logical operation on any data structure as in the case of an assembly. The PAR+PSM PacEdge is simply a PacEdge of all Solid Edge Part and Sheetmetal files gathered in the ListofSolidEdgeFile.

For this reason and unlike the Assembly or the Draft PacEdge, multiple files are allowed to be selected and the button for this PacEdge cane be clicked several times by the user to pick multiple files in multiple attempts followed by removing few files as well from the list until the user has all the required Part and Sheetmetal files in the PacEdge.

Hence the first line in the PAR+PSM PacEdge button’s Click event checks if the current or active PacEdge is a PAR+PSM or not.

If this is the first time the button has been clicked then the ResetPacEdge function called which empties the ListOfSolidEdgeFiles and also clears the TreeList.

If Not ActivePacEdgeMode = PacEdgeMode.PartAndSheetmetalPacEdge Then

  ResetPacEdge()

  ActivePacEdgeMode = PacEdgeMode.PartAndSheetmetalPacEdge

End If

If not, which means this is a successive attempt by the user to add more files to the PAR+PSM PacEdge then the ResetPacEdge function won’t be called.

Continued to part 7... 


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