Ilogic Progress Bar

Ilogic Progress Bar

Anonymous
Not applicable
2,993 Views
6 Replies
Message 1 of 7

Ilogic Progress Bar

Anonymous
Not applicable

I'm wanting to put a progress bar in my rule below as on the larger assemblies it takes a couple of minutes to run.

I'm trying to count all the occurences in the assembly first to give the number of steps in my progress bar, and then everytime i go through to the next occurence move it on a step.

The one below only counts the top level occurences, and so if there is a large sub assembly, the progress bar stops for ages before it finishes the sub assembly, and moves onto the next occurence.

Is it possible to to count all occurences down all levels (and patterns) of the assembly and make the progress bar move a step when it goes through each one?

 

These recursive loops are hurting my brain!

 

SyntaxEditor Code Snippet

Sub Main()

    Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
    Dim oOcc_s As ComponentOccurrences = oCompDef.Occurrences
    Dim oUserParams As UserParameters = oCompDef.Parameters.UserParameters
    
    n=1
    
    For Each oOcc As ComponentOccurrence In oOcc_s
    n=n+1
    Next
    
    Dim iStepCount As Integer
    iStepCount = n
    Dim oDelay As Integer 
    oDelay = 0 'set delay time
    
    Dim oProgressBar As Inventor.ProgressBar
    
    i=1
    oMessage = "Updating... " 
    oProgressBar = ThisApplication.CreateProgressBar(False, iStepCount, oMessage)
    oProgressBar.Message = ("Loading... " )
    System.Threading.Thread.Sleep(oDelay)
    
    
    'look at each occurrence in the assembly
    For Each oOcc As ComponentOccurrence In oOcc_s
        
        'update params for each occurrence        
        UpdateParam(oOcc,oUserParams)
        oProgressBar.Message = ("Updating Part " & i & " of " & iStepCount)
        oProgressBar.UpdateProgress
        System.Threading.Thread.Sleep(oDelay)
        i=i+1
    Next
    oProgressBar.Close
    iLogicVb.UpdateWhenDone = True
End Sub
Sub UpdateParam(occ As ComponentOccurrence, params As Inventor.UserParameters)

 If Component.IsActive(occ.Name) = True

    Dim oParams As Parameters = occ.Definition.Parameters
    For Each param As UserParameter In params
        Try 
        oParams(param.Name).Value = param.Value
        Catch
        End Try
    Next
    
    For Each subOcc As ComponentOccurrence In occ.SubOccurrences
        UpdateParam(subOcc, params)

    Next
 End If
End Sub

 

0 Likes
2,994 Views
6 Replies
Replies (6)
Message 2 of 7

philip1009
Advisor
Advisor

When creating the Progress Bar, the number you put in the second statement has to be the Maximum number of steps that the progress bar will take, you have to create a loop to go through and count how many steps you want to take first then put that number in the Create Progress bar line.  Then when going through the actual rule progress, put in a ProgressBar.UpdateProgress to increment the step in the bar.  I'll provide an example from one of my rules later today.

0 Likes
Message 3 of 7

philip1009
Advisor
Advisor

Sorry it took so long, here's a sample for you:

 

SyntaxEditor Code Snippet

oRefDocs = ThisApplication.ActiveDocument.AllReferencedDocuments
Dim oDoc As Document
Dim iStepCount As Long = 0
Dim iStepMax As Long = 0
ThisApplication.SilentOperation = True
ThisApplication.ScreenUpdating = False
On Error GoTo EndRule
For Each oDoc In oRefDocs
	iStepMax += 1
Next
oProgBar = ThisApplication.CreateProgressBar(False, iStepMax, "Progress Bar Sample")
For Each oDoc In oRefDocs
	iStepCount += 1
	oProgBar.Message = "Scanning " + CStr(iStepCount) + " of " + CStr(iStepMax) + " files."
	oProgBar.UpdateProgress
Next
EndRule : oProgBar.Close
ThisApplication.SilentOperation = False
ThisApplication.ScreenUpdating = True

iStepCount is used for individual steps while iStepMax is the total the progress bar will count to.  In this sample it will count how many documents are used to build the assembly this rule is run from, then applies that total to iStepMax, which is what's used to create the progress bar.  Then at the beginning of the loop you start counting iStepCount up from 0 and you can also have a message in the progress bar to tell you exactly how many files of the total the code has looped through.

 

Make sure that the code you use has proper Error handling, otherwise the rule can fail and leave you with a progress bar that won't go away until you close Inventor.  For me I just have an On Error Goto the line that will close the progress bar and reset Inventor to working condition.

 

Let us know if you have any questions.

0 Likes
Message 4 of 7

Jef_E
Collaborator
Collaborator

You should pass the progressbar object to the update iProperties sub as ByRef, and update the progress there. Otherwise the sub occurrences won't be taken in account.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 5 of 7

Anonymous
Not applicable

Thanks Jef_E

I'm aware of what I need to do, but when I try to implement it my brain starts to get very confused with the recursive loops and i get loads of errors that I don't understand. I'm trying to copy others code and swap the values, but I don't really understand a lot of it e.g. sending an object between subs "as ByRef"

I've been using iLogic for the last few months, but this programming part of it is really slowing me down. Do you think a VB training course is the best way to go? Or is there one more specific to iLogic course that includes coding too? How did you learn?

Regards

Mark

 

0 Likes
Message 6 of 7

Jef_E
Collaborator
Collaborator

As I understand you are NOT aware of what you need to do... recursively shouldn't make anyone's brain hurt. It's just a sub like another..

 

Do some vb.net tutorials, follow a class, I don't know what suits you best. I trained myself via the www



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 7 of 7

AlexFielder
Advisor
Advisor

Taking a VB.NET course would absolutely help you with basic programming procedures/processes. Your reseller should be able to provide training on iLogic specifically.

0 Likes