<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Ilogic increment feature names in ipt in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-increment-feature-names-in-ipt/m-p/11813616#M26109</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12723095"&gt;@ppolcynBNVFN&lt;/a&gt;.&amp;nbsp; 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.&amp;nbsp; There is a built-in system for adding that number after the name, and we do not have access to that built-in system.&amp;nbsp; 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.&amp;nbsp; That is many layers of complication.&amp;nbsp; I created an iLogic rule that you can try out for renaming generic PartFeatures and PlanarSketches in a part.&amp;nbsp; 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.&amp;nbsp; 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.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Sub Main
	If ThisDoc.Document.DocumentType &amp;lt;&amp;gt; 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 &amp;amp; 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 &amp;amp; oInt
		Next
	Next
End Sub&lt;/LI-CODE&gt;
&lt;P&gt;If this solved your problem, or answered your question, please click &lt;SPAN&gt;&lt;STRONG&gt; ACCEPT SOLUTION &lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;BR /&gt;Or, if this helped you, please click (LIKE or KUDOS) &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2023 20:04:23 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2023-03-10T20:04:23Z</dc:date>
    <item>
      <title>Ilogic increment feature names in ipt</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-increment-feature-names-in-ipt/m-p/11812961#M26108</link>
      <description>&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Extrusion2&lt;/P&gt;&lt;P&gt;Sketch7&lt;/P&gt;&lt;P&gt;Hole3&lt;/P&gt;&lt;P&gt;Hole2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This rule would rename this list to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Extrusion1&lt;/P&gt;&lt;P&gt;Sketch1&lt;/P&gt;&lt;P&gt;Hole1&lt;/P&gt;&lt;P&gt;Hole2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:13:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-increment-feature-names-in-ipt/m-p/11812961#M26108</guid>
      <dc:creator>ppolcynBNVFN</dc:creator>
      <dc:date>2023-03-10T15:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Ilogic increment feature names in ipt</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-increment-feature-names-in-ipt/m-p/11813616#M26109</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12723095"&gt;@ppolcynBNVFN&lt;/a&gt;.&amp;nbsp; 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.&amp;nbsp; There is a built-in system for adding that number after the name, and we do not have access to that built-in system.&amp;nbsp; 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.&amp;nbsp; That is many layers of complication.&amp;nbsp; I created an iLogic rule that you can try out for renaming generic PartFeatures and PlanarSketches in a part.&amp;nbsp; 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.&amp;nbsp; 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.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Sub Main
	If ThisDoc.Document.DocumentType &amp;lt;&amp;gt; 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 &amp;amp; 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 &amp;amp; oInt
		Next
	Next
End Sub&lt;/LI-CODE&gt;
&lt;P&gt;If this solved your problem, or answered your question, please click &lt;SPAN&gt;&lt;STRONG&gt; ACCEPT SOLUTION &lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;BR /&gt;Or, if this helped you, please click (LIKE or KUDOS) &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 20:04:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-increment-feature-names-in-ipt/m-p/11813616#M26109</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-03-10T20:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Ilogic increment feature names in ipt</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-increment-feature-names-in-ipt/m-p/11817494#M26110</link>
      <description>&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 11:56:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-increment-feature-names-in-ipt/m-p/11817494#M26110</guid>
      <dc:creator>ppolcynBNVFN</dc:creator>
      <dc:date>2023-03-13T11:56:28Z</dc:date>
    </item>
  </channel>
</rss>

