ilogic to replace Model Reference in idw

ilogic to replace Model Reference in idw

Anonymous
Not applicable
1,696 Views
1 Reply
Message 1 of 2

ilogic to replace Model Reference in idw

Anonymous
Not applicable

Hi
I have a lot of idw's where I am going
to replace Model Reference  ( ipt or iam) in an idw.

example :
12-45.idw has model reference 890-45.ipt (or iam), but it should be change to 12-45.ipt (or iam)


 is there anyone who has a suggestion for an ilogic code that can scan a folder and change all idw's

or just change the model reference when the idw is opened

 

 

0 Likes
1,697 Views
1 Reply
Reply (1)
Message 2 of 2

MechMachineMan
Advisor
Advisor

Here is the bulk of the working code.

 

oDoc = The Document which you want the reference changed in.
oDocToSwap = SomeDocument that you want to remove

For Each oRefDoc in oDoc.ReferencedDocumentDescriptors If oRefDoc.FullDocumentName = oDocToSwap Then oFD = oRefDoc.ReferencedFileDescriptor 'Filter the new file to the same file extension oNewFileRef = FileBrowse("Select new reference!" ,"*" & Right(oRefDoc.ReferencedFileDescriptor.FullFileName, 4)) If oNewFileRef = "" Then MsgBox("New selection ref invalid!" & vbLf & vbLf & "Aborting rule!") Exit Sub End If oFD.ReplaceReference(oNewFileRef) Exit For End If Next

Private Function FileBrowse(oTitle As String, oFilterStr As String) As String

    '"Inventor Files (*.iam;*.ipt;*.idw;*.dwg)|*.iam;*.ipt;*.idw;*.dwg|All Files (*.*)|*.*"
    '       Note, for function, we need to pass the additional items with a colon.

    Dim oFileDlg As FileDialog
    Call ThisApplication.CreateFileDialog(oFileDlg)

    On Error Resume Next

    With oFileDlg
        .FilterIndex = 1
        .MultiSelectEnabled = False
        .CancelError = True
        .Filter = "Inventor Files (" & oFilterStr & ")|" & oFilterStr & "|All Files (*.*)|*.*"
        .DialogTitle = oTitle
        .ShowOpen
    End With
    
    If Err.Number <> 0 Then
        MsgBox("Error Exists")

    ElseIf Not oFileDlg.FileName = "" Then
        Dim fNames As Object
        fNames = Split(oFileDlg.FileName, "|")
        
        Dim curName As Object
        Dim lstSource As Object
       
        For Each curName In fNames
            lstSource.AddItem(curName)
        Next curName
    End If
    
    Return oFileDlg.FileName
End Function

--------------------------------------
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