Why doesn't this work? iLogic Up to Date file data after save as file

Why doesn't this work? iLogic Up to Date file data after save as file

checkcheck_master
Advocate Advocate
802 Views
7 Replies
Message 1 of 8

Why doesn't this work? iLogic Up to Date file data after save as file

checkcheck_master
Advocate
Advocate

This question is related to my earlier post, I'll try it this way because it drives me a bit crazy.
All I want is to Save As a file and have an Up to Date Path and Part Number through iLogic to be able to fill in some iProperties correctly.
See the code, which is handled as Event Trigger 'After Save Document'.
No matter what I try, the Path keeps pointing to the original file.
I've tried closing the file, putting a pause in the code, and then reopening the file as the most recent file, it all works, except the Path doesn't match.
However, when I manually run the Update rule, after that the correct Path is displayed.

Physically it really looks like the new document is loading, so why isn't the Path running with it?

Why doesn't that work in the rule?

 

Can anyone explain to me if/how an iLogic Event Trigger can be used to catch the Save As action?

MessageBox.Show("Document Name: " & ThisDoc.Document.FullDocumentName & vbNewLine & vbNewLine & _
                "Part Number: " & iProperties.Value("Project", "Part Number"), "Test_After_Save_Document")

Call ThisApplication.UserInterfaceManager.DoEvents	
	ThisDoc.Document.Close	
Call ThisApplication.UserInterfaceManager.DoEvents
	System.Threading.Thread.CurrentThread.Sleep(3000)
Call ThisApplication.UserInterfaceManager.DoEvents

' Open the most recent file
ThisApplication.CommandManager.ControlDefinitions("FWxRecentFileCmd1").Execute
Call ThisApplication.UserInterfaceManager.DoEvents	
	InventorVb.DocumentUpdate(False)
Call ThisApplication.UserInterfaceManager.DoEvents	
	InventorVb.DocumentUpdate()
Call ThisApplication.UserInterfaceManager.DoEvents	
	iLogicVb.UpdateWhenDone = True
Call ThisApplication.UserInterfaceManager.DoEvents

MessageBox.Show("Document Name: " & ThisDoc.Document.FullDocumentName & vbNewLine & vbNewLine & _
                "Part Number: " & iProperties.Value("Project", "Part Number"), "Test_After_Save_Document")

 

 

MessageBox.Show("Document Name: " & ThisDoc.Document.FullDocumentName & vbNewLine & vbNewLine & _
                "Part Number: " & iProperties.Value("Project", "Part Number"), "Test_After_Save_Document")

Call ThisApplication.UserInterfaceManager.DoEvents	
	ThisDoc.Document.Close	
Call ThisApplication.UserInterfaceManager.DoEvents
	System.Threading.Thread.CurrentThread.Sleep(3000)
Call ThisApplication.UserInterfaceManager.DoEvents

' Open the most recent file
ThisApplication.CommandManager.ControlDefinitions("FWxRecentFileCmd1").Execute
Call ThisApplication.UserInterfaceManager.DoEvents	
	InventorVb.DocumentUpdate(False)
Call ThisApplication.UserInterfaceManager.DoEvents	
	InventorVb.DocumentUpdate()
Call ThisApplication.UserInterfaceManager.DoEvents	
	iLogicVb.UpdateWhenDone = True
Call ThisApplication.UserInterfaceManager.DoEvents

MessageBox.Show("Document Name: " & ThisDoc.Document.FullDocumentName & vbNewLine & vbNewLine & _
                "Part Number: " & iProperties.Value("Project", "Part Number"), "Test_After_Save_Document")

 

0 Likes
803 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

Here is my attempt to explain the situation. ThisDoc.Document is the ilogic snippet referencing the document the rule is in, or run on first in the case of an external rule.  If you perform a save as action on the file that original file closes but it’s reference lives on in ThisDoc.Document.

Here is a link to its meaning.

