
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.