Replace Reference in vb net

Replace Reference in vb net

Anonymous
Not applicable
1,472 Views
3 Replies
Message 1 of 4

Replace Reference in vb net

Anonymous
Not applicable

Hi All,

 

how to replace references in VB Net

 

 

Sub ReplaceFile(parent As String, oldfilename As String, newfilename As String)
        Dim oDoc As Inventor.Document

        oDoc = OpenFileCad(parent)

        If IsNothing(oDoc) Then
            Exit Sub
        End If

        If Not FileExists(newfilename) Then
            Exit Sub
        End If

        Dim allReferencedFiles As Object
        allReferencedFiles = oDoc.File.ReferencedFileDescriptors
        Dim ofd As FileDescriptor = Nothing

        oldfilename = oldfilename.ToLower
        Dim t As String = ""
        For Each ofd In allReferencedFiles
            Debug.Print(ofd.FullFileName & "  " & FileExists(ofd.FullFileName).ToString)
            t = ofd.FullFileName.ToLower
            If t = oldfilename Then
		ofd.ReplaceReference(newfilename)
                Exit For
            End If
        Next

End Sub

I tried with this code but does not work

Thanks Regards

 

 

 

 

0 Likes
1,473 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Sub ReplaceFileApp(parent As String, oldfilename As String, newfilename As String)

        Dim oADoc As ApprenticeServerDocument
        Dim oApprentice As ApprenticeServerComponent
        oApprentice = New ApprenticeServerComponent
        oADoc = oApprentice.Open(parent)
      
        Dim oFD As FileDescriptor
        For Each oFD In oADoc.File.ReferencedFileDescriptors
            If oFD.FullFileName.ToLower = oldfilename.ToLower Then
                oFD.ReplaceReference(newfilename)
                oADoc.Update

            End If
        Next

    End Sub
0 Likes
Message 3 of 4

MechMachineMan
Advisor
Advisor

1. Replaced file references will not stick in apprentice as you cannot save in apprentice

 

2. Files need to have shared ancestry to be able to replace them using that method. An alternative is to use Occurrence.Replace()


--------------------------------------
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
Message 4 of 4

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

Just an FYI about this article which might also be useful:

http://adndevblog.typepad.com/manufacturing/2016/03/replacereference-vs-filesaveas-vs-onfileresoluti...

 

Cheers,

 



Adam Nagy
Autodesk Platform Services
0 Likes