Message 1 of 16
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is it possible with i logic to replace one rule for another in Event Triggers.
Thanks
Solved! Go to Solution.
Is it possible with i logic to replace one rule for another in Event Triggers.
Thanks
Solved! Go to Solution.
It is possible but it uses some undocumented iProperties. check this:
Dim oldRuleName = "Rule0" Dim replaceWith = "Rule1" Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument Dim oETPropSet As PropertySet Try oETPropSet = oDoc.PropertySets.Item("iLogicEventsRules") Catch oETPropSet = oDoc.PropertySets.Item("_iLogicEventsRules") End Try If oETPropSet Is Nothing Then MsgBox("Couldn't find the Event Triggers property set. Exiting.", vbOKOnly + vbExclamation, " ") Exit Sub End If Dim prop = oETPropSet.Cast(Of [Property]).Where(Function(p) p.Value.Equals(oldRuleName)).FirstOrDefault() If (prop Is Nothing) Then MsgBox("Old rule was not found") Else prop.Value = replaceWith MsgBox("Changes were made") End If ' If you want to check all events uncomment the following lines 'For Each propTest As [Property] In oETPropSet ' logger.Info(String.Format("{0}({1}) = {2}", propTest.Name, propTest.PropId, propTest.Value)) 'Next
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Thank you for your response. I replaced rule names but get msg from rule
Old rule was not found
So question is do i need change anything else in rule. Old rule is in before save document.
Was the 'old rule' a local rule (saved within the same document) or an external rule? This is important, because external rules get extra text ("file://") added to the start of their names when they are added to the event triggers property. If it is an external rule, you may just need to add that extra text to the beginning of the rule's name, in order to find it within the properties.
Wesley Crihfield
(Not an Autodesk Employee)
Working perfect. Thank you guys
Hello,
may I ask if is possible to have the additional instruction for iterate this rule in all components opened below the assemly?
Many thanks
Hi @daniele_vantini4BD5L. That certainly sounds possible. We could likely just move the functionality of this routine into a custom Sub routine, below the Sub Main...End Sub block of code, then while iterating all the referenced documents of the main assembly within the Sub Main block of code, we could call that other Sub routine to run, and supply the referenced document to that Sub routine, along with the name of the iLogic rule to replace, and whether or not it is an external rule, so it knows which document to target, and what rule name to replace.
Wesley Crihfield
(Not an Autodesk Employee)
Sure. Below is a quick example iLogic rule laid out like that you can try. You will need to edit the values of the variables on Lines 3, 4, & 5 first though. I have not tested it yet, so be careful and maybe try it on a test assembly first. Let me know how it works for you.
Sub Main
Dim oDoc As Inventor.Document = ThisDoc.Document
Dim sOldRuleName As String = "MyOldiLogicRuleNameHere"
Dim sNewRuleName As String = "MyNewiLogicRuleNameHere"
Dim bIsExternalRule As Boolean = True
ReplaceRuleInEventTriggers(oDoc, sOldRuleName, sNewRuleName, bIsExternalRule)
Dim oRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
If oRefDocs.Count = 0 Then Return
For Each oRefDoc As Inventor.Document In oRefDocs
ReplaceRuleInEventTriggers(oRefDoc, sOldRuleName, sNewRuleName, bIsExternalRule)
Next 'oRefDoc
oDoc.Update2(True)
'oDoc.Save2(True)
End Sub
Const sInternalName As String = "{2C540830-0723-455E-A8E2-891722EB4C3E}"
Const sExternalRulePrefix As String = "file://"
Sub ReplaceRuleInEventTriggers(ByRef oDoc As Inventor.Document, ByVal sOldRuleName As String, _
ByVal sNewRuleName As String, ByVal bIsExternalRule As Boolean)
If oDoc Is Nothing OrElse (oDoc.IsModifiable = False) OrElse (sRuleName = "") Then Return
Dim oSet As PropertySet = Nothing
If oDoc.PropertySets.PropertySetExists(sInternalName, oSet) Then
If oSet.Count = 0 Then Return
If bIsExternalRule = True Then
sOldRuleName = sExternalRulePrefix & sOldRuleName
sNewRuleName = sExternalRulePrefix & sNewRuleName
End If
For Each oProp As Inventor.Property In oSet
If oProp.Value = sOldRuleName Then
oProp.Value = sNewRuleName
End If
Next 'oProp
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Edit: Updated custom Sub routine a bit after posting it to make it slightly more efficient.
Wesley Crihfield
(Not an Autodesk Employee)
mmmmh.... nothing is happening, errors either.
Both are external rules (new and old) and I have try to insert the name of the rules with and without
file://
Is that possible that the variable are declared two times in conflicting way?
@daniele_vantini4BD5L. The external rule prefix String should not be applied within the Sub Main area, because it is being added within the custom Sub routine, and only when you specify True for the bIsExternalRule input variable. When an 'input' variable is declared within the definition line of a method (Sub or Function) using 'ByRef', that means that input object can be changed by this method in a way that will still be present in the 'calling' routine, but if declared using 'ByVal', that object can not be changed in a way that effects the object within the 'calling' routine, and can only be used/modified internally. If you do not specify 'ByRef' or 'ByVal', then certain 'default' settings are used.
Also, another detail to keep in mind is that this will only effect the settings that were directly defined within the 'This Document' tab of the Event Triggers in that document. It will not change any settings that were defined within any of the other tabs within the Event Triggers dialog. The settings on those other tabs are stored within an external XML file. Only the settings on the 'This Document' tab are stored within that document, in that hidden PropertySet, and if there were never any settings set in that tab, in that document before, then the hidden PropertySet will not even exist yet.
Another complication would be if those external rules were not directly located within directories that are listed within the iLogic Configuration settings (not within sub folders of those directories listed). If the external rules are located within a sub folder of a directory listed within the iLogic Configuration settings, but that sub folder is not specifically in that main list in the iLogic Configuration settings, this will likely not be able to find those rules.
You may also need to save those documents before the changes will take effect, not sure. However, just out of curiosity, did you check to see if this effected some referenced documents, but not others? If so, did those referenced documents contain any internal iLogic rules, or internal iLogic forms? Sometimes, when there were no internal iLogic rules, and no internal iLogic forms in a document, then that document could be missing an important setting, which would basically indicate that it is currently influenced by the iLogic add-in (a DocumentInterest). Sometimes when that is missing, changes made to the Event Triggers by code might appear OK, but do not function correctly afterwards.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @daniele_vantini4BD5L. Was the 'old' rule an 'internal' iLogic rule (saved within that Inventor document), but then the 'new' rule is an 'external' iLogic rule? If that is the case, then I would need to make the code more dynamic by adding an additional input parameter, and adding additional functionality. The additional input would be for specifying the 'old' rule was external, as well as asking if the 'new' rule is external (one additional Boolean). That would give us more control, and make it work better in situations like that.
To help you (and others) understand what is going on better, I will post one of my own 'inspection / research' iLogic rules, similar to the one I used to get all the different PropID ranges required for the different types of events, which we must specify correctly when adding new rules into the Event Triggers dialog by code. That rule code is within the attached text file. When you run that, it will attempt to find this hidden PropertySet, if it exists, then record all available data about it, and all of its Properties, into a StringBuilder, then write those results to the iLogic Log window. So after you run it, check within the iLogic Log window for the results, which can be copied / pasted into a text file or similar, if needed. This will give you a better idea of what information is in there, and how it needs to be changed. It may also help me (and others) to be able to help you, by letting us see the results of that inspection, just to make sure what is going on in there. You could copy that text into a new Notepad text file, and attach it just like I did this external iLogic rule code, if you wanted to.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @daniele_vantini4BD5L. I did find a mistake in the code I posted in Message 10. On Line 21, I checked if sRuleName = "", but that variable did not exist anymore, because I had changed the names of the 'input' variables. So, it was always exiting the routine, before doing anything.
However, after my last response, and thinking about that limitation in functionality, I decided to develop that routine a bit further, as explained there. I will attach that revised version of the code within the attached text file, for convenience.
Wesley Crihfield
(Not an Autodesk Employee)