I'm looking for a piece of code for opening referenced files that have the flag dirty from within an asembly file. These referenced files must be opened in a separate window so the executed ilogic codes that are stored in the referenced file with triggerd after save document does the right job. For instance one of these codes is creating a thumbnail of the solid part (i use these thumbnails in an excel partlist). For this you need to make the part visible in the graphic window.
The thing is that if you save an assembly file and all of its changes in the dependend files, the ilogic codes stored in the dependent files will execude. sofar so good but in case of creating a thumbnail the executed code make a screenprint of the active graphic window of the assembly file and not of the depended file the code is embed. This is also the case for creating a dwf file of depended files.
The topic "vba code for opening parts in the assembly" is close to what i want.
Can someone help me with this?
thanks in advanced,
Jeroen
Solved! Go to Solution.
Solved by j_r_a_koning. Go to Solution.
Document.AllReferencedDocuments collection provides you with the references to all referenced documents.
Referenced parts and subassemblies are already opened as a result of being referenced by the parent document.
So you may check their Dirty property without any problem.
If the Document.Views.Count = 0 then the document is opened in the invisible mode.
To make it visible use Document.Views.Add() method.
You may also try to perform your operations while View.Visible property is equal to False.
Cheers,
Dear Vladimir Ananyev,
Thanks for your suggestions. I will try to write vba code for this, but I think this will not be easy. Hopefully I can come back to you for some extra information 😉
With kind regards,
Jeroen
Edited by
Discussion_Admin
Dear Vladimir Ananyev,
Thank your for your contribution in this.
For anyone who can use this piece of code:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Public Sub Open_save_AllReferencedDocs_Dirty() ' Get the Documents collection object.
Dim i As Integer
Dim oDoc As AssemblyDocument 'use the object "Documents" if collect all documents in memory
Set oDoc = ThisApplication.ActiveDocument 'use the object "ThisApplication.Documents" for collect all documents in memory
'Log all filenames from Documents in memory to a specific file
'Give the flag dirty=true when the document was edited.
'If a logfile exist delete it, if not step in to the next line
On Error Resume Next
Kill "D:\\temp\\List AllReferencedDocs Dirty.txt" 'Delete the file
Open "D:\\temp\\List AllReferencedDocs Dirty.txt" For Output As #1 'create and open file
Print #1, Tab(10); "Document Name"; Tab(120); "File Dirty"; vbNewLine 'print a header to the txt file
ThisApplication.SilentOperation = True 'Causes all dialogs to be suppressed and take the default behavior
' Iterate through the contents of the Documents collection.
For i = 1 To oDoc.AllReferencedDocuments.Count 'use object+method "oDoc.Count" for iterate through the all docs in memory collection
' Get a specific item from the Documents collection.
Dim invDoc As Document
Set invDoc = oDoc.AllReferencedDocuments.Item(i) 'use the object+method "oDoc.Item(i)" to get all docs in memory
'Display the full filename of the document in the Immediate window.
Debug.Print invDoc.FullFileName 'only necessarily when debug the code to see what files are in collection
'place filename in open txt document
Print #1, invDoc.FullFileName; Tab(120); invDoc.Dirty
'check if the file is dirty, then open and save it (the file is edited in this session )
If invDoc.Dirty = True Then 'check if the file is dirty, true means file is dirty
ThisApplication.Documents.Open (invDoc.FullFileName) 'Open the specific document
invDoc.Save2 (False) 'Save document without dependents, "Save2( [SaveDependents] As Boolean, [DocumentsToSave] As Variant )"
invDoc.Close 'close the file
End If
Next
ThisApplication.SilentOperation = False
MsgBox ("Completed, see Logfile D:\\temp\\List AllReferencedDocs Dirty.txt.")
'reset the vba code, otherwise the file in D:\\ will still be in use by the VBa application
End
End Sub
------------------------------------------------------------------------------------------------------------------
I would like to thank everyone who has contributed to this forum. It helped me to get more insight into ilogic and the vba language.
with kind regards,
Jeroen Koning