Change the pattern browser names

Change the pattern browser names

bhavik4244
Collaborator Collaborator
589 Views
6 Replies
Message 1 of 7

Change the pattern browser names

bhavik4244
Collaborator
Collaborator

Hello there,

 

I want to change 2nd letter from right for pattern  and rename browser node like shown in below image.

 

@JhoelForshav  has help me but I want it like this way.

 

bhavik4244_0-1632299482653.png

Thanks!

 

 


Bhavik Suthar
0 Likes
Accepted solutions (1)
590 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @bhavik4244 

Sorry, I just saw that you requested something else in your previous thread, is that still something you need help with?

I didn't really understand that well how you wanted it to work...

 

For this question though, I think something like this should do the trick? 🙂

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oPattern As OccurrencePattern = oAsm.ComponentDefinition.OccurrencePatterns(1)
Dim oAlphabet As String() = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", _
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }
For i = 1 To oPattern.OccurrencePatternElements.Count
	Dim n As Integer = 1
	For Each oOcc As ComponentOccurrence In oPattern.OccurrencePatternElements(i).Occurrences
		oOcc.Name = oAlphabet(n - 1) & i & n.ToString("00")
		n += 1
	Next
Next

 

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

Looks like I'm a few minutes too late, but here is what I was working on for your situation.

 

 

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oPatt As OccurrencePattern = oADef.OccurrencePatterns.Item("Component Pattern 8:1")
Dim oAlpha() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray
Dim oLetter As Char
For oEl As Integer = 1 To oPatt.OccurrencePatternElements.Count
	Dim oElement As OccurrencePatternElement = oPatt.OccurrencePatternElements.Item(oEl)
	'first loop through components to rename them with first two characters
	For oInt1 As Integer = 1 To oElement.Occurrences.Count
		Dim oOcc As ComponentOccurrence = oElement.Occurrences.Item(oInt1)
		oLetter = oAlpha(oInt1)
		oOcc.Name = oLetter & oEl
	Next
	'second loop through (in reverse) to rename again, adding last two characters
	Dim oCounter As Integer = 1
	For oInt2 As Integer = oElement.Occurrences.Count To 1 Step -1
		Dim oOcc As ComponentOccurrence = oElement.Occurrences.Item(oInt2)
		oOcc.Name = oOcc.Name & oCounter.ToString("00")
	Next
Next

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7

JhoelForshav
Mentor
Mentor

Oh!, I missed that the last number should be counting down.

Modified code below:

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oPattern As OccurrencePattern = oAsm.ComponentDefinition.OccurrencePatterns(1)
Dim oAlphabet As String() = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", _
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }
For i = 1 To oPattern.OccurrencePatternElements.Count
	Dim n As Integer = 0
	Dim p As Integer = oPattern.OccurrencePatternElements(i).Occurrences.Count
	For Each oOcc As ComponentOccurrence In oPattern.OccurrencePatternElements(i).Occurrences
		oOcc.Name = oAlphabet(n) & i & p.ToString("00")
		n += 1 
		p -= 1
	Next
Next
Message 5 of 7

bhavik4244
Collaborator
Collaborator

@JhoelForshav 

@WCrihfield 

 

you're almost there. But,  need my first alphabet to be constant in pattern element whereas with this code, it replace to order A, B, C, likewise. It can be some time P. B, N, K in any order. in short, fist letter correspond to the first component, and likewise others elemets as well.

bhavik4244_0-1632388550063.png

It can be like this also,

 

bhavik4244_1-1632388773604.png

very close to the solution but not completely correct! please have a look.

I highly appriciate your efforts.

 


Bhavik Suthar
0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

@bhavik4244 

If I understand correctly, the names of the first pattern element are already set? So you want to change that one, just extract the lettering sequence from it and apply it to the other elemets?

Something like this?

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oPattern As OccurrencePattern = oAsm.ComponentDefinition.OccurrencePatterns(1)
Dim oLetters As String
For i = 1 To oPattern.OccurrencePatternElements.Count
	Dim n As Integer = 0
	Dim p As Integer = oPattern.OccurrencePatternElements(i).Occurrences.Count
	For Each oOcc As ComponentOccurrence In oPattern.OccurrencePatternElements(i).Occurrences
		If i = 1
			oLetters = oLetters & oOcc.Name.Chars(0)
		Else
			oOcc.Name = oLetters.Chars(n) & i & p.ToString("00")
		End If
		n += 1
		p -= 1
	Next
Next

Or like this to still set the numbering of the first element but keep the first letter:

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oPattern As OccurrencePattern = oAsm.ComponentDefinition.OccurrencePatterns(1)
Dim oLetters As String
For i = 1 To oPattern.OccurrencePatternElements.Count
	Dim n As Integer = 0
	Dim p As Integer = oPattern.OccurrencePatternElements(i).Occurrences.Count
	For Each oOcc As ComponentOccurrence In oPattern.OccurrencePatternElements(i).Occurrences
		If i = 1
			oLetters = oLetters & oOcc.Name.Chars(0)
			oOcc.Name = oOcc.Name.Chars(0) & i & p.ToString("00")
		Else
			oOcc.Name = oLetters.Chars(n) & i & p.ToString("00")
		End If
		n += 1
		p -= 1
	Next
Next

 

0 Likes
Message 7 of 7

bhavik4244
Collaborator
Collaborator

@JhoelForshav 

 

Awesome!!! This is what I exactly want.

Many thanks,

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oPattern As OccurrencePattern = oAsm.ComponentDefinition.OccurrencePatterns(1)
Dim oLetters As String
For i = 1 To oPattern.OccurrencePatternElements.Count
	Dim n As Integer = 0
	Dim p As Integer = oPattern.OccurrencePatternElements(i).Occurrences.Count
	For Each oOcc As ComponentOccurrence In oPattern.OccurrencePatternElements(i).Occurrences
		If i = 1
			oLetters = oLetters & oOcc.Name.Chars(0)
			oOcc.Name = oOcc.Name.Chars(0) & i & p.ToString("00")
		Else
			oOcc.Name = oLetters.Chars(n) & i & p.ToString("00")
		End If
		n += 1
		p -= 1
	Next
Next

 


Bhavik Suthar