Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all , I have the below code from Jhoel special thanks to him , but I have two things pending ,
1- this code is counting holes and punches for assembly with part level , I wanted to be assembly with subassembly level then parts ,
2 - get the result's in table in the drawing.
"
Dim oAsm As AssemblyDocument = ThisDoc.Document Dim oHoles As New List(Of String) Dim oPunches As New List(Of String) Dim UoM As UnitsOfMeasure = oAsm.UnitsOfMeasure For Each oOcc As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject AndAlso oOcc.Definition.Document.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Dim oDoc As PartDocument = oOcc.Definition.Document Dim oCD As SheetMetalComponentDefinition = oDoc.ComponentDefinition If oCD.HasFlatPattern = False Then oCD.Unfold oCD.FlatPattern.ExitEdit oDoc.Close oAsm.Activate End If 'Add all holes (diameters) to a list Dim oFace As Face = oCD.FlatPattern.TopFace For Each oLoop As EdgeLoop In oFace.EdgeLoops 'Make sure the edgeloop is a circle If oLoop.IsOuterEdgeLoop = False AndAlso oLoop.Edges.Count = 1 _ AndAlso oLoop.Edges(1).GeometryType = CurveTypeEnum.kCircleCurve oHoles.Add(UoM.GetStringFromValue(oLoop.Edges(1).Geometry.Radius * 2, UoM.LengthUnits)) End If Next For Each oPunch As PunchToolFeature In oCD.Features.PunchToolFeatures For i = 1 To oPunch.PunchCenterPoints.Count oPunches.Add(System.IO.Path.GetFileNameWithoutExtension(oPunch.iFeatureTemplateDescriptor.LastKnownSourceFileName)) Next Next End If Next For Each oProp As Inventor.Property In oAsm.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}") If oProp.Name.StartsWith("Hole: ") Or oProp.Name.StartsWith("Punch: ") Then oProp.Delete Next 'Sort the list oHoles.Sort(Function(a, b) UoM.GetValueFromExpression(a, UoM.LengthUnits).CompareTo(UoM.GetValueFromExpression(b, UoM.LengthUnits))) 'Step through the list and create properties of diameter and count. Dim currCount As Integer = 0 For i = 0 To oHoles.Count - 1 If i > 0 AndAlso oHoles(i) <> oHoles(i - 1) iProperties.Value("Custom", "Hole: " & oHoles(i - 1)) = currCount MsgBox(oHoles(i - 1) & vbCrLf & "Count = " & currCount) currCount = 1 Else currCount += 1 End If If i = oHoles.Count - 1 MsgBox(oHoles(i) & vbCrLf & "Count = " & currCount) iProperties.Value("Custom", "Hole: " & oHoles(i)) = currCount End If Next oPunches.Sort(Function(a, b) a.CompareTo(b)) currCount = 0 For i = 0 To oPunches.Count - 1 If i > 0 AndAlso oPunches(i) <> oPunches(i - 1) iProperties.Value("Custom", "Punch: " & oPunches(i - 1)) = currCount MsgBox(oPunches(i - 1) & vbCrLf & "Count = " & currCount) currCount = 1 Else currCount += 1 End If If i = oPunches.Count - 1 MsgBox(oPunches(i) & vbCrLf & "Count = " & currCount) iProperties.Value("Custom", "Punch: " & oPunches(i)) = currCount End If Next oAsm.Update
"
Thanks.
Solved! Go to Solution.