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?