Progress Bar Issue

Progress Bar Issue

emanuel.c
Collaborator Collaborator
1,101 Views
7 Replies
Message 1 of 8

Progress Bar Issue

emanuel.c
Collaborator
Collaborator

I began to use the progress bar for a few rules and it seems to work OK on one hand, but then there seem to be other issues. For example, in this case I have a "lighting" update symbol on the assembly in the model tree, that I can't get rid of except for "Rebuild All". I have other bigger issues in the Drawing environment and I can give more info on that if needed.

I get the same issues with 2023 and 2024. Would be very grateful if someone would take a look at the code below and see if there is something clearly wrong.

 

Thank you!

 

Public Sub Main()

	Dim result = MessageBox.Show("You're running multiple rules which affect ALL parts in Assembly " & vbCr & fileName & vbCr & "Do you want to continue?", "Run GS and Other Rules", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
	If result = vbOK Then
		RunExternalRules
	Else
		Return
	End If
	
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	oDoc.Update
	oDoc.Save

End Sub

Sub RunExternalRules
	
	Dim oDoc As AssemblyDocument
	oDoc = ThisApplication.ActiveDocument
	Dim iDoc As Document
	
	'Define iLogic folder location
	Dim location As String = "M:\Autodesk Inventor\Ilogic\"
	Dim OtherLocation As String = location & "Other\"
'Set counter for counting parts Dim iPartCount As Integer iPartCount = 0 'Start a transaction for progress bar Call ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Editing All Parts...") 'Progress bar oMessage = "Editing All Parts And Saving, Please Wait..." PartCount = oDoc.AllReferencedDocuments.Count Dim oProgressBar As Inventor.ProgressBar oProgressBar = ThisApplication.CreateProgressBar(False, PartCount, oMessage) 'Iterate through all of the occurrences in the assembly For Each iDoc In oDoc.AllReferencedDocuments iPartCount = iPartCount + 1 Dim fileName As String = IO.Path.GetFileNameWithoutExtension(iDoc.FullFileName) 'Update the progress bar oProgressBar.Message = ("Working on part " & iPartCount & " of " & PartCount & " | " & fileName) oProgressBar.UpdateProgress 'Sheet Metal Type and Part Type If iDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Or iDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then auto = iLogicVb.Automation auto.RunExternalRule(iDoc, location & "GS") auto.RunExternalRule(iDoc, OtherLocation & "Delete User Parameter or iProperty") End If
Next oprogressbar.Close End Sub

 

 

0 Likes
Accepted solutions (2)
1,102 Views
7 Replies
Replies (7)
Message 2 of 8

emanuel.c
Collaborator
Collaborator

Here is an example of the issue in the Drawing environment. The progress bar seems to work well, but after running the rule, when I click on a sheet in the model tree the sheet changes all right but it doesn't highlight it any longer until I close the drawing and start over. If I add a new sheet it doesn't show in the model tree, until closing and re-opening that drawing. There seem to have been deeper and stranger issues too, with drawing not saving properly or views on sheets being raster etc. Yes, the code largely comes from the post on the first line as seen below.

 

' https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-drawing-views-scale/td-p/3875879

Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet
Dim oSheets As Sheets
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oScale As String
oActiveSheet = oDrawDoc.ActiveSheet
'oScale = InputBox("Enter Desired Scale", "Scaler", "1:1") oSheets = oDrawDoc.Sheets 'Create sheet counter variable Dim iSheetCount As Integer iSheetCount = 0 'Start a transaction Call ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Set Drawing View Scale") 'Progress bar oMessage = "Updating Drawing View Format" Dim SheetCount As Integer SheetCount = oDrawDoc.Sheets.Count Dim oProgressBar As Inventor.ProgressBar oProgressBar = ThisApplication.CreateProgressBar(False, SheetCount, oMessage) For Each oSheet In oSheets oSheet.Activate oViews = oSheet.DrawingViews 'Get the current sheet number iSheetCount = iSheetCount + 1 'Update the progress bar to reflect which sheet is being operated on oProgressBar.Message = ("Processing Sheet " & iSheetCount & " of " & SheetCount & "...") oProgressBar.UpdateProgress For Each oView In oViews If oView.ScaleFromBase = False Then Dim OrigScale As Double = 1/oView.Scale 'MessageBox.Show(OrigScale) Dim ScaleNumber As Double If OrigScale < 2 Then ScaleNumber = Format(OrigScale, "0.00") Else ScaleNumber = Format(OrigScale, "0") End If oView.Scale = 1 / ScaleNumber 'MessageBox.Show(ScaleNumber) End If Next Next oProgressBar.Close oActiveSheet.Activate  

 

0 Likes
Message 3 of 8

Michael.Navara
Advisor
Advisor
Accepted solution

I don't test your code, but following line is really bad.

 

'Start a transaction for progress bar
Call ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Editing All Parts...")

 

 

Method StartTransaction returns Transaction object which !!!MUST BE CLOSED!!! in any way.

If you want to use transactions use the following pattern

 

Sub TransactionPatternSample()
    Dim document As Document
    Dim displayName As String

    Dim t As Transaction = ThisApplication.TransactionManager.StartTransaction(document, displayName)
    Try
        'Do something in transaction

        'Successful
        t.End()

    Catch ex As Exception
        'Log or handle exception

        'Failed
        t.Abort()
    End Try
End Sub

For more info see this article

 

Message 4 of 8

emanuel.c
Collaborator
Collaborator

Hi @Michael.Navara thank you for the input! Do I have to use transaction manager or is there a better way to display progress bar? I took that line out and it still seems to work ok. It's the first time I'm using the progress bar and I can't find as much info on it. I'm more or less copying from what others have done.

 

Edit: I failed to see the help article you included. I'll take a look at that too.

Thank you!

0 Likes
Message 5 of 8

JelteDeJong
Mentor
Mentor
Accepted solution

I wrote 2 articles about transactions and the progress bar. They might interest you.

Stop long running rule (with the progress bar). 

Transactions for robust and fast rules 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 8

emanuel.c
Collaborator
Collaborator

Hi Jelte,

 

Thank you for your input and your wonderful blog! There isn't that much info on the progress bar and you are very helpful!

 

One question, the "Cancel" button doesn't really seem to work. It is nice to have, but I'm not sure if it has to do with timing or something, like by the time I click "Cancel" it's already on the next iteration of the progress bar so "Cancel" isn't applied. Has it been working for you?

 

On Transactions, I gather I don't really need to implement it just to run the progress bar, am I right? Thanks!

0 Likes
Message 7 of 8

JelteDeJong
Mentor
Mentor

It's possible to make the cancel button work but the problem is that it can't stop the code from running directly.

When the button is clicked an event is fired. The method "OnCancel()" in my blog code handles that event. In the method, I set the variable "UserClickedOnCancel". In the main code, you need to check that variable and if it is set to true then you can stop the method in a controlled way. In my example, I just do this:

If UserWantsToCancel Then Return

It's a bit weird but you might end up with this line of code in lots of places. 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 8 of 8

emanuel.c
Collaborator
Collaborator

Ah, that makes perfect sense. Thanks so much!

0 Likes