Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
Hi Tatiana,
I added iLogic rules to sample part files you provided.
Case 1. Hole feature pattern
Attached file hole_pattern_iLOGIC.ipt contains the demo iLogic rule for hole feature rectangular pattern.
' Calc Holes in HoleFeature Pattern 'assume part document Dim oDoc As PartDocument = ThisDoc.Document 'Set oDoc = ThisApplication.ActiveDocument Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition 'assume rectangular pattern Dim oRectPatterns As RectangularPatternFeatures = oDef.Features.RectangularPatternFeatures Dim N As Integer = 0 'counter For Each oRP As RectangularPatternFeature In oRectPatterns 'consider only hole patterns If Not (TypeOf oRP.ParentFeatures.Item(1) Is HoleFeature) Then Continue For For Each oFPE As FeaturePatternElement In oRP.PatternElements If Not oFPE.Suppressed Then N += 1 Next Next MsgBox ("The number of holes in the current part is: " & N)
Circular patterns could be processed in the samilar way.
Refer Inventor API Help for CircularPatternFeature object description.
Case 2. Hole features created “from sketch”.
See iLogic rule in the attached file extrude_point_pattern_hole_iLOGIC.ipt
' CalcHolesFromSketch Dim oDoc As PartDocument = ThisDoc.Document Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition Dim oHoles As HoleFeatures = oDef.Features.HoleFeatures Dim N As Integer = 0 'counter For Each oH As HoleFeature In oHoles If oH.Suppressed Then Continue For If oH.PlacementType = HolePlacementTypeEnum.kSketchPlacementType Then N += oH.HoleCenterPoints.Count End If Next Beep MsgBox ("The number of holes in the current part is: " & N)
Hope you could modify these iLogic code samples to suit your needs.
Cheers,
Hi Vladimir
Thank you very much for your help.
But I have another question, hope - the last
How to count the number of holes in the assembly file?
Files for an example - I added
Whether this is possible in general, counting the holes different ways in a single file?
Best regards
Tatiana
Hi Tatiana,
I've attached assembly with iLogic rules that could help you to start.
The first rule Iterates through all leaf occurrences collection.
The second rule Iterates through all referenced documents collection.
The last should be more efficient if your assembly includes a lot of copies of parts with holes.
(I did not test this idea though).
Both Main methods call the same function GetHolesQty which returns the number of holes in the specified part component definition.
Please note that this function cannot work with nested feature patterns.
Approach 1. Iterates through all leaf occurrences collection.
Sub Main() Dim oAsmDoc As AssemblyDocument = ThisDoc.Document Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition Dim N As Integer = 0 'holes counter For Each oOcc As ComponentOccurrence In oAsmDef.Occurrences.AllLeafOccurrences If Not oOcc.Suppressed Then If oOcc.DefinitionDocumentType = kPartDocumentObject Then Dim oDef As PartComponentDefinition = oOcc.Definition N += GetHolesQty(oDef) End If End If Next Beep MsgBox ("The number of holes in the current part is: " & N) End Sub
Approach 2. Iterates through all referenced documents collection.
Sub Main() Dim oAsmDoc As AssemblyDocument = ThisDoc.Document Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition Dim oOccs As ComponentOccurrences = oAsmDef.Occurrences Dim N As Integer = 0 'holes counter For Each oDoc As Inventor.Document In oAsmDoc.AllReferencedDocuments If TypeOf oDoc Is PartDocument Then Dim m As Integer = GetHolesQty(oDoc.ComponentDefinition) N = N + m * oOccs.AllReferencedOccurrences(oDoc).Count End If Next Beep MsgBox ("The number of holes in the current part is: " & N) End Sub
'''Calculates holes in the part document '''Be careful: nested patterns are not analyzed! Function GetHolesQty(ByVal oDef As PartComponentDefinition) As Integer Dim N As Integer = 0 'counter Dim oHoles As HoleFeatures = oDef.Features.HoleFeatures For Each oH As HoleFeature In oHoles If Not oH.Suppressed Then N += oH.HoleCenterPoints.Count End If Next 'have we any rectangular patterns ? Dim oRectPatterns As RectangularPatternFeatures oRectPatterns = oDef.Features.RectangularPatternFeatures For Each oRPF As RectangularPatternFeature In oRectPatterns Dim m As Integer = 0 If Not oRPF.Suppressed Then If (TypeOf oRPF.ParentFeatures.Item(1) Is HoleFeature) Then Dim oH As HoleFeature = oRPF.ParentFeatures.Item(1) If Not oH.Suppressed Then For Each oFPE As FeaturePatternElement In oRPF.PatternElements If Not oFPE.Suppressed Then m += 1 Next End If End If N += m - 1 Else N += m End If Next 'have we any circular patterns ? Dim oCircPatterns As CircularPatternFeatures oCircPatterns = oDef.Features.CircularPatternFeatures For Each oCPF As CircularPatternFeature In oCircPatterns Dim m As Integer = 0 If Not oCPF.Suppressed Then If (TypeOf oCPF.ParentFeatures.Item(1) Is HoleFeature) Then Dim oH As HoleFeature = oCPF.ParentFeatures.Item(1) If Not oH.Suppressed Then For Each oFPE As FeaturePatternElement In oCPF.PatternElements If Not oFPE.Suppressed Then m += 1 Next End If End If N += m - 1 Else N += m End If Next Return N End Function
Cheers,
Dear Vladimir
Thank you for your help
I really appreciate it
But I have another question
In the assembly file I want not only the number of holes bur also the diameter of the holes.
for example:
12 holes - diameter 5 mm
5 hole - diameter 7 mm
Which functions is necessary for this purpose?
Best regards
Tatiana
Hi Tatiana,
look at the HoleFeature ptoperties - HoleDiameter, HoleType, ExtendedName, etc.
HoleFeature.HoleDiameter property returns the model parameter controlling the diameter of the hole.
HoleDiamener.Expression gives diameter in the string format, e.g. "6 mm".
HoleDiamener.Value gives the same diameter in the base length units (cm) - 6.
The following DevBlog post could help you to discover object model
http://adndevblog.typepad.com/manufacturing/2013/10/discover-object-model.html
Cheers,