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: 

Replace Part in Assembly

9 REPLIES 9
Reply
Message 1 of 10
cwhitaker
1127 Views, 9 Replies

Replace Part in Assembly

I am trying to use the Inventor.ApprenticeServerComponent to open our assemblies, look for a certain file referenced in the assy and replace it with a different part. For example if the assy uses u-bolt x09767 replace it with u-bolt x09770. But if there is a "replace" function i am over looking it, can i do this with VB.NET?
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: cwhitaker

FileDescriptor.ReplaceReference can be used to replace the reference, but
note that the original document and the newly referenced document must share
ancestry (InternalNames must be the same) for the replace to work.

Sanjay-
Message 3 of 10
cwhitaker
in reply to: cwhitaker

I am still not finding the fileDescriptor method you mentioned, do you have an example?
Message 4 of 10
cwhitaker
in reply to: cwhitaker

Never mind i finally found it, Thanks for your help.
Message 5 of 10
Raider_71
in reply to: cwhitaker

Hi do you mind sending me the solution to this as well? I am struggling with this as well.

Thanks
Pieter
Message 6 of 10
cwhitaker
in reply to: cwhitaker

Here is what i came up with, hope it helps:

Imports System.IO

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oInv As New Inventor.ApprenticeServerComponent
Dim oAssy As Inventor.ApprenticeServerDocument
Dim oSave As Inventor.FileSaveAs
Dim blnSave As Boolean
Try
Dim oDirs() As DirectoryInfo = New DirectoryInfo("F:\INVENTOR_Drawings").GetDirectories("*", SearchOption.AllDirectories)
For Each oDir As DirectoryInfo In oDirs
If ProcessDir(oDir.FullName) Then
If oDir.GetFiles("*.iam").Length > 0 Then
Dim oFiles() As FileInfo = oDir.GetFiles("*.iam")
For Each oFile As FileInfo In oFiles
oAssy = oInv.Open(oFile.FullName)
blnSave = False
For Each oPart As Inventor.ReferencedFileDescriptor In oAssy.ReferencedFileDescriptors
If InStr(1, oPart.FullFileName, "x09767.ipt", CompareMethod.Text) > 0 Then
Call oPart.PutLogicalFileNameUsingFull("f:\inventor_drawings\standard_ipt\x_pn\x09770.ipt")
blnSave = True
End If
Next
If blnSave Then
oSave = oInv.FileSaveAs
oSave.AddFileToSave(oAssy, oAssy.FullFileName)
oSave.ExecuteSave()
End If
oAssy.Close()
Next
End If
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Function ProcessDir(ByVal Name As String) As Boolean
Dim blnRet As Boolean = True
If InStr(1, Name, "content center", CompareMethod.Text) > 0 Then
blnRet = False
End If
If InStr(1, Name, "tube and pipe", CompareMethod.Text) > 0 Then
blnRet = False
End If
If InStr(1, Name, "design accelerator", CompareMethod.Text) > 0 Then
blnRet = False
End If
If InStr(1, Name, "oldversions", CompareMethod.Text) > 0 Then
blnRet = False
End If
If InStr(1, Name, "imported components", CompareMethod.Text) > 0 Then
blnRet = False
End If
If InStr(1, Name, "cable and harness", CompareMethod.Text) > 0 Then
blnRet = False
End If
If InStr(1, Name, "hoffman enclosures", CompareMethod.Text) > 0 Then
blnRet = False
End If
If InStr(1, Name, "customer files", CompareMethod.Text) > 0 Then
blnRet = False
End If
Return blnRet
End Function
End Class
Message 7 of 10
Raider_71
in reply to: cwhitaker

Hi,

Thanks for the raply! Its a little over my head... I am new to VB.NET and only recently started with basic programming. I can do quite a bit already but nowhere near the complexity of this.
I need basic code that will replace a file reference (c:\temp\part1.ipt) in an assy (c:\temp\Assy.iam) with another (c:\temp\part2.ipt). Its literally as simple as that. I need to do it outside INV using ApprenticeServer. Any pointers?

Thanks once again for the help.

Pieter
Message 8 of 10
cwhitaker
in reply to: cwhitaker

My code was a batch process, here is a simplified version for you to use as reference (i haven't tested it so let me know if you have any problems). This will work outside of Inv, just put in button on a form and give it a try.

Dim oInv As New Inventor.ApprenticeServerComponent
Dim oAssy As Inventor.ApprenticeServerDocument
Dim oSave As Inventor.FileSaveAs

Try
oAssy = oInv.Open("c:\temp\assy.iam")
For Each oPart As Inventor.ReferencedFileDescriptor In oAssy.ReferencedFileDescriptors
If InStr(1, oPart.FullFileName, "c:\temp\part1.ipt", CompareMethod.Text) > 0 Then
Call oPart.PutLogicalFileNameUsingFull("c:\temp\part2.ipt")
End If
oSave = oInv.FileSaveAs
oSave.AddFileToSave(oAssy, oAssy.FullFileName)
oSave.ExecuteSave()
oAssy.Close()
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Message 9 of 10
Raider_71
in reply to: cwhitaker

Thanks I will give this a try tomorrow. Bit late here (11pm) and busy shutting down PC.

Really appreciate the help!!

Pieter
Message 10 of 10
Raider_71
in reply to: cwhitaker

Thanks mate this works perfectly! Thanks for the help!!

Have you ever tried to replace a derived part reference using VB.net?

Regards
Pieter

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

Post to forums  

Autodesk Design & Make Report