Rename a set of work features through Ilogic

Rename a set of work features through Ilogic

mat_hijs
Collaborator Collaborator
959 Views
2 Replies
Message 1 of 3

Rename a set of work features through Ilogic

mat_hijs
Collaborator
Collaborator

I'm looking for a way to rename a selected set of work features through Ilogic. For example:

 

I'll make a part with 8 vertical work axis, and 3 horizontal work axis.

I want to name the vertical work axis "As_Stijl_*" and the horizontal work axis "As_Regel_*". * being the numbers from 1-8 and 1-3.

I found this bit of code, which renames all work axis in the part. I think it shouldn't be too hard to make something where you'd select a set of work features and rename only the selected set. But I have no idea how to start this. Can anyone help me out?

 

'Rename work axis
oDoc = ThisApplication.activedocument
i = 1
For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxis
    If oWorkAxis.IsCoordinateSystemElement = False Then 
    oWorkAxis.Name = "As_Stijl" & i
    i=i+1
    End If
Next

0 Likes
Accepted solutions (1)
960 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

@mat_hijs 

try this 🙂

Just select all workaxes you want to rename and then run the rule.

oDoc = ThisApplication.ActiveDocument
i = 1
Dim oName As String = InputBox("Work axis name:", "Rename workaxes", "As_Stijl_")
For Each oWorkAxis In oDoc.SelectSet
	If TypeOf (oWorkAxis) Is WorkAxis
		If oWorkAxis.IsCoordinateSystemElement = False Then
			Try
				oWorkAxis.Name = oName & i
			Catch
				Dim temp As Integer = i
				While True
					Try
						oWorkAxis.Name = oName & temp
						Exit While
					Catch
						temp += 1
					End Try
				End While
			End Try
			i = i + 1
		End If
	End If
Next
0 Likes
Message 3 of 3

mat_hijs
Collaborator
Collaborator

Works like a charm! I changed the code a little bit so I get 2 inputboxes, one for a prefix and one for a suffix, and it's gonna save me a good amount of time copying, pasting and editing the names. Thanks!