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: 

Run-Time Error 91?

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
alyssaweaver
1262 Views, 22 Replies

Run-Time Error 91?

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.

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
22 REPLIES 22
Message 21 of 23
alyssaweaver
in reply to: rjay75

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.

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
Message 22 of 23
rjay75
in reply to: alyssaweaver

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

 

CopyDesign2.png

 

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.

 

 

Message 23 of 23
alyssaweaver
in reply to: rjay75

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.

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"

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

Post to forums  

Autodesk Design & Make Report