Replace Model Reference - inventor 2014

Replace Model Reference - inventor 2014

Anonymous
Not applicable
424 Views
3 Replies
Message 1 of 4

Replace Model Reference - inventor 2014

Anonymous
Not applicable

I have a Inventor template part say Template.ipt and a template drawing Template.idw referencing Template.idw

I make minor modification to Template.ipt and copy it as Part1.ipt using . I copy Template.idw to Part1.idw.

Now how do I change the Reference model of Part1.idw to us Part1.ipt instead of Template.ipt

 

In Inventor General Discussion Forum I saw the following posting, where it is mentioned to use the Manage--->Modify--->Replace Model Reference

http://forums.autodesk.com/t5/inventor-general-discussion/replace-model-reference-inventor-2014/m-p/...

 

What is the method to be called and from which class/object, to do the equivalent of Manage--->Modify--->Replace Model Reference?

Thanks

PV Subramanian

0 Likes
425 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

You can use the apprentice server to do this.

 

Here is a sample from the help file

 

Private Sub ChangeReferenceSample()
Dim oApprentice As New ApprenticeServerComponent

' Open a document.
Dim oDoc As ApprenticeServerDocument
Set oDoc = oApprentice.Open("C:\Temp\Assembly1.iam")

' Iterate through the references looking for a
' reference to a specific file.
Dim oRefFileDesc As ReferencedFileDescriptor
For Each oRefFileDesc In oDoc.ReferencedFileDescriptors
If oRefFileDesc.FullFileName = "C:\Temp\OldPart.ipt" Then
' Replace the reference.
Call oRefFileDesc.PutLogicalFileNameUsingFull( _
"C:\Temp\NewPart.ipt")
Exit For
End If
Next

' Set a reference to the FileSaveAs object.
Dim oFileSaveAs As FileSaveAs
Set oFileSaveAs = oApprentice.FileSaveAs

' Save the assembly.
Call oFileSaveAs.AddFileToSave(oDoc, oDoc.FullFileName)
Call oFileSaveAs.ExecuteSave
End Sub

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks for the reply. But I want to replace the reference model in the drawing (.idw) and not in the assembly.

Thanks

PV Subramanian

0 Likes
Message 4 of 4

Anonymous
Not applicable

This works for replacing an ipt or iam reference within an idw also.

 

Public Class Form1

    Private Sub TestApprentice()
        'create new instance of apprentice
        Dim oAppSvr As New ApprenticeServerComponent
        Dim FullDocName As String
        
	FullDocName = "C:\Temp\Template.idw"
        
        Dim OldPart As String = "C:\Temp\Template.ipt"
        Dim NewPart As String = "C:\Temp\Part1.ipt"

        'open document
        Dim oDoc As ApprenticeServerDocument
        oDoc = oAppSvr.Open(FullDocName)

        Dim oRefFileDesc As FileDescriptor

        For Each oRefFileDesc In oDoc.File.ReferencedFileDescriptors
            If UCase(oRefFileDesc.FullFileName) = UCase(OldPart) Then
                Call oRefFileDesc.ReplaceReference(NewPart)
                Exit For
            End If
        Next

        Dim oFileSaveAs As FileSaveAs
        oFileSaveAs = oAppSvr.FileSaveAs

        Call oFileSaveAs.AddFileToSave(oDoc, oDoc.FullFileName)
        Call oFileSaveAs.ExecuteSave()

        oDoc.Close()

    End Sub



    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Call TestApprentice()
    End Sub

    
End Class
0 Likes