05-29-2018
05:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
05-29-2018
05:40 PM
Try the sample below via API.
Replace all sub assembly which include Collar.ipt and replace it.
Sub Main()
'Component.Replace("CollarBottomPlate:1", "Collar.ipt", True)
Dim doc As AssemblyDocument
doc = ThisApplication.ActiveDocument
Dim strFileName As String
strFileName = "Collar:"
Dim strPath As String
strPath = "C:\TEMP\iLogicTest\GA\CollarBottomPlate.ipt"
Dim oOcc As ComponentOccurrence
For Each oOcc In doc.ComponentDefinition.Occurrences
Call ReplaceOccurrence(strFileName, strPath, oOcc)
Next
End Sub
Sub ReplaceOccurrence(strFileName As String, strPath As String, oOcc As ComponentOccurrence)
If InStr(oOcc.Name,strFileName)>0 Then
Call oOcc.Replace(strPath, False)
End If
Dim osubOcc As ComponentOccurrence
If oOcc.SubOccurrences.Count > 0 Then
For Each osubOcc In oOcc.SubOccurrences
Call ReplaceOccurrence(strFileName, strPath, osubOcc)
Next
End If
End Sub
another example like to replace Collar.ipt in every assembly
Sub Main()
'Component.Replace("CollarBottomPlate:1", "Collar.ipt", True)
Dim doc As AssemblyDocument
doc = ThisApplication.ActiveDocument
Dim strFileName As String
strFileName = "Collar:1"
Dim strPath As String
strPath = "C:\TEMP\iLogicTest\GA\CollarBottomPlate.ipt"
Dim oOcc As ComponentOccurrence
For Each oOcc In doc.ComponentDefinition.Occurrences
Call ReplaceOccurrence(strFileName, strPath, oOcc)
Next
End Sub
Sub ReplaceOccurrence(strFileName As String, strPath As String, oOcc As ComponentOccurrence)
If oOcc.Name = strFileName Then
Call oOcc.Replace(strPath, False)
End If
Dim osubOcc As ComponentOccurrence
If oOcc.SubOccurrences.Count > 0 Then
For Each osubOcc In oOcc.SubOccurrences
Call ReplaceOccurrence(strFileName, strPath, osubOcc)
Next
End If
End Sub
Hope it helps!
Xun