<?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: Counting Work feature in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12096685#M155158</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10139375"&gt;@ysbaodnj&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure if you need to change the strings for Workfeatures, sketches, ... for localization, but I adjusted the rule to only export the totals.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like you have multiple instances of the same part, so I am displaying total for all instances combined.&amp;nbsp; Do you want that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the updated rule as a text file.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2023 13:42:49 GMT</pubDate>
    <dc:creator>J-Camper</dc:creator>
    <dc:date>2023-07-12T13:42:49Z</dc:date>
    <item>
      <title>Counting Work feature</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12092977#M155016</link>
      <description>&lt;P&gt;hello,&lt;BR /&gt;I would like to know the number of features used in assemblies opened using inventor i-logic.&lt;BR /&gt;Types of features include work points, work axes, work planes, extrusions , etc.&lt;BR /&gt;There are many parts in an open assembly, and there are also sub-assemblies.&lt;/P&gt;&lt;P&gt;Is there any code that can tell how many different types of features are used?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 07:28:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12092977#M155016</guid>
      <dc:creator>ysbaodnj</dc:creator>
      <dc:date>2023-07-11T07:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Work feature</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12093022#M155019</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10139375"&gt;@ysbaodnj&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just so we can understand better what you are asking, what do you want as an output ? A number representing the total feature count ? What would be those features? Does the origins (planes, center point, axis X Y Z) have to be included ? Is it only in part, or are there some assemblies that also containes features? Do we count them ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;FINET L.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 07:51:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12093022#M155019</guid>
      <dc:creator>FINET_Laurent</dc:creator>
      <dc:date>2023-07-11T07:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Work feature</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12093037#M155020</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10139375"&gt;@ysbaodnj&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a small code that goes into each single parts contained in the assembly and add up all the part features, and also user created work planes, work axes and work points.&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim Doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim AssyCompDef As Inventor.AssemblyComponentDefinition = Doc.ComponentDefinition

Dim Counter As Integer = 0

For Each Occ As Inventor.ComponentOccurrence In AssyCompDef.Occurrences.AllLeafOccurrences
	Dim pDoc As Inventor.PartDocument = Occ.ReferencedDocumentDescriptor.ReferencedDocument
	Dim PartCompDef As Inventor.PartComponentDefinition = pDoc.ComponentDefinition
	
	Dim f As Integer = PartCompDef.Features.Count
	Counter += f
	
	Dim wp As Integer = PartCompDef.WorkPlanes.Count - 3
	Dim wa As Integer = PartCompDef.WorkAxes.Count - 3
	Dim p As Integer = PartCompDef.WorkPoints.Count - 1
	
	Counter = Counter + wp + wa + p
	
Next

MsgBox(Counter)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The downside is that it doesn't add up the work planes, points, and axes created in an sub assembly. Only it's parts. Do we have to go further ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;FINET L.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 07:58:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12093037#M155020</guid>
      <dc:creator>FINET_Laurent</dc:creator>
      <dc:date>2023-07-11T07:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Work feature</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12094636#M155084</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10139375"&gt;@ysbaodnj&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure what you will use this for, but I liked the challenge.&amp;nbsp; Here is a scalable option:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main
	
	Dim aDoc As AssemblyDocument = TryCast(ThisApplication.ActiveDocument, AssemblyDocument)
	If IsNothing(aDoc) Then Logger.Debug("Not Run In Assembly Document") : Exit Sub
	
	iLogicVb.Automation.LogControl.Level = LogLevel.Trace
	
	Dim FeatureTypesToCount As New List(Of ObjectTypeEnum)
	FeatureTypesToCount.AddRange({ObjectTypeEnum.kExtrudeFeatureObject, ObjectTypeEnum.kSweepFeatureObject, ObjectTypeEnum.kCombineFeatureObject })
	
	Dim WorkObjectsToCount As New List(Of String)
	WorkObjectsToCount.AddRange({"WorkPoint", "WorkAxis", "WorkPlane", "WorkSurface", "UCS" })
	
	Dim OtherObjectsToCount As New List(Of String)
	OtherObjectsToCount.AddRange({"Sketch", "Sketch3D" }) 	'Anything added needs manual programming in Function: "GetOtherObjectCount"
	
	Call CountAssemblyFeatures(aDoc, WorkObjectsToCount, OtherObjectsToCount, FeatureTypesToCount)
	
	For Each refDoc As Document In aDoc.ReferencedDocuments
		If aDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(refDoc).Count &amp;lt; 1 Then Continue For
		
		If refDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
			Call CountAssemblyFeatures(refDoc, WorkObjectsToCount, OtherObjectsToCount, FeatureTypesToCount)
		Else If refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
			Call CountPartFeatures(refDoc, WorkObjectsToCount, OtherObjectsToCount, FeatureTypesToCount)
		End If
	Next
	
	Dim tempFileName As String = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), ".txt")
	iLogicVb.Automation.LogControl.SaveLogAs(tempFileName)
	
	Dim AllLogText As String = System.IO.File.ReadAllText(tempFileName)
	Dim MarkerString As String = ": &amp;gt;&amp;gt;---------------------------"
	Dim MarkerIndex As Integer = AllLogText.LastIndexOf(MarkerString) + MarkerString.Length+2
	System.IO.File.WriteAllText(tempFileName, AllLogText.Substring(MarkerIndex))
	
	Shell("notepad.exe " &amp;amp; tempFileName, vbNormalFocus)
	
