Friday 5 December 2014

Making of PacEdge Part 11

...continued from part 10
Specify PacEdge File (ZIP): This button again simply displays the same File open dialog with a .zip filter to allow user specify a PacEdge i.e. .zip file which is stored in the Form level variable sPacEdgeFile.
Create PacEdge: This button when clicked first checks if a PacEdge file (.zip) has been specified.
If sPacEdgeFile = String.Empty Then

  MessageBox.Show("Specify a PacEdge file first.", "Create PacEdge", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

  Exit Sub

End If

Next pBar which is a progress bar control is made visible, its minimum value is set to 0 and the maximum value is set to the total count of files in the various nodes together:
pBar.Visible = True

pBar.Minimum = 0

pBar.Maximum = nodeASM.ChildrenCount + nodePAR.ChildrenCount + nodePSM.ChildrenCount + nodeDFT.ChildrenCount + nodeOther.ChildrenCount

The mouse cursor over the Form is set to the wait cursor:
Me.Cursor = Cursors.WaitCursor
Next it is checked if the user has opted to use a password for the PacEdge and also if there is a non-blank password entered in the password TextBox:
If chkPassword.Checked = True Then

If txtPassword.Text <> String.Empty Then

sPassword = txtPassword.Text.Trim

End If

End If

To zip the files, another freeware Ioniz.Zip library is used which can be obtained from codeplex.
The DLL is referenced in the project from Project > Add References… and can be seen listed under References in the solution Explorer:
This is also imported into the project using the Imports statements:

Imports Ionic

Imports Ionic.Zip

The general format for the zipping process using the Ionic Zip library is as below:

Using oZip as Ionic.Zip.Zipfile = New Ionic.Zip.ZipFile("\\Path\")

  oZip.Password = "PassOnTheWord" ‘[Password is optional]





End Using

Acordingly, the using statement starts the process of creating the PacEdge as below:
Using PacEdge As Ionic.Zip.ZipFile = New Ionic.Zip.ZipFile(sPacEdgeFile)
The password is first added:
If sPassword.Trim <> String.Empty Then

  PacEdge.Password = sPassword.Trim

End If

First the files under the Assembly node are added:
For Each n As TreeListViewItem In nodeASM.Items

  txtStatus.Text = "PacEdging Solid Edge assembly file..." + vbCrLf + n.SubItems(0).Text + ".asm"

  PacEdge.AddFile(n.SubItems(2).Text + "\" + n.SubItems(0).Text + ".asm")

  pBar.Value += 1



The file name is built using the Path and the file name from the respective columns of the assembly file node. Note the status TextBox is updated as the files are added so the user knows the status.
The DoEvents calls facilitates updating the ProgressBar display when the files are being added. If you don’t find this to be working, try using a BackGroundWorker about which I have little or no knowledge.
Similarly, the files from other Solid Edge nodes and finally the OtherFiles node are also added to the PacEdge.
The mouse cursor is restored back to Default and the user is notified about the PacEdge:
txtStatus.Text = "Creating PacEdge..." + vbCrLf + sPacEdgeFile


End Using

Me.Cursor = Cursors.Default

pBar.Visible = False

txtStatus.Text = "Created PacEdge" + vbCrLf + sPacEdgeFile

MessageBox.Show("Created PacEdge" + vbCrLf + sPacEdgeFile)

Most of the functions have been described here. I do not guarantee this would meet all of your needs.
If you find mistakes or bugs, do rectify them.
This is not a final release and you can send me mails when you find bugs:
The objective is to give a god starting point so keep the code for personal use - Do not exploit it commercially.

 15Download the PacEdge Source Code here.
 24  Join the Solid Edge User's Group on Facebook.
Note: You might be aware that it is not necessary to share your profile or personal details to join this Facebook group nor be friends with the owner of the group.

PacEdge is part of the Solid Edge Maker Faire. The other programming tutorials in this series are:

Making of Match Properties for Solid Edge

Making of Purge Variables for Solid Edge

Making of Rectangle Centerlines for Solid Edge

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

No comments:

Post a Comment