iLogic Progress Bar

iLogic Progress Bar

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

iLogic Progress Bar

Anonymous
Not applicable

Hello,

I'm struggling trying to add a progress bar to the iLogic code attached below.  I'd like the progress bar to display each iPart member as it is processed so that I can see it's progress.  Thank you

 

 

0 Likes
Accepted solutions (3)
2,338 Views
6 Replies
Replies (6)
Message 2 of 7

YuhanZhang
Autodesk
Autodesk
Accepted solution

Firstly I suggest you to post  to Inventor Customization forum for Inventor API & iLogic questions.  Below is the updated iLogic code to show the progress bar, hope it helps:

 

Sub Main()

Call UpdateWeightOfiParts

End Sub

Sub UpdateWeightOfiParts()
    ' Get the active document.  This assumes it is a part.
    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument

    ' Check that this part is an iPart factory.
    If Not oPartDoc.ComponentDefinition.IsiPartFactory Then
        MsgBox ("This part must be an iPart factory.")
        Exit Sub
    End If

    Dim oFactory As iPartFactory
    oFactory = oPartDoc.ComponentDefinition.iPartFactory

    ' Check that there's a "Weight" column in the iPart table,
    ' and get its index in the table.
    Dim iWeightColumnIndex As Long
    iWeightColumnIndex = GetColumnIndex(oFactory, "Weight")
    If iWeightColumnIndex = -1 Then
        MsgBox ("The column ""weight"" does not exist in the table.")
        Exit Sub
    End If
	
	Dim oProgressBar As Inventor.ProgressBar
	oProgressBar = ThisApplication.CreateProgressBar(False,oFactory.TableRows.Count,"iPart Table Mass Update Process")
	
    ' Iterate through the rows
    Dim oRow As iPartTableRow
    For Each oRow In oFactory.TableRows
		
        ' Make this the active row so the model will recompute.
        oFactory.DefaultRow = oRow

        ' Get the weight.
        Dim dWeight As Double
        dWeight = oPartDoc.ComponentDefinition.MassProperties.Mass

        ' Convert it to current mass units defined by the document.
        Dim strWeight As String
        strWeight = oPartDoc.UnitsOfMeasure.GetStringFromValue(dWeight, kDefaultDisplayMassUnits)

        ' Set the row value for the weight column.
        oRow.Item(iWeightColumnIndex).Value = strWeight
		
		oProgressBar.UpdateProgress  
    Next
	
	oProgressBar.Close
End Sub

'' Function that given a factory and the name or a column will return
'' the index number of the column, if it's found in the factory's
'' table.  If the column is not found it returns -1.  The comparison
'' of the name is done in a case insensitive way.
Private Function GetColumnIndex(ByVal Factory As iPartFactory,ByVal ColumnName As String) As Long
'    ' Iterate through all of the columns looking for a
'    ' match to the input name.
    Dim i As Long
    For i =1 To Factory.TableColumns.Count
        Dim oColumn As iPartTableColumn
        oColumn = Factory.TableColumns.Item(i)

'        ' Compare this column with the input name.
        If LCase(oColumn.DisplayHeading)= LCase(ColumnName) Then
            ' A matching column was found so exit.
            GetColumnIndex = i
            Exit Function
        End If
    Next

    ' The column wasn't found so return -1.
    GetColumnIndex = -1
End Function


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 7

Anonymous
Not applicable

Thank you very much, this works great!  Out of curiosity, is it possible to display the active member being processed on the progress bar as it runs though the rule.  I was envisioning where it says "iPart Table mass Update Process" to also include the active member part number.  Or maybe state "active member  being processed".  I wasn't sure if iLogic is capable of this or not.  Thank you

0 Likes
Message 4 of 7

YuhanZhang
Autodesk
Autodesk
Accepted solution

Yes you can add below bold code line:

 

' Iterate through the rows
    Dim oRow As iPartTableRow
    For Each oRow In oFactory.TableRows
		oProgressBar.Message="Process the active row: " + oRow.MemberName
        ' Make this the active row so the model will recompute.
        oFactory.DefaultRow = oRow

        ' Get the weight.
        Dim dWeight As Double
        dWeight = oPartDoc.ComponentDefinition.MassProperties.Mass

        ' Convert it to current mass units defined by the document.
        Dim strWeight As String
        strWeight = oPartDoc.UnitsOfMeasure.GetStringFromValue(dWeight, kDefaultDisplayMassUnits)

        ' Set the row value for the weight column.
        oRow.Item(iWeightColumnIndex).Value = strWeight
		
		oProgressBar.UpdateProgress  
    Next

Then you will see the progress bar like below:

    ProgressBar.png

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 5 of 7

Anonymous
Not applicable

Hello @YuhanZhang 
When run in my Inventor Professional 2018 this code I receive this error. I didn't know how to debug it and I want to ask you for your help.
On the other hand it is a possibility to insert in the Weight cells only the value of the mass without adding the unit of measure (kg) at the end ?
Thank you.

14031971_0-1594234140510.png

 

0 Likes
Message 6 of 7

johnsonshiue
Community Manager
Community Manager

Hi! Please share the files here so forum experts can take a look.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 7 of 7

Anonymous
Not applicable
Accepted solution

Hello @johnsonshiue 

I've found now that from the code present in the post is missing the Set function of the variable (copied the correct code into the ipart_weight_progressbar.txt file)
Problem solved.
Please let me know if there is a possibility to show in the WEIGHT[KG] column only the weight values, without "kg" suffix (see image below)

With many thanks,
Lucian Crisan

14031971_0-1594726042135.png

without_kg_prefix.PNG