Overriding the Inventor native "File SaveAs" dialog box

Overriding the Inventor native "File SaveAs" dialog box

fakeru
Advocate Advocate
623 Views
2 Replies
Message 1 of 3

Overriding the Inventor native "File SaveAs" dialog box

fakeru
Advocate
Advocate

Hello everybody,

I'm trying to customize the SaveAs dialog box for some specific drawing, so that the proposed name for the drawing is the same as the Part Number property of the model file that it's in the drawing. By default, Inventor gives you the same name as the model file name. 

I used some reference info from this page:

http://adndevblog.typepad.com/manufacturing/2012/12/overriding-the-inventor-native-file-open-and-fil...

 

The problem is that I have 2 SaveAs dialog boxes. First one is the customized one, the other one the default one of Inventor. 

How do I make that the second doesn't not appear? 

Autodesk Inventor 2015 Certified Professional
0 Likes
624 Views
2 Replies
Replies (2)
Message 2 of 3

bshbsh
Collaborator
Collaborator

I always wanted to do something like this but somehow never gotten to it, so this made me experiment a bit with it, and I came up with this primitive code:

Public Sub ThisIsyourMainMacro()
    .....
    Set oFileEvents = New cFileEvents
    .....
End Sub
'This goes into a Class Module called "cFileEvents"
Private WithEvents oFileUIEvents As FileUIEvents
Private Suppressed As Boolean

Private Sub Class_Initialize()
Set oFileUIEvents = ThisApplication.FileUIEvents
Suppressed = False
End Sub

Private Sub Class_Terminate()
Set oFileUIEvents = Nothing
End Sub

Private Sub oFileUIEvents_OnFileSaveAsDialog(FileTypes() As String, ByVal SaveCopyAs As Boolean, ByVal ParentHWND As Long, FileName As String, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
If (SaveCopyAs = False) And (Suppressed = False) And (Context.Count = 2) Then
If (Context.Item(2).DocumentType = kDrawingDocumentObject) Then
Suppressed = True
Dim oFileDialog As FileDialog
Call ThisApplication.CreateFileDialog(oFileDialog)
With oFileDialog
.FileName = Context.Item(2).ReferencedDocuments.Item(1).PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
.InitialDirectory = Context.Item(1)
.Filter = Join(FileTypes(), "|")
.ShowSave
End With
If oFileDialog.FileName <> "" Then
Call ThisApplication.ActiveDocument.SaveAs(oFileDialog.FileName, False)
HandlingCode = kEventHandled
End If
Set oFileDialog = Nothing
Suppressed = False
End If
End If
End Sub

I guess there's a better way to suppress filedialog events, but I don't know it, so I used a boolean for that. The rest is just some checking.

0 Likes
Message 3 of 3

fakeru
Advocate
Advocate

So I don't manage to customize the native SaveAs dialogbox... This is what I really need.

 

  Public Sub FileUIEvents_OnFileSaveAsDialog_Handler(ByRef FileTypes() As String, ByVal SaveCopyAs As Boolean, ByVal ParentHWND As Int32, ByRef FileName As String, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
            

            Dim oDoc As Document = m_inventorApplication.ActiveDocument
            If m_inventorApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
                Dim oActiveSheet As Sheet = oDoc.ActiveSheet
                Dim oView As DrawingView = oActiveSheet.DrawingViews.Item(1)
                Dim oRefDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
                Dim PartNumber As String = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value.ToString
              
                Dim m_FileOpenForm As Inventor.FileDialog = Nothing
                m_inventorApplication.CreateFileDialog(m_FileOpenForm)
                With m_FileOpenForm
                    .Title = "File Save Custom"
                    .Filter = "Drawing File (*.idw)|*.idw"
                    .FileName = PartNumber
                    .ShowSave()
                End With
        
                HandlingCode = HandlingCodeEnum.kEventCanceled
           
                m_FileOpenForm = Nothing
            End If
        End Sub

Inventor will display its default saveas dialogbox. Everything I want is to have the partnumber as the name for the new drawing.

 

If I create a Windows Dialogbox, it works.

Dim m_FileOpenForm As System.Windows.Forms.SaveFileDialog  = New System.Windows.Forms.SaveFileDialog

 

But I prefer to customize the Inventor dialogbox.

 

Any ideas why it's not working? 

Autodesk Inventor 2015 Certified Professional
0 Likes