You will need ThisApplication.ActiveEditDocument to detect the newly open document. Unfortunately you can’t use the handy ilogic snippets for the path because of that embedded reference so you now need to use the system IO method to get path information or string manipulation from the full file path of the newly active file. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

checkcheck_master
Advocate
Advocate

Thanks A.Acheson for your reaction and tips.


Unfortunately it doesn't lead to a solution for me yet.
When I look at 'ActiveEditDocument' I find that it applies when an assembly is the ActiveDocument and you want to claim the document that is currently being edited, that way I am also familiar with it.
That situation is not relevant to my alleged problem.
I have a part open and choose file\save as, then when this new file is saved I want to know the new Path and Part Number, that's all.
I'm trying to do that using an external rule that is run through event trigger 'After save document'.
What can be difficult about that you might say 🙂
So far I can't get this to work...

 

I also tried ThisApplication.ActiveDocument, same result.
Anyone have other suggestions?
Someone from Autodesk maybe?

0 Likes
Message 4 of 8

JelteDeJong
Mentor
Mentor

It might sound strange but you could try to run your rule on the event "after opening". This will work because the "Save as"-Command triggers that event after saving. That has the disadvantage that it will run on all open file actions...

 

You could get better results if you use the API events. Those are only very hard to use in an iLogic rule (Normally you would use those only in an addin.).  but if you want to this is an example:

Public Class ThisRule
	Private appEvents As ApplicationEvents
	
    Sub Main()
		appEvents = thisapplication.ApplicationEvents
		AddHandler appEvents.OnOpenDocument, AddressOf AppEvents_OnOpenDocument
    End Sub
	
	Private Sub AppEvents_OnOpenDocument(DocumentObject As _Document, 
										 FullDocumentName As String, 
										 BeforeOrAfter As EventTimingEnum, 
										 Context As NameValueMap, 
										 ByRef HandlingCode As HandlingCodeEnum)
		HandlingCode = HandlingCodeEnum.kEventNotHandled
		If (BeforeOrAfter = EventTimingEnum.kAfter) Then 
			Try
				MessageBox.Show("Document Name: " & thisapplication.activeDocument.FullDocumentName & vbNewLine & vbNewLine & _
                "Part Number: " & iProperties.Value("Project", "Part Number"), "Test_After_Save_Document")					
			Catch 
			End Try
			
			' remove the handler or you will be in for some troubles
			RemoveHandler appEvents.OnOpenDocument, AddressOf AppEvents_OnOpenDocument
			appEvents = Nothing
		End If
    End Sub

End Class

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 8

checkcheck_master
Advocate
Advocate

Thank you Jelte for your response.
I hadn't come up with that yet and it does provide the info I'm looking for, thanks for the insight.
But indeed, what you already say, that applies to all files that will be opened.
In our environment/structure, that doesn't seem convenient for now.
What I find so strange is that the Part Number already has the new value, which is equated with the file name, but that the new Path is nowhere to be found.
By way of debugging I have a VBA script where I can poke around with Watch in oDoc = ThisApplication.ActiveDocument.
As mentioned, the new Part Number can be found there under PropertySets but a new Path... No idea.
Although the original is apparently not touched and finally the new file will be saved.

0 Likes
Message 6 of 8

JelteDeJong
Mentor
Mentor

I'm not sure if I was clear enough but if the first option is not convenient. The second option (the iLogic rule) can be used with the event trigger "After save" and solves the problem with the after open event.  (internally it will use the "after open"-event but only one time, directly after the save as  🙂  ) Did you try this? I do expect that you will get the expected values.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 7 of 8

checkcheck_master
Advocate
Advocate

I'm going to try Jelte, thanks again for the explanation and quick response, quite handy that same time zone 🙂

0 Likes
Message 8 of 8

checkcheck_master
Advocate
Advocate

Hi Jelte,

I suspect that the 'OnOpenDocument' event continues to run in the background even though it is closed, could that be possible?
When I use a Punch Tool, Inventor asks to save the file first.
This only seems to happen when the rule containing the OnOpenDocument event has run once.
Do you have an idea whether this can be overcome?

0 Likes