Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
DRoam
2907 Views, 9 Replies

iLogic to set initial filename on first save

I'd like to create an iLogic code to do two things:

 

1. On the first save of a part, check if the Description is filled out, and give me the option to fill it out if I want

2. After that, allow the Save As dialog to come up, with the Filename populated with the current Description if it exists

 

Here's the code that I have right now, a lot of which I got from the forums:

 

 

If ThisDoc.Path="" Then
    'If document has not been saved before...
    
    If iProperties.Value("Project", "Description")="" Then
        'If the Description is empty...
        GiveDescription=MessageBox.Show("You have not given this part a Description (Component name). Would you like to do so now?", "Missing Description",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation)
        If GiveDescription=DialogResult.Yes Then
            'If the user wants to provide a Description...
            iProperties.Value("Project", "Description") = InputBox("Component Name:", "Part Description", "")
        End If
    End If
    
    'SAVE AS DIALOG BOX
    'define the active document
    oDoc = ThisDoc.Document
    'create a file dialog box
    Dim oFileDlg As inventor.FileDialog = Nothing
    InventorVb.Application.CreateFileDialog(oFileDlg)
    
    'Set dialog filter
    'oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
    
    'set the directory to open the dialog at
    'oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
    'set the file name string to use in the input box as the value entered in Excel Spreadsheet
    oFileDlg.FileName = iProperties.Value("Project", "Description")
    
    'work with an error created by the user backing out of the save
    oFileDlg.CancelError = True
    On Error Resume Next
    'specify the file dialog as a save dialog (rather than a open dialog)
    oFileDlg.ShowSave()
    
    'catch an empty string in the imput
    If Err.Number <> 0 Then
    MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
    ElseIf oFileDlg.FileName <> "" Then
    'save the file
    oDoc.SaveAs(iProperties.Value("Project", "Description"), False) 'True = Save As Copy & False = Save As
    End If
Else
    'If document has been saved before...
    Return
End If

 

 

Here are the two main issues with it:

 

1. If I put it under the "Before Save Document" trigger, Inventor runs it AFTER displaying the Save As dialog box, so that makes it useless.

2. If I just run the rule manually before ever saving the document, it appears that everything works as intended, but after hitting "Save", nothing happens. The part isn't actually saved.

 

So, does anyone know how I can get my code to:

 

1. Intercept the Save As dialog and run BEFORE it comes up

2. Actually save the file once it's done

 

Thanks!