total ilogic time ? how does I see that?

total ilogic time ? how does I see that?

Darkforce_the_ilogic_guy
Advisor Advisor
370 Views
4 Replies
Message 1 of 5

total ilogic time ? how does I see that?

Darkforce_the_ilogic_guy
Advisor
Advisor

is that a way to see how mush extra saving time is cause by the running ilogic ? .. I have more then one code  and I want to total time on running on the ilogic code ... not the total saving time. on an Large assembly, and it sub parts 

 

0 Likes
371 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @Darkforce_the_ilogic_guy.  One tool that comes to mind that you may be able to use is the Stopwatch object (System.Diagnostics.Stopwatch).  You can create a new instance of one by using the 'New' keyword when declaring its variable.

Here is a very simple example of its use.

Dim oTimer As New Stopwatch
oTimer.Start
'Do some stuff here
Dim i As Long
Dim oCode As Long
For i = 1 To 1000000
	oCode = ThisApplication.Locale
Next
'This one is more specific (shows 3 decimal places after seconds)
MsgBox("Elapsed time = " & oTimer.ElapsedMilliseconds / 1000 & " seconds", , " ")
'or this one doesn't have any decimal places
'MsgBox("Elapsed time = " & oTimer.Elapsed.Seconds & " seconds",," ") 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Michael.Navara
Advisor
Advisor

Another approach is to extract time measure code to external file

 

iLogic rule with usage sample

AddVbFile "C:\Temp\TimeMeasure.vb"

Sub Main()
	TimeMeasure.Start()

	MsgBox("Wait for exit code")
	
	Logger.Debug(TimeMeasure.Duration)
End Sub

	

 

TimeMeasure.vb code

Class TimeMeasure
	Shared startTime As DateTime
	Shared Sub Start()
		startTime = DateTime.Now
	End Sub
	
	Shared Function Duration() As Double
		Return (DateTime.Now - startTime).TotalSeconds
	End Function
End Class
Message 4 of 5

TechInventor20
Advocate
Advocate
Dim stopWatch As New Stopwatch()
 stopWatch.Start()
'------------------


'Your code



'-----------------
stopWatch.Stop()
' Get the elapsed time as a TimeSpan value.
Dim ts As TimeSpan = stopWatch.Elapsed

' Format and display the TimeSpan value.
Dim elapsedTime As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
MsgBox("RunTime " & elapsedTime)
0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Just throwing another thought into the mix here.  Since you may be running multiple iLogic rules across many documents, you could incorporate the use of SharedVariables into this project.  As you may already know, they are a way to temporarily store data within Inventor's 'session memory'.  Therefore that data you store that way will remain available as long as your Inventor session remains active, and you have not removed the data by using the SharedVariable.Remove() or SharedVariable.RemoveAll methods.

 

And another thought would be to use another iLogic rule as a starting point for running a series of other iLogic rules and/or VBA macros, but start your Stopwatch just before running that series of other rules, then stop the Stopwatch right after control returns to that top rule, then format the resulting time however best suits your needs, then write it to the iLogic Logger, or out to a more permanent external Log file.  In my testing, the multi-rule accumulated time total seemed accurate.  But keep in mind, that if you use interactive prompts, such as MsgBox, MessageBox.Show, InputBox, etc, those will allow elapsed time to keep counting while it is waiting on the user to respond, before moving forward with the remaining rule code, which can cause inaccuracies in recording true code processing time.

 

Here is a simple example of both ideas:

Dim oStopwatch As Stopwatch = Nothing
If SharedVariable.Exists("iLogic Stopwatch") Then
	oStopwatch = SharedVariable.Value("iLogic Stopwatch")
Else
	oStopwatch = New Stopwatch
End If
If Not oStopwatch.IsRunning Then oStopwatch.Start
'-----------------------------------------------------------------------------
'do some stuff here directly,
'or run multiple other rules/macros from here
'iLogicVb.RunRule("InternalRuleName1")
'iLogicVb.RunExternalRule("ExternalRuleName1")
'iLogicVb.RunMacro("ProjectName", "ComponentName", "MacroName")
'----------------------------------------------------------------------------
If oStopwatch.IsRunning Then oStopwatch.Stop
Dim oElapsed As TimeSpan = oStopwatch.Elapsed
Dim oTimeStr As String = oElapsed.Hours & " hrs " & oElapsed.Minutes & " min " _
& oElapsed.Seconds & " sec " & oElapsed.Milliseconds & " ms"
Logger.Info("Stopwatch Elapsed Time = " & oTimeStr)
SharedVariable.Value("iLogic Stopwatch") = oStopwatch
'or
'SharedVariable.Remove("iLogic Stopwatch")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes