Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA code for opening referenced files (dirty) in an assembly

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
j_r_a_koning
2658 Views, 3 Replies

VBA code for opening referenced files (dirty) in an assembly

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.

 http://forums.autodesk.com/t5/Inventor-Customization/vba-code-for-opening-part-in-the-assy/td-p/4373...

 

Can someone help me with this?

 

thanks in advanced,

 

Jeroen

3 REPLIES 3
Message 2 of 4

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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 4
j_r_a_koning
in reply to: j_r_a_koning

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

Message 4 of 4
j_r_a_koning
in reply to: j_r_a_koning

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

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report