'After Save Document' event happens on original document when 'Save As' is used

'After Save Document' event happens on original document when 'Save As' is used

checkcheck_master
Advocate Advocate
1,231 Views
5 Replies
Message 1 of 6

'After Save Document' event happens on original document when 'Save As' is used

checkcheck_master
Advocate
Advocate

I run an iLogic rule using event trigger 'After Save Document'.
In that rule various iProperties are checked based on the file location etc., nothing exciting but works fine.
Until I do Save As action on a part.
I expect that the rule will run 'After Save Document', so with the file name of the Save As action.
However, nothing could be further from the truth, the rule runs on the basis of the original file name but knows for example Part Number if we use the Save As name.
Am I missing something?
Can I change this differently.
Can iLogic detect that we are dealing with a Save As action in order to stop running through the rule?

1,232 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Could you post the related portion of your code, and the screenshot of the Event Triggers dialog with your rule in it?

Which tab of the Event Triggers is your rule in?...Or is it in multiple tabs?

When you are using the SaveAs method, are you specifying a value for the second input variable called "SaveCopyAs" (Boolean), or are you leaving it blank?  If you are specifying something, what are you specifying there?

Technically, if you are supplying a new file name, and specifying False for SaveCopyAs, you aren't really saving the original document on purpose, but it gets saved automatically anyways when you attempt to save it as new file, because the original gets closed, leaving the new file open.  Then it would seem that the new file isn't really being saved either, it is just being initially created...I think. 🤔  But when specifying a new file name, and specifying True for SaveCopyAs, the original file remains open, and it just generates the other file in the file system.

 

This is an interesting challenge.  If possible, you may have to use a more complicated method of triggering your rule, if you need something to happen with the new document, in 'after' a save happens.  I know of at least two pre-defined Events that you can create your own 'event handler' code for.  The 'ApplicationEvents.OnSaveDocument' event, and the 'DocumentEvents.OnSave' event.  I don't think I have any pre-existing examples of complete codes using either of them, which might show you how to extract the 'second' document/file though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

checkcheck_master
Advocate
Advocate

Thank you WCrihfield for your response and asking specific questions.
I'll explain things in more detail.

To be clear, the Save As mentioned is a manual action, not initiated from iLogic.
The rule 'After Save Document' is just to be able to use the current file data, 'After Save Document', such as PathName, Part Number etc.

See videos and image:
To make it clear, I've made two very simple rules that show the FullDocumentName and the Part Number in a message box. One rule is called 'Test Before Save Document' and the other 'Test After Save Document'.
In the video you can see me doing a 'Save As' on a simple part.
Notice that the Before Save Document rule shows info from the original file while nothing happens to that original as witness Windows File Explorer on the right side of my screen.
You will then see the Save As file appear in File Explorer, after which the After Save Document rule does its thing.
There you can see that we are looking again at the Path Name of the original file but at the new Part Number.
In other words, Path Name is lagging while Part Number is accurate, it will be clear that nothing can be done with the Path Name this way.
Is there any other way so that I can access the correct Path Name?

 

For the second video I added a Save command to the Test After Save Document Rule (in my normal rule this Save command is executed when the document became 'Dirty').
As a result, the Save As document is saved again and reference is made in the Assy to this Save As document.
More or less an accidental Save and Replace...

 

Help is greatly appreciated, thanks in advance.

 

0 Likes
Message 4 of 6

basslagter
Participant
Participant

Hi @checkcheck_master 

 

Have you found a solution for this in a meantime?

 

I did exactly the same with the messagebox's in before save and after save. My goal is to run a rule in a save as document and also run a rule in a new document when using save and replace. I want to caption the original partnumber and put that in the new document as a reference. That way we can find where files are built from and evolved. And this might also come in handy when making drawings and to take the last most similar/ comparable model.

 

Does someone have a solution for this?

 

0 Likes
Message 5 of 6

checkcheck_master
Advocate
Advocate

@basslagter

Hi Bas,

I have tried several ways to get to the data of a Save As file using the Event Trigger 'After Save Document'.
See this post, message 4 and 6 where Jelte de Jong explains how and what.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/why-doesn-t-this-work-ilogic-up-to-d...
Although it seems technically correct I have not been able to keep this stable, mind you I am a hobbyist who occasionally tries something with code.

 

Now, to get to the data of a newly saved file I use this under Event Trigger 'After Save Document':

 

 

Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	If oDoc.FileSaveCounter = 1 Then
		iLogicVb.RunExternalRule("InventorPLUS_Before_Save_Document")
		oDoc.Save
	End If	
End If

 

 

So I perform my trick 'Before Save Document' for a new file.
That way I can get to the Path Name etc. of the new file.

 

If I understand you correctly you want to be able to see the past of a file based on previous file names/part numbers.
What I can imagine is a custom property that is always supplemented with the current part number.
In that case you don't have to base something on a path that doesn't exist yet, but you can use the file name/part number that is already there.
In my opinion that could be a rule that you execute 'Before Save Document'.

0 Likes
Message 6 of 6

basslagter
Participant
Participant

Hi @checkcheck_master,

 

Thanks for the reply, I will look into that. 

 

I have something similar, the only thing is that we use vault, so it won't be able to put in the information in checked in parts and then the challenge is to get the information over to the new part. I am also a bit of a hobbyist, so I am trying different ways to get it working without interfering checked in parts/assemblies (such as saving the document while it's checked in).

0 Likes