Message 1 of 10

Not applicable
10-05-2018
05:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey,
i have a rule wich fills in iproperties from an excel file.
i wanted to add a progressbar wich works but it has a cancel option.
Now i want to make my rule stop when i hit that cancel button.
When i hit cancel, it will close the progressbar but not end the rule
Sub Main() doc = ThisDoc.ModelDocument 'check file type Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmCompDef.Occurrences.AllLeafOccurrences Dim totalCount As Integer totalCount = 0 For Each oOcc In oLeafOccs totalCount = totalCount + 1 Next progBar = New TestProgressBar(ThisApplication) progBar.Start(totalCount) Dim cnt As Integer = 0 For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) Dim oUOM As UnitsOfMeasure oUOM = oOccurrence.Definition.Document.UnitsOfMeasure Dim Aream As String Aream = Round(iProperties.AreaOfComponent(oOccurrence.Name)/1000000,2) Dim strArea As String strArea = Aream & "m²" map = Left(ThisDoc.FileName(False),6) & ".xlsx" xls = "C:\VaultWorkspace\Projecten" info = xls & "\" & map Dim Titel As String Titel = GoExcel.CellValue(info, "Pro-info","C10") Dim Subject As String Subject = GoExcel.CellValue("C11") Dim Manager As String Manager = GoExcel.CellValue("C41") Dim Project As String Project = GoExcel.CellValue("C39") Dim Klant As String Klant = GoExcel.CellValue("C33") Dim Projectnaam As String Projectnaam = GoExcel.CellValue("C10") Dim Subbeschrijving As String Subbeschrijving = GoExcel.CellValue("C11") If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then If Not oOccurrence.Definition.BOMStructure = 51973 Then cnt = cnt + 1 progbar.update(cnt,totalCount) iProperties.Value(oOccurrence.Name, "Custom", "Aream") = strArea iProperties.Value(oOccurrence.Name, "Summary", "Title") = Titel iProperties.Value(oOccurrence.Name, "Summary", "Subject") = Subject iProperties.Value(oOccurrence.Name, "Summary", "Manager") = Manager iProperties.Value(oOccurrence.Name, "Project", "Project") = Project iProperties.Value(oOccurrence.Name, "Custom", "Klant") = Klant iProperties.Value(oOccurrence.Name, "Custom", "Projectnaam") = Projectnaam iProperties.Value(oOccurrence.Name, "Custom", "Subbeschrijving") = Subbeschrijving If Left (oOccurrence.Name,6) = Left (ThisDoc.FileName(0),6) Then iProperties.Value(oOccurrence.Name, "Project", "Part Number") = Mid (oOccurrence.Name,8,12) Else iProperties.Value(oOccurrence.Name, "Project", "Part Number") = " " End If End If End If Next progBar.Finish() MsgBox("Finished") End Sub Public Class TestProgressBar Private WithEvents progBar As Inventor.ProgressBar Private invApp As Inventor.Application Public Sub New(InventorApp As Inventor.Application) invApp = InventorApp End Sub Public Sub Start(totalCount) progBar = invApp.CreateProgressBar(False,totalCount,"Filling in iproperties", True) End Sub Public Sub Update(cnt, totalCount) progBar.Message = ("Processing file " & cnt & " of " & totalCount & "...") progBar.UpdateProgress End Sub Public Sub Finish() progBar.Close() End Sub Private Sub progBar_OnCancel() Handles progBar.OnCancel progBar.Close() MsgBox("Filling in iPoperties is cancelled") return End Sub End Class
Solved! Go to Solution.