End Sub

Sub CountPartFeatures(pDoc As PartDocument, WorkObjectsToCount As List(Of String), OtherObjectsToCount As List(Of String), FeatureTypesToCount As List(Of ObjectTypeEnum))
	Dim countingMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	
	For Each s As String In WorkObjectsToCount
		countingMap.Add(s, GetWorkObjectCount(s, pDoc))
	Next
	
	For Each s As String In OtherObjectsToCount
		countingMap.Add(s, GetOtherObjectCount(s, pDoc))
	Next
	
	For Each ObjTypeEnum As ObjectTypeEnum In FeatureTypesToCount
		Dim StrippedName As String = Mid(CType(ObjTypeEnum, ObjectTypeEnum).ToString, 2, CType(ObjTypeEnum, ObjectTypeEnum).ToString.Length-7)
		countingMap.Add(StrippedName, pDoc.ComponentDefinition.Features.OfType(Of PartFeature).Where(Function(d) d.Type = ObjTypeEnum).Count)
	Next
	
	Call ExportResults(pDoc.DisplayName, countingMap)
End Sub

Sub CountAssemblyFeatures(aDoc As AssemblyDocument, WorkObjectsToCount As List(Of String), OtherObjectsToCount As List(Of String), FeatureTypesToCount As List(Of ObjectTypeEnum))
	Dim countingMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	
	For Each s As String In WorkObjectsToCount
		countingMap.Add(s, GetWorkObjectCount(s, aDoc))
	Next
	
	For Each s As String In OtherObjectsToCount
		countingMap.Add(s, GetOtherObjectCount(s, aDoc))
	Next
	
	For Each ObjTypeEnum As ObjectTypeEnum In FeatureTypesToCount
		Dim StrippedName As String = Mid(CType(ObjTypeEnum, ObjectTypeEnum).ToString, 2, CType(ObjTypeEnum, ObjectTypeEnum).ToString.Length-7)
		countingMap.Add(StrippedName, aDoc.ComponentDefinition.Features.OfType(Of PartFeature).Where(Function(d) d.Type = ObjTypeEnum).Count)
	Next
	
	Call ExportResults(aDoc.DisplayName, countingMap)
End Sub

Sub ExportResults(DocDisplayName As String, countedMap As NameValueMap)
	
	Logger.Trace(DocDisplayName &amp;amp; " Feature Counts:")
	
	For i = 1 To countedMap.Count
		If countedMap.Value(countedMap.Name(i)) &amp;lt; 0 Then Continue For 'Exlcudes pre-built errors for hard call failures of non-existant objects
		If countedMap.Value(countedMap.Name(i)) &amp;lt; 1 Then Continue For 'Excludes lines for 0 results
		
		Logger.Trace("    " &amp;amp; countedMap.Name(i) &amp;amp; ": " &amp;amp; countedMap.Value(countedMap.Name(i)).ToString)
		
	Next
	
End Sub

Function GetWorkObjectCount(ObjectName As String, Doc As Document) As Integer
	
	Select Case ObjectName
		
	Case "WorkPoint"
		Return Doc.ComponentDefinition.WorkPoints.Count-1
	Case "WorkAxis"
		Return Doc.ComponentDefinition.WorkAxes.Count-3
	Case "WorkPlane"
		Return Doc.ComponentDefinition.WorkPlanes.Count-3
	Case "WorkSurface"
		Try
			Return Doc.ComponentDefinition.WorkSurfaces.Count
		Catch
			Return -1 'WorkSurfaceObject Doesn't exist for assemblies
		End Try
	Case "UCS"
		Return Doc.ComponentDefinition.UserCoordinateSystems.Count
	End Select
	
	Logger.Debug(ObjectName &amp;amp; " not setup in Function: ""GetWorkObjectCount""")
	Return -1
	
End Function

Function GetOtherObjectCount(ObjectName As String, Doc As Document) As Integer
	
	Select Case ObjectName
		
	Case "Sketch"
		Return Doc.ComponentDefinition.Sketches.Count
	Case "Sketch3D"
		Try
			Return Doc.ComponentDefinition.Sketches3D.Count
		Catch
			Return -1 'Sketch3DObject Doesn't exist for assemblies
		End Try
	End Select
	
	Logger.Debug(ObjectName &amp;amp; " not setup in Function: ""GetOtherObjectCount""")
	Return -1
	
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anything that is not a PartFeature, will need to be added to the "OtherObjectsToCount" list and manually programmed in the "GetOtherObjectCount" Function.&amp;nbsp; I included 2D and 3D sketches in that function for examples.&amp;nbsp; Part Features can be added by including the ObjectTypeEnum in the "FeatureTypesToCount" list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The rule will display results in Logger and create a temp text file in the temp folder.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 19:07:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12094636#M155084</guid>
      <dc:creator>J-Camper</dc:creator>
      <dc:date>2023-07-11T19:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Work feature</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12095293#M155100</link>
      <description>&lt;P&gt;Thank you for answer.&lt;/P&gt;&lt;P&gt;What I want to do is to know the total number of work features used in an assembly as shown in the picture below.&lt;BR /&gt;For example, 5 work axes and 7 work planes&lt;BR /&gt;I would like to know these information.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ysbaodnj_0-1689125123742.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1239251iCFE8AB1B99F241C1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ysbaodnj_0-1689125123742.png" alt="ysbaodnj_0-1689125123742.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 01:25:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12095293#M155100</guid>
      <dc:creator>ysbaodnj</dc:creator>
      <dc:date>2023-07-12T01:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Work feature</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12095547#M155103</link>
      <description>&lt;P&gt;Thank you for answer.&lt;/P&gt;&lt;P&gt;What I want to do is to know the total number of work features used in an assembly as shown in the picture below.&lt;BR /&gt;For example, 5 work axes and 7 work planes&lt;BR /&gt;I would like to know these information.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ysbaodnj_0-1689135771264.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1239297iD5F366957DA7E6BC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ysbaodnj_0-1689135771264.png" alt="ysbaodnj_0-1689135771264.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 04:22:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12095547#M155103</guid>
      <dc:creator>ysbaodnj</dc:creator>
      <dc:date>2023-07-12T04:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Work feature</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12096685#M155158</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10139375"&gt;@ysbaodnj&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure if you need to change the strings for Workfeatures, sketches, ... for localization, but I adjusted the rule to only export the totals.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like you have multiple instances of the same part, so I am displaying total for all instances combined.&amp;nbsp; Do you want that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the updated rule as a text file.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 13:42:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/counting-work-feature/m-p/12096685#M155158</guid>
      <dc:creator>J-Camper</dc:creator>
      <dc:date>2023-07-12T13:42:49Z</dc:date>
    </item>
  </channel>
</rss>

