Apprentice Replace Reference Issues

Apprentice Replace Reference Issues

MechMachineMan
Advisor Advisor
1,162 Views
2 Replies
Message 1 of 3

Apprentice Replace Reference Issues

MechMachineMan
Advisor
Advisor

Issue 1: 

           On the occasional run of my excel vba rule, after I open a file with apprentice, save it as a new name, and then try to  reassign it to modify iProps, it gives me an error. Looking in the debug window it shows the PropertySets as application error. Is there a better way to change Properties in a newly saved file in apprentice then to reopen it under the new file name, modify properties, and then flushing to file?

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
1,163 Views
2 Replies
Replies (2)
Message 2 of 3

frederic.vandenplas
Collaborator
Collaborator

Hi,

 

A little bit of code would be nice to see where the problem may be.

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 3 of 3

MechMachineMan
Advisor
Advisor

Sorry about that, I was rushed at the end of the workday. Anyways, the code I've been using with varying success - sometimes it saves fine, others it doesn't, is pasted below.

 

I'm guessing I manage to confuse apprentice because I have more than one document opened/assigned to the same sharedapprentice As ApprenticeServerComponent, but can anyone confirm this?

ie; in the main sub

Set oParentDoc = sharedapprentice.Open("PARENTFILENAME.ipn")

Set oOldDoc = sharedapprentice.Open("FILENAME.iam")

Set oNewDoc = sharedapprentice.Open("FILENAME2.iam")

 

Call ReplaceRef(oOldDoc, oNewDoc, oParentDoc)

 

 

 

Sub ReplaceRef(oOldDoc As ApprenticeServerDocument, oNewDoc As ApprenticeServerDocument, Optional oParentDoc As ApprenticeServerDocument = vbNullString)
    
    Dim oWasReplaced As Boolean
    oWasReplaced = False
    'Replace ref in parent doc
    If Not oParentDoc Is Nothing Then
        Dim oDD As DocumentDescriptor
        For Each oDD In oParentDoc.ReferencedDocumentDescriptors
            If oDD.ReferencedFileDescriptor.FullFileName Like "*" & fso.GetBaseName(oOldDoc.FullFileName) & "." & fso.GetExtensionName(oOldDoc.FullFileName) Then
                On Error Resume Next
                oDD.ReferencedFileDescriptor.ReplaceReference (oNewDoc.FullFileName)
                If Err.Number <> 0 Then
                    MsgBox ("Error Found")
                End If
                On Error GoTo 0
                oWasReplaced = True
            End If
        Next
        
        With sharedapprentice.FileSaveAs
            Call .AddFileToSave(oParentDoc, oParentDoc.FullFileName)
            Call .ExecuteSave
        End With
        Call oParentDoc.Close
        Set oParentDoc = Nothing
        
    End If
    If oWasReplaced = False Then
        MsgBox ("Failed to Replace!")
    End If
        
End Sub

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes