Option Explicit On Sub Main() Dim body As SurfaceBody Dim oFaces As Faces Dim oFace As Face body = ThisDoc.Document.ComponentDefinition.SurfaceBodies(1) Dim faceCount As Integer = body.Faces.Count For faceIndex = 1 To faceCount ' Every time we add a feature, the body is recomputed. Have to get the body and new faces each time. body = ThisDoc.Document.ComponentDefinition.SurfaceBodies(1) oFaces = body.Faces Dim checkFaceCount = oFaces.Count If checkFaceCount <> faceCount Then Logger.Error("ERROR: face count changed from {0} to {1}", faceCount, checkFaceCount) End If If faceIndex <= checkFaceCount Then oFace = oFaces(faceIndex) ThreadBuild(oFace) End If Next End Sub Sub ThreadBuild(oFace as Face) Logger.Debug(oFace.SurfaceType.ToString) Dim oTFs As ThreadFeatures = ThisDoc.Document.ComponentDefinition.Features.ThreadFeatures Dim oTF As ThreadFeature Dim oEdge As Edge Dim oThreadInfo As ThreadInfo Dim sThreadType As String If oFace.SurfaceType = kCylinderSurface ' Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)) If oFace.ThreadInfos Is Nothing sThreadType = GetThreadTypeFromRadius(oFace.Geometry.Radius) If sThreadType<>String.Empty oEdge = oFace.Edges(1) oThreadInfo = oTFs.CreateStandardThreadInfo(True, True, "ISO Metric Profile", sThreadType, "6H") oTF = oTFs.Add(oFace, oEdge, oThreadInfo, False, True) End If End If End If End Sub Function GetThreadTypeFromRadius(dRadius As Double) As String Dim sThreadType As String logger.debug(Round(dRadius, 3)) Select Round(dRadius, 3) Case 0.078 sThreadType = "M2x0.4" Case 0.123 sThreadType = "M3x0.5" Case 0.162 sThreadType = "M4x0.7" Case 0.207 sThreadType = "M5x0.8" Case 0.246 sThreadType = "M6x1" Case 0.354 sThreadType = "M8x1.25" Case 0.419 sThreadType = "M10x1.5" Case 0.505 sThreadType = "M12x1.75" Case 0.592 sThreadType = "M14x2" Case 0.692 sThreadType = "M16x2" ' Case Else ' Nothing End Select Return sThreadType End Function