Changing all reference files for DWG file

Changing all reference files for DWG file

shrey9GP3F
Enthusiast Enthusiast
228 Views
1 Reply
Message 1 of 2

Changing all reference files for DWG file

shrey9GP3F
Enthusiast
Enthusiast

Hello,

 

I am trying to replace all the reference files for an Inventor DWG file (new files already exist in the target folder). But ReferencedFileDescriptor does not replace the suppressed files. How do I replace all the file references without modifying the model state?

 

 

 

 

public static void ChangeRef(Inventor.Document oDoc)
        {

            foreach (Inventor.FileDescriptor oFileDesc in oDoc.File.ReferencedFileDescriptors)
            {
                string oSubFileName = System.IO.Path.GetFileNameWithoutExtension(oFileDesc.FullFileName);
                string oSubFileExt = System.IO.Path.GetExtension(oFileDesc.FullFileName);
                string oSubNewFileName =  @"C:\Users\Public\Desktop\NewFolder\" + oSubFileName + "_NEW" + oSubFileExt;


                oFileDesc.ReplaceReference(oSubNewFileName);
            }
        }

 

 

 

 

 

 

 

0 Likes
229 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @shrey9GP3F.  I am not fluent in C#, but it looks to me like the code posted here is missing a step.  In line 4, it looks like you are attempting to get 'ReferencedFileDescriptors' directly from a Document object (oDoc), but I believe you need to get the document's 'File', before you can then get that File.ReferencedFileDescriptors.  So, I believe you would need to replace this:

foreach (Inventor.FileDescriptor oFileDesc in oDoc.ReferencedFileDescriptors)

...with this:

foreach (Inventor.FileDescriptor oFileDesc in oDoc.File.ReferencedFileDescriptors)

However, if there are ModelStates involved, and you want to maintain each view's reference to the equivalent ModelState of the replacement model, then you may have to iterate each view, on each sheet, and replace its reference individually.

DrawingView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(sReplacementFileName)

That way you can extract the originally specified ModelState name (or iPart/iAssembly Member name) before the replacement, then set it back after the replacement, to maintain it.  Each DrawingView object has a property named ActiveMemberName, which records which iPart/iAssembly member it is set to, and a property named ActiveModelState, which obviously records which ModelState it is set to.  But the ActiveModelState property is ReadOnly, so you would have to use the DrawingView.SetActiveModelState method to set the value back to the view after the replacement.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes