- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
External Rule to create Internal rule
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@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