Adding external rule to event trigger

Adding external rule to event trigger

Charlies_3D_T
Advocate Advocate
3,734 Views
35 Replies
Message 1 of 36

Adding external rule to event trigger

Charlies_3D_T
Advocate
Advocate

Hello,

 

Does someone know how to declare an external rule to be added to event triggers?

 

Below is a piece of the ilogic for a local ilogic rule.

 

EventPropSet.Add("RULE TO Trigger", "PartBodyChanged ", 1200)

 

This doesn't work with external rules... 

 

Sub Events
On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
	EventPropSet.Add("RULE TO Trigger", "PartBodyChanged ", 1200)

'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()

 

Thank you!

 

0 Likes
Accepted solutions (1)
3,735 Views
35 Replies
Replies (35)
Message 21 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck

 

Will try it tomorrow morning and let you know! Thank you for the help so far! 

0 Likes
Message 22 of 36

Darkforce_the_ilogic_guy
Advisor
Advisor

why not just add in to before save event  for drawing ? no code should be needed for it ?

0 Likes
Message 23 of 36

Charlies_3D_T
Advocate
Advocate

Hello,

 

Now i have this: 

 

Sub Events
On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
		
	' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
	Dim tempRule = iLogicVb.Automation.AddRule(ThisDoc.Document, "TemporaryRule_392856A2", "")
	EventPropSet.Add("file://Drawing\Drawing - Auto_AUTOCAD_DWG", "BeforeDocSave0", 700)
	iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name)
	

'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

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()


End Sub

Still no succes... 😞

0 Likes
Message 24 of 36

MjDeck
Autodesk
Autodesk

A few questions:
Is there any error message when you run the rule?
Does anything show up in the Event Triggers dialog?

As a test, please create a new drawing and try it there.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 25 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

hello,

 

I run this rule: 

Sub Main()
	
Events

End Sub 


Sub Events
On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
		
	' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
	Dim tempRule = iLogicVb.Automation.AddRule(ThisDoc.Document, "TemporaryRule_392856A2", "")
	EventPropSet.Add("Drawing - Auto_AUTOCAD_DWG.txt", "BeforeDocSave", 700)
	iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name)
	

'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

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()


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

 

And nothing happens and no error just nothing. In an old or new drawing. And nothing shows up in the event triggers... 

 

Thank you for your help!

 

 

0 Likes
Message 26 of 36

MjDeck
Autodesk
Autodesk

As I mentioned above, you have to use "file://" to tell iLogic that it's an external rule.

EventPropSet.Add("file://Drawing - Auto_AUTOCAD_DWG.txt", "BeforeDocSave", 700)

Could you create a drawing from your standard template and post it here? It can just be an empty drawing. I want to see if it already contains any event triggers.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 27 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

The problem was indeed that there were other ilogic in the event triggers. I replaced ther 700 with 750 and now it's placed at the botom so great!

 

Thanks again for your help!

0 Likes
Message 28 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

I think i need your experience again.

 

I have a file and i have a rule in, the Before Save Document trigger.

 

I want to add 2 external rules. But it only adds one. Ony idea whats wrong? 

 

EventPropSet.Add("file://FlatPattern", "PartBodyChanged", 1250)
	EventPropSet.Add("file://BendRadius", "BeforeDocSave", 701)
	EventPropSet.Add("file://Sheet_Metal_Unfol_Rule_Trumpf", "BeforeDocSave", 702)
	iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name)
0 Likes
Message 29 of 36

MjDeck
Autodesk
Autodesk

@Charlies_3D_T , you can't use the same name for both properties. Try this:

EventPropSet.Add("file://BendRadius", "BeforeDocSave1", 701)
EventPropSet.Add("file://Sheet_Metal_Unfol_Rule_Trumpf", "BeforeDocSave2", 702)

Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 30 of 36

Charlies_3D_T
Advocate
Advocate

Hello @MjDeck 

 

I have 2 rules that need to place the external rule in the event triggers. But that does not work. Can you help me out? 

 

I have for rule 1 this:

 

On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
		
	' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
	Dim tempRule = iLogicVb.Automation.AddRule(ThisDoc.Document, "TemporaryRule_392856A2", "")
	EventPropSet.Add("file://Drawing - AutoDWG", "BeforeDocSave1", 750)
	iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name)

 

I have for rule 2 this:

On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
		
	' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
	Dim tempRule = iLogicVb.Automation.AddRule(ThisDoc.Document, "TemporaryRule_392856A3", "")
	EventPropSet.Add("file://Drawing - AutoDXF", "BeforeDocSave2", 790)
	iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name)

 

0 Likes
Message 31 of 36

MjDeck
Autodesk
Autodesk

@Charlies_3D_T , I tested your rules on my system (Inventor 2021) and they both work OK. Do you see an error message? There might be an error, but the line:

On Error Resume Next

prevents it from showing a dialog. Please try commenting out the line.
Can you send me a very simple drawing (maybe empty) in which these rules fail?

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 32 of 36

Charlies_3D_T
Advocate
Advocate

Hello @MjDeck 

 

I run this in following rule:

 

Sub Main()  
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument
	
	Dim IPJ As String
    Dim IPJ_Name As String
    Dim IPJ_Path As String
    Dim FNamePos As Long
    'set a reference to the FileLocations object.
    IPJ = ThisApplication.FileLocations.FileLocationsFile
    'get the location of the last backslash seperator
    FNamePos = InStrRev(IPJ, "\", -1)    
    'get the project file name with the file extension
    IPJ_Name = Right(IPJ, Len(IPJ) - FNamePos)
    'get the project name (without extension)
    IPJ_ShortName = Left(IPJ_Name, Len(IPJ_Name) - 4)
    'get the path of the folder containing the project file
    IPJ_Folder_Location = Left(IPJ, Len(IPJ) - Len(IPJ_Name))
	
	Dim newPath As String = IPJ_Folder_Location
	
	'oDisplayName = oAsmDoc.DisplayName & ".dwg"

	Dim oDrwPath As String 
	oDrwPath = newPath + "5. DWG & IDW\"
	
    ' Get all of the referenced documents. 
    Dim oRefDocs As DocumentsEnumerator 
    oRefDocs = oAsmDoc.AllReferencedDocuments 

    ' Iterate through the list of documents. 
    Dim oRefDoc As Document 
    For Each oRefDoc In oRefDocs 
		
    'Dim oDrwName As String = oRefDoc.ReferencedDocumentDescriptor.ReferencedDocument.Displayname
    oDisplayName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4) & ".dwg"
	
	Dim fList = System.IO.Directory.GetFileSystemEntries(oDrwPath, "*.dwg",System.IO.SearchOption.AllDirectories).Where(Function(X) X.Contains(oDisplayName))	
	
	If fList(0) <> String.Empty Then

		Dim oDrwDoc As DrawingDocument
		oDrwDoc = ThisApplication.Documents.Open(fList(0), True)
		
		' iLogicVb.RunExternalRule("file://Drawing\Drawing - AutoDWG")
        ' Events
		'iLogicVb.Automation.RunExternalRule(oDrwDoc, "Drawing - AutoDWG")
		Events
		
 		Call oDrwDoc.Close
	Else  	 
		'MessageBox.Show(oDisplayName +" - Drawing is unavailable ")
	End If 
Next
		
End Sub


Public Sub TraverseAssembly(Occurrences As ComponentOccurrences,Level As Integer) 
    ' Iterate through all of the occurrence in this collection.  This 
    ' represents the occurrences at the top level of an assembly. 
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In Occurrences 
        ' Print the name of the current occurrence. 
	oDrwName = oOcc.DisplayName & ".dwg" 

	Dim oDrwPath As String 
	oDrwPath = newPath + "5. DWG & IDW\"
	
	MessageBox.Show(oDrwName, "Title2")
	MessageBox.Show(oDrwPath, "Title2")
	
	Dim fList = System.IO.Directory.GetFileSystemEntries(oDrwPath, "*.dwg",System.IO.SearchOption.AllDirectories).Where(Function(X) X.Contains(oDrwName))	
	
	
	If fList(0) <> String.Empty Then
		   
		
		Dim oDrwDoc As DrawingDocument
		oDrwDoc = ThisApplication.Documents.Open(fList(0), True)
		
		' iLogicVb.RunExternalRule("file://Drawing\Drawing - AutoDWG")
        ' Events
		'iLogicVb.Automation.RunExternalRule(oDrwDoc, "Drawing - AutoDWG")
		Events
		
 		Call oDrwDoc.Close
	Else  	 
		MessageBox.Show(oDrwFile +" - Drawing is unavailable ")
	End If 
