OK. Since the original template document had the "ShowForm" rule and event trigger set-up within it, the new document created by the SaveAs method will also have that rule and event trigger set-up within it. So the new document you create with the SaveAs method will need to be opened, either visibly or invisibly, so that we can get rid of the event trigger setting within it. Otherwise everything we do will be effecting the original template. And when we open that new document, we need to capture it to a variable, so that we can work with it after we open it. By capturing the new document to a variable, then using that variable, we make sure we are not effecting the original template document.
Since i don't know if the other rule that is set to an event trigger is set to be triggered by the same event, I created a custom Sub routine that we can use multiple times, and it will remove the specified rule from 'every' event it might be listed under, not just from under one specific event, to make it simpler. Also, if your rule named "Remove iTriggers" is an external rule, then we will have to use a slightly different method to run it (iLogicVb.Automation.RunExternalRule(oDoc, "Remove iTriggers")). By the way...is the rule doing the SaveAs task also a local rule within that template file, or is it an external rule?
Here is a slightly modified version of the one code you posted, where I am using the other RunRule methods near the end.
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path
' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
MsgBox("This file has not yet been saved and doesn't exist on disk! - please save it first",64, "Lord iLogic")
Return
End If
If System.IO.Directory.Exists(ExportPath) = False Then
MsgBox("The directory does not exist.", , "")
Return
End If
' Define folder browse dialog
Dim Dialog = New System.Windows.Forms.FolderBrowserDialog
' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."
' Show dialog box
If Dialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then
' User clicked 'ok' on dialog box - capture the export path
ExportPath = Dialog.SelectedPath & "\"
Else
' User clicked 'cancel' on dialog box - exit
Return
End If
oFileName = iProperties.Value("Project", "Part Number")
' Define the filename of the file to be exported - in this case it is a iam file extension
ExportFilename = oFileName & ".iam"
Dim oNewFullFileName As String = ExportPath & ExportFilename
'Do export operation (Using save As)
Try
ThisDoc.Document.SaveAs(oNewFullFileName, True)
Catch
MsgBox("File export failed...", vbInformation, "Lord iLogic")
End Try
Dim oDoc As Document = Nothing
' Ask user if they want to open (launch) the file we just exported...
If MsgBox("File exported: " & ExportFilename & vbLf & vbLf & _
"Do you want to 'Visibly' open the Assembly Now?", vbYesNo + vbQuestion, "Lord iLogic - File Exported") = vbYes Then
'Create a NameValue Map
Dim oNVMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
'Add option to NameValueMap
oNVMap.Value("DesignViewRepresentation") = "Default"
oDoc = ThisApplication.Documents.OpenWithOptions(oNewFullFileName, oNVMap, True)
'if the rule named "Remove iTriggers" is a local rule within the new assembly then
iLogicVb.Automation.RunRule(oDoc, "Remove iTriggers")
'But if that rule is an external rule, then use the following line:
'iLogicVb.Automation.RunExternalRule(oDoc, "Remove iTriggers")
Return
End If
If IsNothing(oDoc) Then
oDoc = ThisApplication.Documents.Open(oNewFullFileName, False)
iLogicVb.Automation.RunRule(oDoc, "Remove iTriggers")
'iLogicVb.Automation.RunExternalRule(oDoc, "Remove iTriggers")
oDoc.Save
oDoc.Close
End If
And if you want to totally skip the whole other rule named "Remove iTriggers", and just put that code into your SaveAs rule, you can use that custom Sub routine I mentioned above, which I will post below:
Sub RemoveRuleFromAllEventTriggers(oDoc As Document, oRuleName As String)
Dim oSet As PropertySet = Nothing
Dim oInternalName As String = "{2C540830-0723-455E-A8E2-891722EB4C3E}"
If oDoc.PropertySets.PropertySetExists(oInternalName, oSet) Then
If oSet.Count = 0 Then Exit Sub
For Each oProp As Inventor.Property In oSet
'an external rule's name will start with "file://"
If oProp.Value = oRuleName Or _
oProp.Value = "file://" & oRuleName Then
oProp.Delete
End If
Next
If oSet.Dirty Then oDoc.Save
End If
End Sub
Then if you choose to use this custom Sub routine, instead of running the "Remove iTriggers" rule, you can call that sub to run similar to this: (just supply the input document reference we captured, and the name of the rule you want removed from the event triggers of that document.)
Sub Main
Dim oDoc As Document = ThisDoc.Document
RemoveRuleFromAllEventTriggers(oDoc, "ShowForm")
End Sub
Wesley Crihfield

(Not an Autodesk Employee)