Why does this work within a part but not when its edited through a assembly

Why does this work within a part but not when its edited through a assembly

AMN3161
Advocate Advocate
451 Views
2 Replies
Message 1 of 3

Why does this work within a part but not when its edited through a assembly

AMN3161
Advocate
Advocate

So i am stumped here

 

If I open the part and run this external rule it does exactly what i need it to but if i run the external rule while editing a part through a assembly it doesn't work. If I am editing it through a assembly it will not detect the rule exist already and add another one but with a _1. I know it has something to do with the activedocument part but if i am editing a part within a assembly wouldn't the activedocument be the one i am editing? I don't know, any help would be appreciated 

 

Dim oRuleName As String = "Master_Parts_List"
Dim oTxtFileName As String = "C:\_VAULT_WORKSPACE\JOBS\FAB\Ilogic Rules\External Rules\Referenced Rules\Master Parts List Link (REF).txt"
Dim oRuleText As String = IO.File.ReadAllText(oTxtFileName)
Dim oDoc As Document = ThisApplication.ActiveEditDocument
Dim oRuleExists As Boolean = False
Dim iLogicAuto = iLogicVb.Automation
iLogicAuto.RulesEnabled = True
iLogicAuto.RulesOnEventsEnabled = True
Dim oRule As iLogicRule


Dim TargetRuleName As String = "Master_Parts_List"

Dim auto As IiLogicAutomation  = iLogicVb.Automation
Dim doc As Inventor.Document = ThisApplication.ActiveDocument

' Get the rules 
Dim ruleCol As System.Collections.IEnumerable = auto.Rules(doc)
Dim bRuleExists As Boolean = False	

' make sure the rules collection exists
If Not ruleCol Is Nothing Then
    ' string to hold the rule names
    Dim name As String = ""
    ' Go through each of the rules
    For Each rule As iLogicRule In ruleCol
        ' check the name of the rule
        If TargetRuleName.ToUpper = rule.Name.ToUpper Then
            bRuleExists = True
            Exit For
        End If
    Next
End If

If bRuleExists Then
	
	MessageBox.Show("The Master Parts List Rule exists in this file, i will replace it with the most current version", "Rule Exists")

	iLogicAuto.DeleteRule(oDoc, oRuleName)
	
	oRule = iLogicAuto.AddRule(oDoc, oRuleName, "")
	
	oRule.Text = oRuleText
	iLogicVb.DocumentUpdate
	oDoc.Save

Else 

oRule = iLogicAuto.AddRule(oDoc, oRuleName, "")
	
	oRule.Text = oRuleText
	iLogicVb.DocumentUpdate
	oDoc.Save

End If 

 

0 Likes
Accepted solutions (1)
452 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @AMN3161 

ActiveDocument will be the assembly if you edit a part within the assembly...

ActiveEditDocument on the other hand is the document you're editing.

Try changing this line:

Dim doc As Inventor.Document = ThisApplication.ActiveDocument

To this:

Dim doc As Inventor.Document = ThisApplication.ActiveEditDocument
0 Likes
Message 3 of 3

AMN3161
Advocate
Advocate

that fixed it, thank you for the help!

0 Likes