Reopening the current drawing with updates deferred

Reopening the current drawing with updates deferred

Anonymous
Not applicable
619 Views
4 Replies
Message 1 of 5

Reopening the current drawing with updates deferred

Anonymous
Not applicable

Hi

I have a problem where when I open a drawing, the part may have changed and propagated changes to the drawing.

For historical reasons I need to make a copy of the drawing first. (Before you suggest I re-frame the problem out of existence, I can't make the copy at the last moment of the drawing being open, because the drawing doesn't know when the change needs to be committed, as it's dependent on external factors. So I can only make the copy once changes to the model may have been already made.)

To make things easier for me, I'm trying to make a script that substitutes the currently open drawing for the same drawing with updates deferred.

What's weird is, despite my best efforts, I can't seem to get rid of the reference to the updated drawing, and even though I successfully reopen the drawing with updates deferred, it opens with all the updates already effected.

Not only that, but with every different attempt I've made, it seems like it permanently causes the drawing to be updated, as whenever I open it from scratch the updates are applied already.

Is this possible?

Here's the most over-engineered rule I've been working with, to try to eradicate all traces of the original document:

Imports System.Threading.Tasks
Sub Main()
	Const sTargetPathArgName As String = "TargetDoc"

	Dim oApp As Application = ThisApplication
	Dim oDoc As Document = ThisDoc.Document
	oDoc.Activate()
	Dim sActivePath As String = oDoc.FullDocumentName
	
	Dim sTargetPath As String = String.Empty
	If RuleArguments.Exists("TargetPath") Then _
		sTargetPath = RuleArguments.Value("TargetPath")
	
	If String.IsNullOrWhiteSpace(sTargetPath) _
	Or sTargetPath = sActivePath _
	OrElse Not IO.File.Exists(sTargetPath) Then
		If sActivePath Is Nothing Then _
			Exit Sub
		Dim oProxyDoc As Document = oApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject)
		Test(oProxyDoc, sActivePath)
		oDoc.Close()
		Exit Sub
	End If

	For Each oD As Document In oApp.Documents
		If oD.FullDocumentName <> sTargetPath Then _
			Continue For
		oD.ReleaseReference()
		Exit For
	Next

	Dim nvmOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	nvmOptions.Add("DeferUpdates", True)
	oApp.Documents.OpenWithOptions(sTargetPath, nvmOptions, True)

	oDoc.Close()
End Sub

Async Sub Test(
	ByVal oDoc As Document _
	, ByVal sTargetPath As String
)
	Await Task.Delay(10000)
	Dim nvmArgs As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	nvmArgs.Add("TargetPath", sTargetPath)
	iLogicVb.Automation.RunExternalRuleWithArguments(oDoc, "OpenSelfWDefer", nvmArgs) ' this is a call to itself, but with a target path
End Sub

 

0 Likes
Accepted solutions (1)
620 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous 

 

I don't think this is possible with iLogic.

 

To close and reopen with defer updates, you need to unload it from memory.

 

But since iLogic is tied to a document, you can't close the document that you have opened and run a rule in without generating a fatal error. 

 

Can you just open the drawing with defer updates from the beginning?

 

EESignature

Message 3 of 5

Anonymous
Not applicable

Thanks for the definitive response.

 

I suspected this was the case, which was why I was both trying to run the rule from the proxy document and use the async sub to let the original rule call end before the next started, in the hopes that would sever the connection.

 

This is for my company. We're a small team, but my coworkers don't really grasp basic things, and opening with deferred updates from the start would require instituting a new policy within our revision process, which realistically is a lot to ask, as much as it may be a small thing in and of itself.

 

Anyway, not having this doesn't leave us any worse off than we were, but it would have been really helpful.

0 Likes
Message 4 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@Anonymous 

 

you could probably do it with a small add-in or use the VBA application project since those will not be tied to the document in the way that the ilogic rule is.

 

Getting Started with Inventor VBA

https://download.autodesk.com/us/community/mfg/part_1.pdf

 

 

EESignature

Message 5 of 5

JelteDeJong
Mentor
Mentor

reopening a file might be a problem but opening a file (with deferred updates) from an external rule is possible. I did write a blog post "Show Changed Dimensions." The rule in that blog post shows the following steps:

  • open a drawing with updates deferred.
  • save all dimensions in memory.
  • Update the drawing.
  • Find all dimensions that have been changed.
  • show which dimensions have been changed.

I expect that this is close to what you want.

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