Vb.Net - DialogEvents_OnFileSaveAsDialog - Get Active Document

Vb.Net - DialogEvents_OnFileSaveAsDialog - Get Active Document

isocam
Collaborator Collaborator
182 Views
2 Replies
Message 1 of 3

Vb.Net - DialogEvents_OnFileSaveAsDialog - Get Active Document

isocam
Collaborator
Collaborator

Can anybody help?

 

I am writing a Vb.Net "AddIn" for Autodesk Inventor.

 

I am using the DialogEvents_OnFileSaveAsDialog event.

 

Does anybody know how to get the active document oDoc?

 

For example, use oDoc so I can get the full file name. 

 

FileName = oDoc.FullFileName

 

The code I am currently using is:

 

Private Sub DialogEvents_OnFileSaveAsDialog(ByRef FileTypes() As String, SaveCopyAs As Boolean, ParentHWND As Integer, ByRef FileName As String, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles DialogEvents.OnFileSaveAsDialog
HandlingCode = HandlingCodeEnum.kEventHandled

MsgBox("SAVING NEW FILE")

End Sub

 

Many thanks in advance!

 

Darren

0 Likes
183 Views
2 Replies
Replies (2)
Message 2 of 3

marcin_otręba
Advisor
Advisor

you can get topleveldocument from context:

 

marcin_otrba_0-1745395154724.png

 

using :

dim docname as string=""

For i = 0 To Context.Count
 If Context.Name(i) = "TopLevelDocument" Then

 docname= Context.Value(i)
 End If
Next

 

 

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

I believe you get the actual Document object from that 'context' entry, when it is provided, not just the name of the document.  Below is a short example code showing how that event handler can be used from an iLogic rule.  It just gathers information about the event, then writes that to the iLogic Log window, on the 'Trace' level.  For this to work, you must have your iLogic Log level set to Trace level, but not need the 'Detailed Trace' setting turned on.  I made this example a 'one shot' routine, so that it will only react to the event one time, then remove itself, for safety.

But if you truly want to get the application's 'active' document (not just the Document involved with this event), then get its FullFileName, then you would need to have access to the Inventor.Application object...presumably through a variable that was declared at a higher level within your overall code structure.

When this event fires, if the document being saved has not been saved before (initial save), then it might not report its 'FileName'.  Similarly, if you get the Document object from the Contextual 'TopLevelDocument' entry, and it had not been saved before, its FullFileName will be empty.

Sub Main
	If oFileUIEvents Is Nothing Then oFileUIEvents = ThisApplication.FileUIEvents
	'use next line to start event handling, if you want to be ablt to remove it later
	AddHandler oFileUIEvents.OnFileSaveAsDialog, AddressOf FileUIEvents_OnFileSaveAsDialog
End Sub

'use WithEvents & Handles if you do not need to 'remove' the event handler later
'Dim WithEvents oFileUIEvents As Inventor.FileUIEvents

Dim oFileUIEvents As Inventor.FileUIEvents

Sub FileUIEvents_OnFileSaveAsDialog(ByRef FileTypes() As String, _
	SaveCopyAs As Boolean, ParentHWND As Long, ByRef FileName As String, _
	Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) 'Handles oFileUIEvents.OnFileSaveAsDialog
	
	Dim oReport As New System.Text.StringBuilder()
	oReport.AppendLine("FileUIEvents.OnFileSaveAsDialog Event Fired")
	Dim sFileTypes As String = String.Concat(FileTypes)
	oReport.AppendLine("FileTypes = " & sFileTypes)
	oReport.AppendLine("SaveCopyAs = " & SaveCopyAs.ToString)
	oReport.AppendLine("ParentHWND = " & ParentHWND.ToString)
	oReport.AppendLine("FileName = " & FileName)
	'check 'Top Level Document'
	Dim bTopLevelDocEntryFound As Boolean = False
	Dim oTopLevelDoc As Inventor.Document = Nothing
	If Context IsNot Nothing AndAlso Context.Count > 0 Then
		For i As Integer = 1 To Context.Count
			Dim sName As String = Context.Name(i)
			If sName = "TopLevelDocument" Then
				bTopLevelDocEntryFound = True
				oTopLevelDoc = Context.Value(sName)
			End If
		Next
	End If
	Dim sTopLevelDocFFN As String
	If bTopLevelDocEntryFound Then
		oReport.AppendLine("Context:  'TopLevelDocument' entry was present")
		If oTopLevelDoc Is Nothing Then
			oReport.AppendLine("Context:  'TopLevelDocument' = Nothing (no value)")
		Else
			oReport.AppendLine("Context:  'TopLevelDocument' TypeName = " & TypeName(oTopLevelDoc))
			sTopLevelDocFFN = oTopLevelDoc.FullFileName
			If sTopLevelDocFFN = "" Then
				oReport.AppendLine("Context:  'TopLevelDocument' FullFileName = 'empty'(unsaved)")
			Else
				oReport.AppendLine("Context:  'TopLevelDocument' FullFileName = " & sTopLevelDocFFN)
			End If
		End If
	Else
		oReport.AppendLine("Context:  'TopLevelDocument' entry was not present")
	End If
	oReport.AppendLine("HandlingCode = " & HandlingCode.ToString)
	Logger.Trace(vbCrLf & oReport.ToString)
	'if using 'AddHandler', then uncomment next line to make this a 'one shot' routine
	'a one shot routine is one that only reacts to an event one time
	RemoveHandler oFileUIEvents.OnFileSaveAsDialog, AddressOf FileUIEvents_OnFileSaveAsDialog
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes