@JhoelForshav I'm taking this opportunity to learn. You gave me before the solution of pdffill, from that code I took the same concept and made it work somehow. Need your comment how to improve.
Thank you, I learned many things from you and the rest of the top solution authors here.
Sub Main ()
Dim oFileDlg As Inventor.FileDialog = Nothing
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Autodesk Inventor Drawings (*.idw)|*.idw"
oFileDlg.DialogTitle = "Select Drawings To With The Rule To Copy"
oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oFileDlg.MultiSelectEnabled =True
oFileDlg.FilterIndex = 1
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
Dim oDrgDoc As DrawingDocument
If Err.Number <> 0 Then
MsgBox("File not chosen.",,"Dialog Cancellation")
ElseIf oFileDlg.FileName <> "" Then
For Each oFileName As String In oFileDlg.FileName.Split("|")
Dim copyFrom As Document = ThisApplication.Documents.Open("C:\Users\Joseph\Desktop\Inventor Study\AL WASL\Workspaces\Workspace\Test\Copy\CopyFrom.idw", False) 'Document to copy from
Dim copyTo As Document = ThisApplication.Documents.Open(oFileName, False) 'Document to copy to
'Copy the rules
CopyRules(copyFrom, copyTo)
'Copy the Event triggers
CopyEventsPropSet(copyFrom, copyTo)
'Close the original document
copyFrom.Close
'Save the document to which rules and triggers has been copied
copyTo.Save
'Close document
copyTo.Close
Next
End If
End Sub
Sub CopyRules(CopyFrom As Document, CopyTo As Document)
For Each oRule As iLogicRule In iLogicVb.Automation.Rules(CopyFrom)
Dim oCopy As iLogicRule = iLogicVb.Automation.AddRule(CopyTo, oRule.Name, "")
oCopy.Text = oRule.Text
Next
End Sub
Sub CopyEventsPropSet(CopyFrom As Document, CopyTo As Document)
Dim oPropSet As Inventor.PropertySet = CopyFrom.PropertySets("{2C540830-0723-455E-A8E2-891722EB4C3E}")
Try
CopyTo.PropertySets("{2C540830-0723-455E-A8E2-891722EB4C3E}").Delete()
Catch
End Try
Dim newPropSet As Inventor.PropertySet = CopyTo.PropertySets.Add("_iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
For Each prop As Inventor.Property In oPropSet
newPropSet.Add(prop.Value, prop.Name, prop.PropId)
Next
End Sub