Next
		
        'Debug.Print Space(Level * 3) & oOcc.Name 

        ' Check to see if this occurrence represents a subassembly 
        ' and recursively call this function to traverse through it. 
        If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then 
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) 
        End If 
End Sub


'modelFullFileName = ThisDoc.ModelDocument.FullFileName 
'modelDirectoryName = IO.Path.GetDirectoryName(modelFullFileName) 
'modelFileName = IO.Path.GetFileName(modelFullFileName) 
'modelFileNamewithoutextentionsion = IO.Path.GetFileNameWithoutExtension(modelFullFileName) 
'MsgBox( modelFullFileName ) 
'MsgBox( modelDirectoryName ) 
'MsgBox( modelFileName ) 
'MsgBox( modelFileNamewithoutextentionsion )


Sub Events
'On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument)
		
	' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
	Dim tempRule = iLogicVb.Automation.AddRule(ThisDoc.Document, "TemporaryRule_392856A2", "")
	EventPropSet.Add("file://Drawing - AutoDWG", "BeforeDocSave1", 750)
	iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name)
	

'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

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()


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 run this in an assembly and normaly this works fine. But since inventor 2021 not any more.

I get this error

 

Error in rule: Activate_AutoDWG_In_Each_Drawing, in document: Test.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.PropertySet.Add(Object PropValue, Object Name, Object PropId)
at ThisRule.Events()
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Can you tell me what is wrong? 

0 Likes
Message 33 of 36

MjDeck
Autodesk
Autodesk
Accepted solution

@Charlies_3D_T , I found a few problems in your rule. A good way to resolve them is to pass the drawing document object to the Events function. Change this line:

Events()

to

Events(oDrwDoc)

Then edit the Events subroutine so it looks something like this:

Sub Events(doc As Document)
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(doc)

	Dim existingProp As Inventor.Property = Nothing
	Try
		existingProp = EventPropSet.Item("BeforeDocSave1")
	Catch
	End Try
		
	If existingProp Is Nothing Then
		' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
		Dim tempRule = iLogicVb.Automation.AddRule(doc, "TemporaryRule_392856A2", "")
		EventPropSet.Add("file://Drawing - AutoDWG", "BeforeDocSave1", 750)
		iLogicVb.Automation.DeleteRule(doc, tempRule.Name)
	End If
End Sub

