iLogic error on first run

iLogic error on first run

mbrB43N5
Participant Participant
639 Views
7 Replies
Message 1 of 8

iLogic error on first run

mbrB43N5
Participant
Participant

Hello 

 

I have been trying to figure out why the below rule fails on the first run after opening the file. The rule was much longer, but I have narrowed it down to the below. 

 

It is important to note that the rule only fails on the first run after opening the file. Afterwards it runs as expected. 

 

The error seems to occur because of the "Feature.IsActive" lines which causes the variable "Bracket" to throw exception on all properties and methods. In this case the error occurs when trying to reach the visibility property of Bracket. 

 

I have been using Inventor 2022 and I hope you guys can help me solve this small mystery 🙂 

 

Sub Main

'The following two lines trigger an error the first time the rule is run after the document is opened. 

	Dim Bracket As SurfaceBody
	Bracket = ThisDoc.Document.ComponentDefinition.SurfaceBodies.Item(1)

'When the feature is activated/deactivated, the variable o40x40 is "lost"
	
	Feature.IsActive("MirrorBracket") = True
	Feature.IsActive("MirrorBracket") = False

'Error occurs on next line as the variable "Bracket" has been "lost"
	
	If Bracket.Visible Then
		Bracket.Visible = False
	Else
		Bracket.Visible = True
	End If

End Sub

 

0 Likes
640 Views
7 Replies
Replies (7)
Message 2 of 8

basautomationservices
Advocate
Advocate

I can't try it out with your part because I'm still on Inventor 2021, but it sounds like you are trying to set the visibility of a suppressed feature?

 

Once the feature is suppressed, it is not possible to set the surface bodies visibilty. 

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 3 of 8

mbrB43N5
Participant
Participant

Thank you for your reply 🙂 

 

I set visibility "Solid1 (Bracket)" and the feature I suppress/unsuppress is the mirror feature. I hope this clarifies. 

Please see the pics below. 

mbrB43N5_0-1651219549333.png

mbrB43N5_1-1651219683982.png

 

 

0 Likes
Message 4 of 8

basautomationservices
Advocate
Advocate

I see, the same is happening for me. Strange that is is only the first time indeed, when you activate/deactive the mirror feature the 'Bracket' variable is invalidated.

 

When I swap the lines, it's fine though. Is this a possible workaround for you?

 

Sub Main

'The following two lines trigger an error the first time the rule is run after the document is opened. 
	
	Feature.IsActive("MirrorBracket") = True
	Feature.IsActive("MirrorBracket") = False

	Dim Bracket As SurfaceBody
	Bracket = ThisDoc.Document.ComponentDefinition.SurfaceBodies.Item(1)
	
	If Bracket.Visible Then
		Bracket.Visible = False
	Else
		Bracket.Visible = True
	End If

End Sub

 

Another thing, I don't know what you will be using this for, but using the mirror feature and turning the original's visibility off will leave you with the wrong mass for the part (if you are only looking to keep the mirrored part after toggling it using the rule). If this is important I would mirror the sketch and have two extrude features which you can suppress.

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 5 of 8

mbrB43N5
Participant
Participant
You are completely right and I also came to this conclusion and it can be fixed by altering the "Featur.IsActive" line. However this code is broken down solely with the purpose of investigating this error that only occurs on the first run. So the rule does not have any practical purpose anymore. My issue is that this error could occur in a much more complicated rule if we don't know the reason for it.
0 Likes
Message 6 of 8

basautomationservices
Advocate
Advocate

You're right. I also don't know what's going on here but it looks like a bug.

 

I'm getting the same results in VBA in Inventor 2021. Only on the first run after opening the part. When setting the surfacebody and after toggling suppression on its mirror, the object is invalidated. 

 

basautomationservices_0-1651221690121.png

 

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 7 of 8

mbrB43N5
Participant
Participant
Yes. This is also what I have seen in Visual Studio. I just don't understand why the "Feature.IsActive" invalidates the variable.

But hopefully someone in here can come up with an explanation or tell if it should be reported as a bug.
0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

Hi guys.  Just some more food for thought.  One of the first things I noticed when reading down through this case a minute ago was that there is just one solid body, not two.  So the mirror feature is not creating its own new solid body, it is sharing the same original body.  This is likely key to this behavior.  Also, just because it sounds simple to try, and logical, maybe try putting something like a document update or document rebuild line like 'iLogicVb.DocumentUpdate' or 'Document.Update' or 'Document.Rebuild' right at the start of the rule, or in various other places throughout the rule, and see if that has any effect.  I have heard of others having similar first run issues before, and it seems like some things may not be fully loaded into session memory yet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes