How to change the suggested filename when saving a idw?

How to change the suggested filename when saving a idw?

jzietsman
Explorer Explorer
807 Views
11 Replies
Message 1 of 12

How to change the suggested filename when saving a idw?

jzietsman
Explorer
Explorer

We have a document system that requires that the filename follows a standard. In short, its partnumber-suffex as it's now when we create the drawing from a template, and we hit save, the suggested filename is partnumber.idw 

As the suffix is already defined in the template, I want to change the suggested file name to part number-suffix.idw 

But when I try to update the filename before saving, I get an error.

ThisDoc.FileName = newFileName (Property FileName is ReadOnly) 

is there no workaround to change the suggested filename with the save dialogue box? 

0 Likes
808 Views
11 Replies
Replies (11)
Message 2 of 12

Frederick_Law
Mentor
Mentor
Message 3 of 12

WCrihfield
Mentor
Mentor

Hi @jzietsman.  I was also looking into this request, for a way to automate that 'suggestion' to be the way you want it.  It would likely require a bit of trial & error testing to get it just right.  And yes, the ThisDoc.FileName property is ReadOnly, so that is not where we would be putting the temporary file name value before the save.   I believe you may need to use utilize a real event handler directly for this, which will give you more control.

 

  I was using the actual DocumentEvents.OnSave event handler to monitor for when I saved a new DrawingDocument for the first time, checking during its 'kBefore' timing state, and this event is triggered after the manual dialog has already been shown to the user, so that would not work exactly the way you were wanting.  We would have to be able to monitor for when that dialog gets shown, and react during its 'Before' timing state.  I know we have the FileDialogEvents.OnOptions event handler we could use, but that will only be triggered by clicking on the Options button within that dialog, not by the main dialog showing.  So the next target would be the FileUIEvents.OnFileSaveAsDialog Event.  It even says this will be triggered by using the regular Save command on a document that has not been saved yet, because then it acts like SaveAs.  You may be able to use this one to override the suggested file name.  

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 12

TONELLAL
Collaborator
Collaborator

I don't know if you can use it in your case, but to remane default FG files I use fileUIEvts_OnPopulateFileMetadata, then test Context and fill Metadata.

0 Likes
Message 5 of 12

jzietsman
Explorer
Explorer

Thanks. So, can the code that listens to the event be in the template? I have not used event handlers in Inventor and was hoping to use logic to run a script before saving, but it seems that it does not trigger the first time one saves. ironicly. 

0 Likes
Message 6 of 12

WCrihfield
Mentor
Mentor

Hi @jzietsman.  Unfortunately, it is not going to be that simple.  What you are trying to achieve, event though it may seem simple, would actually require some fairly advanced code to make happen.  The type of code that would normally be put into an Inventor add-in, rather than an iLogic rule.  Working with real event handler codes can be rather complicated, and can cause problems, if not handled correctly and efficiently.  If we were able to make this happen using iLogic rules (multiple may be required), then at least one of those rules would need to be an external rule, because we are dealing with Inventor application level functionality here.  And one rule may simply be to launch that other external rule's process, when the first new drawing document is created.  The FileUIEvents object itself is obtained directly from the Inventor Application object, not from a Document.  And the FileUIEvents.OnFileSaveAsDialog and FileUIEvents.OnPopulateFileMetadata events can be triggered with any document(s) involved.

 

I am not that familiar with the OnPopulateFileMetadata event yet myself, but after reviewing the OnFileSaveAsDialog Event properties and functionality, I'm starting to wander which may be better to use for this situation.  It seems like both events get triggered when I click on the regular Save button to save a 'New' drawing that has not been saved yet.  It is difficult to tell which event is really first (before the other), but at the moment it seems like the OnFileSaveAsDialog event may get triggered very slightly before the OnPopulateFileMetadata event does (I could be wrong though).  When the OnFileSaveAsDialog event is triggered, the 'FileName' property of the event is empty, but the value of its 'TopLevelDocument' (in the Context) contains the 'DisplayName' of the document (without any file extension yet), and the 'InitialDirectory' (in the Context) contains a file path that seemed to not have anything to do with that document (somewhere that we may have saved some other file previously).  When the OnPopulateFileMetadata event is triggered, within the 'FileMetadataObjects' is a FileMetadata object with the DisplayName (but this time with the default file extension included for that type of Document), but no file path, and no formulae, and in the 'Context' is a property named 'CommandName' with the value 'AppFileSaveAsCmd'.

 

Interesting stuff.  But if I were to figure this out, I would need to do more research, and trial & error testing (when I find the time, while keeping up with other work/tasks).  Maybe @TONELLAL could offer more insight about that one event, since he has used it before, but I am not sure.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 12

Frederick_Law
Mentor
Mentor

PS: I see now you want to change the filename in dialog box when user Save the file.

 

The dialog "suggest" name is same as the one shown on browser node:

FileSave-01.jpg

Change the node name before Saving the file.

 

Technically you only need this on first save.

 

iLogic "Before Save" trigger after the save dialog box.

 

Maybe able to catch it with Addin:

FileSave-02.jpg

0 Likes
Message 8 of 12

TONELLAL
Collaborator
Collaborator
Effectively it is quite complex.
I use this to automatically rename the default filenames when inserting a FG part.
The event detect a dialog box asking for file names is open, then test the "Context". In my case, if the Context is Frame Generator, I modify corresponding Metadatas.
This is managed in a class module in VBA, so I don't think it is possible (or very difficult) to adapt this to iLogic.
0 Likes
Message 9 of 12

Frederick_Law
Mentor
Mentor

This totally went in different direction.

Don't know your exact work flow.

Assuming user open "New" file and change Part Number.

So I try to catch the iProperties change event and change "Display name".

May need to save the event in Template file.

 

Be very careful.  This rule will run on ALL files.

FileSave-03.jpg

Sub Main()
Dim oDoc As Document
Dim oPropsets As PropertySets

Logger.Info("File Save")
oDoc = ThisApplication.ActiveDocument
If oDoc.FileSaveCounter = 0 Then
	Logger.Info("FullDocumentName: " & oDoc.FullDocumentName)
	Logger.Info("DisplayName: " & oDoc.DisplayName)
	Logger.Info("FullFileName: " & oDoc.FullFileName)
	Logger.Info("FileSaveCounter: " & oDoc.FileSaveCounter.ToString)
	oPropsets = oDoc.PropertySets
	'oPropsets.Item
	oDoc.DisplayName = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value.ToString + "-Testing"
End If
'oDoc.FullFileName = "Testing"
End Sub
0 Likes
Message 10 of 12

jjstr8
Collaborator
Collaborator

@jzietsman :  I don't know if this will work for you, but if you change .DisplayName, the initial save will use that instead of the default.

 

...and I just saw @Frederick_Law 's post about the node name, doh!

Message 11 of 12

Frederick_Law
Mentor
Mentor

Need to change it before the user hit Save and dialog popup.

Can't do anything while the dialog is showing.

0 Likes
Message 12 of 12

jjstr8
Collaborator
Collaborator

Definitely.  It sounded like @jzietsman was already trying to make the change before the save, just had the wrong property.

0 Likes