(Just to make for less code, I'm not showing the event number range comments here.)
Another problem is that you're opening each drawing, modifying it, and then closing it. You should add a call to Save before closing it.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 34 of 36

Charlies_3D_T
Advocate
Advocate

Hello @MjDeck 

 

I have the following rule: 

 

But even now the Autocad rule is not placed in the event triggers... 

 

Sub Main()  
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument
	
	Dim IPJ As String
    Dim IPJ_Name As String
    Dim IPJ_Path As String
    Dim FNamePos As Long
    'set a reference to the FileLocations object.
    IPJ = ThisApplication.FileLocations.FileLocationsFile
    'get the location of the last backslash seperator
    FNamePos = InStrRev(IPJ, "\", -1)    
    'get the project file name with the file extension
    IPJ_Name = Right(IPJ, Len(IPJ) - FNamePos)
    'get the project name (without extension)
    IPJ_ShortName = Left(IPJ_Name, Len(IPJ_Name) - 4)
    'get the path of the folder containing the project file
    IPJ_Folder_Location = Left(IPJ, Len(IPJ) - Len(IPJ_Name))
	
	Dim newPath As String = IPJ_Folder_Location
	
	'oDisplayName = oAsmDoc.DisplayName & ".dwg"

	Dim oDrwPath As String 
	oDrwPath = newPath + "5. DWG & IDW\"
	
    ' Get all of the referenced documents. 
    Dim oRefDocs As DocumentsEnumerator 
    oRefDocs = oAsmDoc.AllReferencedDocuments 

    ' Iterate through the list of documents. 
    Dim oRefDoc As Document 
    For Each oRefDoc In oRefDocs 
		
    'Dim oDrwName As String = oRefDoc.ReferencedDocumentDescriptor.ReferencedDocument.Displayname
    oDisplayName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4) & ".dwg"
	
	Dim fList = System.IO.Directory.GetFileSystemEntries(oDrwPath, "*.dwg",System.IO.SearchOption.AllDirectories).Where(Function(X) X.Contains(oDisplayName))	
	
	If fList(0) <> String.Empty Then

		Dim oDrwDoc As DrawingDocument
		oDrwDoc = ThisApplication.Documents.Open(fList(0), True)
		
		' iLogicVb.RunExternalRule("file://Drawing\Drawing - AutoDWG")
        ' Events
		'iLogicVb.Automation.RunExternalRule(oDrwDoc, "Drawing - AutoDWG")
		Events(oDrwDoc)
		Call oDrwDoc.Save
		
 		Call oDrwDoc.Close
	Else  	 
		'MessageBox.Show(oDisplayName +" - Drawing is unavailable ")
	End If 
Next
		
End Sub


Public Sub TraverseAssembly(Occurrences As ComponentOccurrences,Level As Integer) 
    ' Iterate through all of the occurrence in this collection.  This 
    ' represents the occurrences at the top level of an assembly. 
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In Occurrences 
        ' Print the name of the current occurrence. 
	oDrwName = oOcc.DisplayName & ".dwg" 

	Dim oDrwPath As String 
	oDrwPath = newPath + "5. DWG & IDW\"
	
	MessageBox.Show(oDrwName, "Title2")
	MessageBox.Show(oDrwPath, "Title2")
	
	Dim fList = System.IO.Directory.GetFileSystemEntries(oDrwPath, "*.dwg",System.IO.SearchOption.AllDirectories).Where(Function(X) X.Contains(oDrwName))	
	
	
	If fList(0) <> String.Empty Then
		   
		
		Dim oDrwDoc As DrawingDocument
		oDrwDoc = ThisApplication.Documents.Open(fList(0), True)
		
		' iLogicVb.RunExternalRule("file://Drawing\Drawing - AutoDWG")
        ' Events
		'iLogicVb.Automation.RunExternalRule(oDrwDoc, "Drawing - AutoDWG")
		Events(oDrwDoc)
		call oDrwDoc.Save
		
 		Call oDrwDoc.Close
	Else  	 
		MessageBox.Show(oDrwFile +" - Drawing is unavailable ")
	End If 
Next
		
        'Debug.Print Space(Level * 3) & oOcc.Name 

        ' Check to see if this occurrence represents a subassembly 
        ' and recursively call this function to traverse through it. 
        If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then 
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) 
        End If 
End Sub


'modelFullFileName = ThisDoc.ModelDocument.FullFileName 
'modelDirectoryName = IO.Path.GetDirectoryName(modelFullFileName) 
'modelFileName = IO.Path.GetFileName(modelFullFileName) 
'modelFileNamewithoutextentionsion = IO.Path.GetFileNameWithoutExtension(modelFullFileName) 
'MsgBox( modelFullFileName ) 
'MsgBox( modelDirectoryName ) 
'MsgBox( modelFileName ) 
'MsgBox( modelFileNamewithoutextentionsion )


Sub Events(doc As Document)
'On Error Resume Next
	Dim EventPropSet As Inventor.PropertySet
	EventPropSet = GetiLogicEventPropSet(doc)

	Dim existingProp As Inventor.Property = Nothing
	Try
		existingProp = EventPropSet.Item("BeforeDocSave1")
	Catch
	End Try
		
	If existingProp Is Nothing Then
		' To make sure that the document has an iLogic DocumentInterest, add a temporary rule
		Dim tempRule = iLogicVb.Automation.AddRule(doc, "TemporaryRule_392856A2", "")
		EventPropSet.Add("file://Drawing - AutoDWG", "BeforeDocSave1", 750)
		iLogicVb.Automation.DeleteRule(doc, tempRule.Name)
	End If
	

'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

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()


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
0 Likes
Message 35 of 36

MjDeck
Autodesk
Autodesk

@Charlies_3D_T , It works ok on my system, running Inventor 2021.2. Which version are you running? Do you see an error message? Can you post a sample part and drawing that fails?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 36 of 36

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

I found the problem! 

 

I have already 2 or 3 rules in the before save so the command 

BeforeDocSave1

 was not good i changed it to 

BeforeDocSave90

 and now it works!

0 Likes