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

Hi, I usually use an external rule similar to the one I share below to add an internal rule.
You must be careful when you try to add a quotation mark character, you must duplicate it within the rule, otherwise you will have error.

Sub Main
	
Dim oDoc As Document = ThisDoc.Document

If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject AndAlso
 iProperties.Volume > 0 Then	
 
Dim RuleName As String = "Thickness_Rule"
Dim RuleText As String = "'Example of Ilogic Rule" & vbCrLf & _
						"iProperties.Value(""Project"", ""Stock Number"") = ""t = "" & Thickness & "" mm"""
            
Dim RuleAlreadyExists As Boolean = False
' Define the iLogic addin
Dim iLogicAddIn As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
' Get the iLogic automation object
Dim iLogic As Object = iLogicAddIn.Automation
' Get the list of iLogic rules in the current Inventor document
Try
	iLogic.DeleteRule(oDoc, RuleName)
	iLogic.AddRule(oDoc, RuleName, RuleText)
Catch
    iLogic.AddRule(oDoc, RuleName, RuleText)
End Try

	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
	EventPropSet.Add(RuleName, "AfterAnyParamChange", 1000)
	EventPropSet.Add(RuleName, "PartBodyChanged ", 1200)
	EventPropSet.Add(RuleName, "AfterDocSave",800)

'After Open Document					: AfterDocOpen                 		: 400
'Close(Document)						: DocClose                     		: 500
'Before Save Document                   : BeforeDocSave           			: 700
'After Save Document               		: AfterDocSave               		: 800
'Any Model Parameter Change        		: AfterAnyParamChange   			: 1000
'Part Geometry Change**            		: PartBodyChanged         			: 1200
'Material Change**                  	: AfterMaterialChange     			: 1400
'Drawing View Change***               	: AfterDrawingViewsUpdate  			: 1500
'iProperty(Change)                  	: AfterAnyiPropertyChange           : 1600
'Feature Suppression Change**          	: AfterFeatureSuppressionChange   	: 2000
'Component Suppression Change*   		: AfterComponentSuppressionChange 	: 2200
'iPart / iAssembly Change Component* 	: AfterComponentReplace   			: 2400
'New Document                         	: AfterDocNew                  		: 2600

InventorVb.DocumentUpdate()
	
End If
End Sub


Function GetiLogicEventPropSet(cDocument As Document) As Inventor.PropertySet
	On Error Resume Next
		iLogicEventPropSet = cDocument.PropertySets.Item("iLogicEventsRules")
		
		If iLogicEventPropSet Is Nothing Then
			iLogicEventPropSet = cDocument.PropertySets.Item("_iLogicEventsRules")
		End If
		
		If iLogicEventPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then
			Call iLogicEventPropSet.Delete
			iLogicEventPropSet = cDocument.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
		End If
		
		If iLogicEventPropSet Is Nothing Then
			iLogicEventPropSet = cDocument.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
		End If
		
		If iLogicEventPropSet Is Nothing Then
			MsgBox ("Unable to create the Event Triggers property for this file!", , "Event Triggers Not Set")
			Err.Raise(1)
			Exit Function
		End If
	On Error GoTo 0
	
	Return iLogicEventPropSet
End Function


I hope this helps with your problem. Regards 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn