Ilogic increment feature names in ipt

Ilogic increment feature names in ipt

ppolcynBNVFN
Enthusiast Enthusiast
541 Views
2 Replies
Message 1 of 3

Ilogic increment feature names in ipt

ppolcynBNVFN
Enthusiast
Enthusiast

Hello, I am new to ilogic and wondering if there is a rule created to rename features in a part all at once. Say when I delete an extrusion (or sketch, hole, pattern, etc.) and then I create a new one, the number is off. Can a rule be made to re-increment all features. Example tree:

 

Extrusion2

Sketch7

Hole3

Hole2

 

This rule would rename this list to look like:

 

Extrusion1

Sketch1

Hole1

Hole2

 

Thanks in advance!

 

0 Likes
542 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @ppolcynBNVFN.  What you are asking for is fairly complicated, because there are many different types of features and/or sketches, or other things that might be present in the model browser tree.  There is a built-in system for adding that number after the name, and we do not have access to that built-in system.  So, you would have to be able to recognize the Type of each object, then keep track of every one of that Type of object you find, so you can keep all the numbering sequence for that one specific Type together, and keep track of each sequence place for each Type as you go.  That is many layers of complication.  I created an iLogic rule that you can try out for renaming generic PartFeatures and PlanarSketches in a part.  I did not have a change to fully test this code yet, because I'm about to leave for the day, but here it is below.  I did not take the time to put comments into it due to the time restriction, so if you have questions, I may have to answer them next week.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisDoc.Document
	RenameFeaturesInSequence(oPDoc)
	RenameSketchesInSequence(oPDoc)
End Sub

Sub RenameFeaturesInSequence(oPartDoc As Document)
	If IsNothing(oDoc) OrElse oDoc.IsModifiable = False Then Exit Sub
	Dim oPDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	Dim oFeats As PartFeatures = oPDef.Features
	Dim oDict As New Dictionary(Of String, List(Of PartFeature))
	For Each oFeat As PartFeature In oFeats
		Dim oType As String = System.Enum.GetName(GetType(ObjectTypeEnum), oFeat.Type)
		oType = Replace(Right(oType, oType.Length - 1), "Object", "")
		If oDict.Keys.Contains(oType) = False Then
			oDict.Add(oType, New List(Of PartFeature) From {oFeat })
		Else
			If oDict.Item(oType).Contains(oFeat) = False Then
				oDict.Item(oType).Add(oFeat)
			End If
		End If
	Next
	If IsNothing(oDict) OrElse oDict.Count = 0 Then Exit Sub
	For Each oPair In oDict
		If oPair.Value.Count = 0 Then Continue For
		Dim oInt As Integer = 0
		For Each oPartFeat In oPair.Value
			oInt = oInt + 1
			oPartFeat.Name = oPair.Key & oInt
		Next
	Next
End Sub

Sub RenameSketchesInSequence(oPartDoc As Document)
	If IsNothing(oDoc) OrElse oDoc.IsModifiable = False Then Exit Sub
	Dim oPDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	Dim oSketches As PlanarSketches = oPDef.Sketches
	Dim oDict As New Dictionary(Of String, List(Of PlanarSketch))
	Dim oType As String = "PlanarSketch"
	For Each oSketch As PlanarSketch In oSketches
		If oDict.Count = 0 Then
			oDict.Add(oType, New List(Of PlanarSketch) From {oSketch})
		Else
			If oDict.Item(oType).Contains(oSketch) = False Then
				oDict.Item(oType).Add(oSketch)
			End If
		End If
	Next
	If IsNothing(oDict) OrElse oDict.Count = 0 Then Exit Sub
	For Each oPair In oDict
		If oPair.Value.Count = 0 Then Continue For
		Dim oInt As Integer = 0
		For Each oSk In oPair.Value
			oInt = oInt + 1
			oSk.Name = oPair.Key & oInt
		Next
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

ppolcynBNVFN
Enthusiast
Enthusiast

Thanks for all the effort you put into this. I tried it out and wasn't able to achieve any results. Is there anything I need to modify before running?

0 Likes