Close document event trigger fires when checking in related documentation.

Close document event trigger fires when checking in related documentation.

peterjoachim
Enthusiast Enthusiast
569 Views
2 Replies
Message 1 of 3

Close document event trigger fires when checking in related documentation.

peterjoachim
Enthusiast
Enthusiast

So I have a rule that is set to run with the close document event trigger. This will prompt a user asking if they want to export a DWF of an assembly, but only if that assembly follows a particular filename scheme.

 

If ThisApplication.ActiveDocumentType <> 12291 Then
	Return
End If

	oJobNum = Left(ThisApplication.ActiveDocument.DisplayName, 6)
	oAsmNum = Right(ThisApplication.ActiveDocument.FullFileName, 7)
	oFolder = "J:\" & oJobNum & "\MECH\REFERENCE"

	If oAsmNum = "A01.iam" Then
		oDWF = MessageBox.Show("Would you like to export DWF?", "Export DWF", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
		If oDWF = vbYes Then
			ThisDoc.Document.SaveAs( oFolder & "\" & ThisDoc.FileName(False) & (".dwf") , True) 
		End If
	End If

 

 This rule works as intended BUT when I check in an assembly and chose to include all related files, the prompt comes up for every file during its search for related files. Any ideas on how to correct this?

DWF error.PNG 

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

Michael.Navara
Advisor
Advisor
Accepted solution

This is because the closing document is not the ActiveDocument.

 

Try this rule

Dim closedDocument As Document = ThisDoc.Document 
If closedDocument.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
    Return
End If

Dim oJobNum = Left(closedDocument.DisplayName, 6)
Dim oAsmNum = Right(closedDocument.FullFileName, 7)
Dim oFolder = "J:\" & oJobNum & "\MECH\REFERENCE"

If oAsmNum = "A01.iam" Then
    Dim oDWF = MessageBox.Show("Would you like to export DWF?", "Export DWF", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If oDWF = vbYes Then
        Dim fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(closedDocument.FullFileName)
        Dim dwfFileName as string = oFolder & "\" & fileNameWithoutExt & ".dwf"
        closedDocument.SaveAs(dwfFileName, True)
    End If
End If

 

0 Likes
Message 3 of 3

peterjoachim
Enthusiast
Enthusiast

Perfect.. Thanks!

0 Likes