External Rule to create Internal rule

External Rule to create Internal rule

vkulikajevas
Advocate Advocate
797 Views
4 Replies
Message 1 of 5

External Rule to create Internal rule

vkulikajevas
Advocate
Advocate

How to create an External Rule, which could copy its content rule to as Internal Rule of the part?

 

For Example External Rule "Ext" has a line

iProperties.Value("Project", "Stock Number") = "t = " & Thickness & " mm"

I need this Rule "Ext" to be inserted into the part and named as "Int" 

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

Sergio.D.Suárez
Mentor
Mentor

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

Message 3 of 5

Sergio.D.Suárez
Mentor
Mentor

note that a function is added to add the events you need (you can remove this fragment if you do not need it)


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

0 Likes
Message 4 of 5

vkulikajevas
Advocate
Advocate

Thank you for fast reply, Sergio D. Suarez.

I have tried running this Rule multiple times, and it doesn't seem to do anything. It Doesn't show any error though.

0 Likes
Message 5 of 5

Curtis_Waguespack
Consultant
Consultant

@vkulikajevas wrote:

Thank you for fast reply, Sergio D. Suarez.

I have tried running this Rule multiple times, and it doesn't seem to do anything. It Doesn't show any error though.


Hi vkulikajevas ,

 

Make sure your file is a part file and has a volume (meaning you have at least one solid feature).

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

aaa.JPG

EESignature

0 Likes