Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic won't run when expected.

machiel.veldkamp
Collaborator

iLogic won't run when expected.

machiel.veldkamp
Collaborator
Collaborator

I have a bunch of iLogic rules (external) set to trigger when the Document is saved or when the geometry changes. 

 

Long story short; they don't work. 

 

Here's what I've checked:

image.png

 

 

 

 

 

 

 

 

 

 

 

 

 

image.png

 

The things I've tried:

- The rules work when I click "Run Rule" perfectly. 

- Restart Inventor

- Restart the PC

- Check code for obvious mistakes

- This has been happening for some time now (months)

 

What could be happening here? Inventor is updated to 2018.3.4

 

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Reply
Accepted solutions (1)
1,595 Views
17 Replies
Replies (17)

machiel.veldkamp
Collaborator
Collaborator

I'd really like a solution to this please.

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

AlexFielder
Advisor
Advisor

Can you share the file or files that aren't working?

0 Likes

machiel.veldkamp
Collaborator
Collaborator

Sure!

 

This is the most important one. 

 

Sub Main()
	'Prevents Inventor from crashing.
	'---------------------------------------------------------------------------------------------
	InventorVb.DocumentUpdate()

	'Check if open document is sheetmetal
	'---------------------------------------------------------------------------------------------

	Dim oDoc As Document = ThisApplication.ActiveDocument
	If oDoc.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		Exit Sub
	Else
	End If
	'MsgBox("Is sheetmetal")

	'Check if open sheetmetal document has flatpattern view
	'---------------------------------------------------------------------------------------------
	Dim oSMD As SheetMetalComponentDefinition
	oSMD = oDoc.ComponentDefinition
	If Not oSMD.HasFlatPattern Then Exit Sub
	Dim oFlat As FlatPattern = oSMD.FlatPattern
	'MsgBox("Has flatpattern")

	'Check for bend features
	'---------------------------------------------------------------------------------------------
	Try
		Dim BendCount As Integer = oSMD.Bends.Count
		If BendCount < 1 Then Exit Sub
		'MsgBox("# bends " & BendCount)
	Catch
		'MsgBox("error: Sheetmetalcomponentdefinition.Bends.Count (Can't find bends?)")
		Exit Sub
	End Try

	'Check if feature "BendMarkerHoles" exists
	'---------------------------------------------------------------------------------------------
	Dim FeatureName As String = "BendMarkerHoles"

	Try
		Dim oFTS As FlatPatternFeatures = oFlat.Features
		If oFTS.Count > 0 Then
			For Each oFT As PartFeature In oFTS
				If oFT.Name <> FeatureName Then Continue For
				Try
					oFT.Delete()
				Catch

				End Try
				Exit For
			Next
		End If
	Catch
		MsgBox("error in MAIN()")
	End Try

	BendMarker(oFlat)

End Sub

Sub BendMarker(oFlat As FlatPattern)
	Dim oEdges As Edges
	Dim oHoleCenters As Object = ThisApplication.TransientObjects.CreateObjectCollection
	Dim oSketch As PlanarSketch

	'Flatpattern sketch -------------------------------------------------------------------------
	Try
		oSketch = oFlat.Sketches.Add(oFlat.TopFace, True)
	Catch
		oSketch = oFlat.Sketches.Add(oFlat.BottomFace, True)
	End Try

	oSketch.Edit()

	'Detect bend down ---------------------------------------------------------------------------
	Try
		oEdges = oFlat.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True)
		WorkEdges(oHoleCenters, oSketch, oEdges)
	Catch
		MsgBox("error: GetEdgesOfType 64005/kBendDownFlatPatternEdge")
	End Try

	'Detect bend up -----------------------------------------------------------------------------
	Try
		oEdges = oFlat.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True)
		WorkEdges(oHoleCenters, oSketch, oEdges)
	Catch
		MsgBox("error: GetEdgesOfType 64004/kBendUpFlatPatternEdge")
	End Try
	Call oFlat.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHoleCenters, 0.1, kPositiveExtentDirection)

	Try
		Dim oHoleFeat As HoleFeature = oFlat.Features.HoleFeatures.Item(1)
		oHoleFeat.Name = "BendMarkerHoles"

		oSketch.ExitEdit()
		oSketch.Name = "MarkedBends"
	Catch
		MsgBox("error: GetEdgesOfType kBendUpFlatPatternEdge (64004) en/of kBendDownFlatPatternEdge (64005) kunnen niet worden gevonden")
	End Try
	
End Sub

Sub WorkEdges(ByRef oHoleCenters As Object, ByRef oSketch As PlanarSketch, oEdges As Edges)

	'Create list of coördinates
	'-------------------------------------------------------------------------------------------
	Dim oDoc As Document = ThisDoc.Document
	Dim oSMD As SheetMetalComponentDefinition
	oSMD = oDoc.ComponentDefinition

	Dim oLoft As Integer = 0
	For Each HFeature As LoftedFlangeFeature In oSMD.Features.LoftedFlangeFeatures
		oLoft = 1
	Next

	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

	Dim Xi As Integer = 0

	Dim BendCount As Integer = oSMD.Bends.Count
	BendCount *= 4
	Dim oPointGrid(BendCount, 1) As Double

	For Each oEdge As Edge In oEdges
		Try
			Dim oEnt As SketchEntity = oSketch.AddByProjectingEntity(oEdge)

			oPointGrid(Xi, 0) = oEnt.StartSketchPoint.Geometry.X.ToString
			oPointGrid(Xi, 1) = oEnt.StartSketchPoint.Geometry.Y.ToString

			Xi = Xi + 1
			oPointGrid(Xi, 0) = oEnt.EndSketchPoint.Geometry.X.ToString
			oPointGrid(Xi, 1) = oEnt.EndSketchPoint.Geometry.Y.ToString
			Xi = Xi + 1

			oEnt.Delete	'Deleting projected geometry
		Catch
			'MsgBox("error")
		End Try
	Next

	If Xi = 0 Then Exit Sub

	'Loft Filter Start
	'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	If oLoft = 0 Then GoTo Endloft
	'MsgBox("Loft Code")

	Dim intCount1, intCount2 As Integer
	Dim DictX As Object = CreateObject("Scripting.Dictionary")
	Dim DictY As Object = CreateObject("Scripting.Dictionary")

	'Filter Points within certain promximity of each other
	'-------------------------------------------------------------
	For intCount1 = 0 To Xi
		For intCount2 = 0 To Xi
			If intCount1 <> intCount2 Then
				'																		2D-array
				'																		 |_0__|_1__|
				'																		0|_X__|_Y__|	0,0 = x coördinate 0,1 = y coördinate
				'																		1|_X__|_Y__|	1,0 = x coördinate 1,1 = y coördinate
				'																		2|_X__|_Y__|	2,0 = x coördinate 2,1 = y coördinate			


				'											X-Value intCount1		  X-Value intCount2									Y-Value intCount1	   	  Y-Value intCount2			
				'						Compare			2D Array Cel X,0	With	  2D Array Cel X,0			And		Compare			2D Array Cel X,1	With	  2D Array Cel X,1
				If EqualWithinTolerance(oPointGrid(intCount1, 0), oPointGrid(intCount2, 0), 0.1) And EqualWithinTolerance(oPointGrid(intCount1, 1), oPointGrid(intCount2, 1), 0.1) Then
					Try
						DictX.Add(oPointGrid(intCount2, 0) & " " & oPointGrid(intCount2, 1), oPointGrid(intCount2, 0))
						DictY.Add(oPointGrid(intCount2, 0) & " " & oPointGrid(intCount2, 1), oPointGrid(intCount2, 1))
					Catch
						'Nothing
					End Try
				End If
			End If
		Next intCount2
	Next intCount1
	'MsgBox("IntCount " & intCount1 & " " & intCount2)

	'Filter points.
	'Only the points which are not close to each other remain.
	'-------------------------------------------------------------
	Dim i As Integer = 0
	Dim oPointGridFilteredX As Object = CreateObject("Scripting.Dictionary")
	Dim oPointGridFilteredY As Object = CreateObject("Scripting.Dictionary")

	For i = 0 To Xi
		If Not Xi = 0 Then
			If Not DictX.Exists(oPointGrid(i, 0) & " " & oPointGrid(i, 1)) Then
				oPointGridFilteredX.Add(oPointGrid(i, 0) & " " & oPointGrid(i, 1), oPointGrid(i, 0))
				oPointGridFilteredY.Add(oPointGrid(i, 0) & " " & oPointGrid(i, 1), oPointGrid(i, 1))
			Else
				'Nothing
			End If
		End If
	Next

	'Convert the created dictionary of filtered points into an 2d-array
	'-------------------------------------------------------------
	Dim ArrayFiltered(oPointGridFilteredX.Count - 1, 1) As Double
	Dim ii As Integer = 1

	For ii = 0 To oPointGridFilteredX.Count - 1
		ArrayFiltered(ii, 0) = oPointGridFilteredX.Items()(ii)
		ArrayFiltered(ii, 1) = oPointGridFilteredY.Items()(ii)
	Next

	'Place holecenters
	'--------------------------------------------
	Dim iii As Integer = 0

	For iii = 0 To ii - 1
		Dim oP = oSketch.SketchPoints.Add(oTG.CreatePoint2d(ArrayFiltered(iii, 0), ArrayFiltered(iii, 1)), True)
		'MsgBox("oP " & ArrayFiltered(iii, 0) & " " & ArrayFiltered(iii, 1))
		If Not (ArrayFiltered(iii, 0) = 0 And ArrayFiltered(iii, 1) = 0) Then
			'MsgBox("oP " & ArrayFiltered(iii, 0) & " " & ArrayFiltered(iii, 1))
			oHoleCenters.Add(oP)
		End If
	Next

	'Loft Filter End
	'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------		

	'Place holecenters
	'--------------------------------------------
	If oLoft = 1 Then Exit Sub

	Endloft :
	'MsgBox("Non Loft Code")

	For Each oEdge As Edge In oEdges
		Dim oEnt As SketchEntity = oSketch.AddByProjectingEntity(oEdge)
		Dim P As Point2d = oEnt.StartSketchPoint.Geometry
		Dim oSP As SketchPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(P.X, P.Y), True)
		oHoleCenters.Add(oSP)
		P = oEnt.EndSketchPoint.Geometry
		Dim oEP As SketchPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(P.X, P.Y), True)
		oHoleCenters.Add(oEP)
	Next
End Sub

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

machiel.veldkamp
Collaborator
Collaborator

Any ideas

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

AlexFielder
Advisor
Advisor

Sorry, @machiel.veldkamp I didn't see your earlier reply.

 

My best advice (without any provided Inventor files to test your rule on) is to comment out the Try Catch blocks you have as one of them could be hiding an underlying error in the rule. If it runs without them, then slowly add them one by one testing as you go.

 

It's tedious I know; did you say the rule was previously functioning correctly? If so, perhaps a roll-back of the latest-installed hotfix for Inventor might help.

0 Likes

machiel.veldkamp
Collaborator
Collaborator

Yeah. Pre-2018 these and all other rules were functioning fine. 

 

Since 2018 sometimes rules won't be triggered. Now trigger them manually. 

It's not the rule that is not working. IT IS THE TRIGGER

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

machiel.veldkamp
Collaborator
Collaborator

So. Any other ideas?

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

AlexFielder
Advisor
Advisor

I'm not sure if you have a version of Inventor prior to 2018 installed, but if you do perhaps you can create a screencast showing how this rule used to function?

 

And then perform the same steps inside of Inventor 2018 for comparison.

 

Also, are you certain that the files in which the rule doesn't run are not Library files? This was a change Autodesk made in Inventor 2018 to "...maintain consistency with the UI behavior."

 

https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/sfdcarticles/sfdcartic...

 

One other thing, right at the top of the rule you refer to the "DocumentSubTypeID" - I doubt this will have changed between versions, but it's worth checking otherwise your rule will exit at this line:

2019-02-15 09_32_47-iLogic won't run when expected. - Autodesk Community- Inventor Products.png

 

A better approach might be to do this instead:

 

If Not TypeOf ThisApplication.ActiveDocument.ComponentDefinition Is SheetMetalComponentDefinition Then
    Exit Sub
End If

:slightly_smiling_face:

0 Likes

machiel.veldkamp
Collaborator
Collaborator

Again. The rules work. They are not broken. It's the triggers that are not working. 

This is not the only rule we have. They all work fine when you select them manually. 

 

https://www.youtube.com/watch?v=Dh74EFsj7y8&feature=youtu.be

 

Sometimes they do work most of the time they don't. 

 

The rules are fine. They have been fine for a long time. The triggers worked fine. They don't anymore since we got new templates. 

 

I have checked every obvious thing that could be wrong. I can't find any obvious setting or thing that doesn't work. 

Hence my suspicion that there is something else at play. 

 

My coworkers have the same issue. Sometimes it works fine but 98% of the time it doesn't. 

 

We should get IV2020 this summer. Hopefully the problem is solved then. 

 

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

AlexFielder
Advisor
Advisor

Can you share the file in the YouTube clip? I have 2018.something (as well as 2019.3) installed so can see if your trigger works for me.

0 Likes

machiel.veldkamp
Collaborator
Collaborator

Yes. Here you go.

 

 

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

AlexFielder
Advisor
Advisor

I tried your file and after having created a simple iLogic rule that displayed a messagebox I got this:

(See attachment)iLogic It no worky (Except when it does).gif

I didn't change anything other than dragging the EOP marker up and then down again.

 

My Inventor version is 2018.3.4 Build 284

 

I will try the same file in 2019.3

0 Likes

AlexFielder
Advisor
Advisor

Here's a short gif of the 2019.3 attempt:

iLogic It no worky (Except when it does in 2019.3).gif

Thoughts?

0 Likes

machiel.veldkamp
Collaborator
Collaborator

So.. It works in 2019.3 right?

 

Have you tried in 2018?

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

machiel.veldkamp
Collaborator
Collaborator
Accepted solution

Holy fudgeballs!

 

I think I found the error. 

 

In one of my many ****ty iLogic Rules I had this line of code

iLogicVb.Automation.RulesOnEventsEnabled = False									'Disable all iLogic rules

I guess this doesn't automatically turn back to TRUE  after the rule is run. 

 

 

I think deleting this line might have solved it! 

 

Just gonna run some tests but ... Oh heck, I feel like an idiot. 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________

AlexFielder
Advisor
Advisor

There's little need to feel bad. As I used to tell my trainees: it's only easy if you know how.

 

My own iLogic library could do with a spit & polish, I may borrow your naming structure for it. :slightly_smiling_face:

machiel.veldkamp
Collaborator
Collaborator

Yes. The more you know maxresdefault

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes