This run-time error 91 doesn't make sense to me. Generally the issue is I didn't define something, but I've noted everything this time.
The error is on this line:
Set f = ThisApplication.ActiveDocument.File
ThisApplication is defined towards the beginning. File is defined right before that line.
Here is my code:
Option Explicit Public Sub ReplaceReference() Dim invApp As Inventor.Application Set invApp = ThisApplication Dim NameStr As String Dim NewNamePath As String Dim NameStr2 As String Dim OldNamePath As String NameStr = Renamer.New_Name.Text 'Concatenates the full new file path NewNamePath = Renamer.Path_Text.Text & "\" + NameStr & "-" & Right("00" & i, 3) & ".ipt" If Err.Number <> 0 Then MsgBox "Error Found After NewNamePath:" & Err.Description Err.Clear NameStr2 = Renamer.Old_Name_Display.Text 'Concatenates the old file NAME OldNamePath = NameStr2 & "-" & Right("00" & i, 3) & ".ipt" If Err.Number <> 0 Then MsgBox "Error Found After OldNamePath:" & Err.Description Err.Clear Do While i < 99 Dim f As File Set f = ThisApplication.ActiveDocument.File Dim fd As FileDescriptor For Each fd In f.ReferencedFileDescriptors If fd.FullFileName = OldNamePath Then fd.ReplaceReference (NewNamePath) End If Next Loop End Sub
I know run-time error 91 is common and seems silly, but I just don't know what is wrong with it.
Solved! Go to Solution.
Solved by rjay75. Go to Solution.
Solved by rjay75. Go to Solution.
That would be awesome, thanks so much.
The reason I did it this way is because all the files have to actually be renamed, not just from within the assembly, by the way. There are multiple assemblies containing those files.
Attached is a rough concept of of doing an inplace copy design. It works, but is not completely tested on complex assembly types.
Super Basic Instructions
1. Add the files you want to copy. This should be drawings and/or assemblies. You can add multiple drawings at once. Useful if you multiple drawing files per a design.
2. Select the source and target directories. If your source directories has sub directories any files copied will maintain the same folder structure.
3. Add prefix patterns. ie if the numbers are ABCD-001 -> XYZ-001 then it would be ABCD, and XYZ
4. Refresh and it will scan and display all the files that will be copied and the location they will copy to. This allows you to fix the prefixes if needed. (The Don't Copy button isn't set to do anything.
5. Copy the design. It will copy in the background and prompt if you want it to open.
Not it also changes the partnumbers on the copied files to match the new files.
Its a rough start but it may give you hints and ideas on how to modify areas of your project.
Oh my goodness! It's fantastic. I'm going to make a few modifications to it, but it's wonderful. I will definitely recommend you and your company to my coworkers and feellow engineering friends. Thanks so much, rjay!
I'm incredibly excited!!!!!!!!!!!!!!!!!!!! I've been trying to figure this out for two months.