- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Counting Work feature
hello,
I would like to know the number of features used in assemblies opened using inventor i-logic.
Types of features include work points, work axes, work planes, extrusions , etc.
There are many parts in an open assembly, and there are also sub-assemblies.
Is there any code that can tell how many different types of features are used?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @ysbaodnj,
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 ?
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @ysbaodnj,
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.
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)
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 ?
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Not sure what you will use this for, but I liked the challenge. Here is a scalable option:
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 < 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 = ": >>---------------------------"
Dim MarkerIndex As Integer = AllLogText.LastIndexOf(MarkerString) + MarkerString.Length+2
System.IO.File.WriteAllText(tempFileName, AllLogText.Substring(MarkerIndex))
Shell("notepad.exe " & 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 & " Feature Counts:")
For i = 1 To countedMap.Count
If countedMap.Value(countedMap.Name(i)) < 0 Then Continue For 'Exlcudes pre-built errors for hard call failures of non-existant objects
If countedMap.Value(countedMap.Name(i)) < 1 Then Continue For 'Excludes lines for 0 results
Logger.Trace(" " & countedMap.Name(i) & ": " & 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 & " 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 & " not setup in Function: ""GetOtherObjectCount""")
Return -1
End Function
Anything that is not a PartFeature, will need to be added to the "OtherObjectsToCount" list and manually programmed in the "GetOtherObjectCount" Function. I included 2D and 3D sketches in that function for examples. Part Features can be added by including the ObjectTypeEnum in the "FeatureTypesToCount" list.
The rule will display results in Logger and create a temp text file in the temp folder.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you for answer.
What I want to do is to know the total number of work features used in an assembly as shown in the picture below.
For example, 5 work axes and 7 work planes
I would like to know these information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you for answer.
What I want to do is to know the total number of work features used in an assembly as shown in the picture below.
For example, 5 work axes and 7 work planes
I would like to know these information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
It looks like you have multiple instances of the same part, so I am displaying total for all instances combined. Do you want that?
I have attached the updated rule as a text file.