How to check if a file has been saved in Inventor 2022?

How to check if a file has been saved in Inventor 2022?

CattabianiI
Collaborator Collaborator
983 Views
4 Replies
Message 1 of 5

How to check if a file has been saved in Inventor 2022?

CattabianiI
Collaborator
Collaborator

This one is a well known code snippet to check if a file has been saved in Inventor 2021 and previous versions:

if Document.FileSaveCounter > 0 then


Since the document and file now are different elements that property could not be the one we were looking for.
Fortunately it's already there the proper one which is:

Document.File.FileSaveCounter


Why? What's now the Document.FileSaveCounter? How can be Document.FileSaveCounter = 0 and no save needed? 

...

This is the biggest Inventor update in many years as you, Autodesk, often says and it's having an even bigger impact on .NET API devs.
No more posts on the inventor API blogs, just the LODs migration document written one year ago, many things has changed in the updates without any mention in the release notes.

0 Likes
984 Views
4 Replies
Replies (4)
Message 2 of 5

pball
Mentor
Mentor

I do not see any difference in the behavior in 2022 though I'm on vanilla 2022 without any updates as I can't install them.

 

debug.Print thisapplication.activeeditdocument.FileSaveCounter
1 'after save
0 'before save

 

debug.Print thisapplication.ActiveEditDocument.File.FileSaveCounter
1 'after save
0 'before save

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 3 of 5

CattabianiI
Collaborator
Collaborator

You're totally right, there isn't any difference if you don't use model states nor substitutes.

 

In any other case there are differences!

0 Likes
Message 4 of 5

pball
Mentor
Mentor

That may have been a good point to note originally. I haven't actively started using 2022 yet so I haven't touched model states yet.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 5 of 5

JBerns
Advisor
Advisor

The AssemblyDocument.FileSaveCounter Property seems to be a good way to test if a file has ever been saved, but subsequent tests will just report how many times it has been saved.

This does not accurately report if an existing file has been modified and requires saving.

 

Would it be better to use the property, AssemblyDocument.Dirty, to check if the file requires saving?

 

Sub Main()
	
	Debugger.Break
	
    ' Ensure we're in an assembly document
    If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
        MessageBox.Show("Please run this rule from an assembly document.", "iLogic")
        Return
    End If

    ' Get the active assembly document
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument

	' Report counter and dirty status
	MessageBox.Show( _
		"FileSaveCounter = " & oAsmDoc.FileSaveCounter & vbCr & _
		"Dirty: " & oAsmDoc.Dirty & vbCr & _
		" ",
		"REPORT",
		MessageBoxButtons.OK,
		MessageBoxIcon.Information
		)
	
End Sub

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes