- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I have a bolt which has been assembled 3 times in an assy. Then this bolt is patterned around the axis of the part using circular pattern command. Let's call this pattern A. So now, Pattern A has 2 instances Element 1 and Element 2 and each instance have 3 bolts in it.
Pattern A is again patterned "n" no of times around another axis using circular pattern command. So now, pattern A is sitting inside another pattern. Let's call it Pattern B.
So Pattern B is the top level pattern which contains pattern A as its instances "n" no of times. Pattern A then contains 2 instance as given above. I also have same bolt existing in the model tree outisde pattern B.
I need iLogic code to do component replace on the bolt inside pattern B. The code should replace all instaces of the bolts but only inside the pattern B. Any bolt existing outside pattern B should remain unchanged.
Can anyone help with this please? I have searched internet to find something similar but no luck.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, you can try this:
Dim PatternName As String = "Component Pattern 1:1" ' This is the Pattern you want to search for Dim OldFile As String = "MyFile1" ' This is the part you want to replace, without extension
Dim NewFile As String = "C:/MyPath/MyFile2.ipt" ' This is the replacing part, full path Dim oDoc As Document = ThisApplication.ActiveDocument Dim oOcc As ComponentOccurrence For Each oOcc In oDoc.ComponentDefinition.Occurrences Dim oName As String = oOcc.Name
Dim FNP As Integer = InStrRev(oName, ":", -1)
oName = Left(oName, FNP - 1)
If Not oName = OldFile Then Continue For
Try If Not oOcc.PatternElement.Type.ToString = "kOccurrencePatternElementObject" Then Continue For Catch Continue For End Try Dim oElement As OccurrencePatternElement = oOcc.PatternElement Dim oParent As Object = oElement.Parent If oParent.Name = PatternName Then oOcc.Replace(NewFile, False) ' False to not replace all occurrences End If Next
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Mike,
Thanks for your code. When using it, following line give me an error.
oName = Left(oName, FNP - 1)
The error is
Argument 'Length' must be greater or equal to zero.
My guess is this is happening because I am not using default inventor names for bolts. Rather I am using my own defined names as "BR BOLT 1" "BR BOLT 2" and "BR BOLT 3".
Any idea?
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have come up with the following code which works fine but I hate the fact that I have to hard code the names of each parent bolt in component.replace command. See the code below.
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oPattern As OccurrencePattern oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("BR STRING FASTENER SET") Dim oElement As OccurrencePatternElement oElements = oPattern.OccurrencePatternElements Dim i As Integer For i = 1 To oElements.Count Dim OCCS As OccurrencePatternElement OCCS = oElements(i).Components(1).OccurrencePatternElements(1) For Each OCCS In oElements Try Component.Replace("BR BOLT 1", "File name to replace with including path", False) Component.Replace("BR BOLT 2", "File name to replace with including path", False) Component.Replace("BR BOLT 3", "File name to replace with including path", False) Catch 'some code here
End Try Next Next InventorVb.DocumentUpdate()
As I understand, this code is replacing only the parent or master component. The rest of the occurrances are replaced or updated due to fact that they are the pattern of this master component. In this case the master components are 3 bolts.
Anyway it works!!
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is there a way to not have to hard code the pattern name? So that I can loop through occurrences in an assembly and suppress that "top-level" pattern.