VBA & Knurled Surfaces

VBA & Knurled Surfaces

isocam
Collaborator Collaborator
669 Views
3 Replies
Message 1 of 4

VBA & Knurled Surfaces

isocam
Collaborator
Collaborator

Can anybody help?

 

If I have created a revolved surface and placed a Knurled Surface pattern on that surface, is there any way of getting the diameter start point and end point of the knurled surface (in mm) using VBA?

 

Many thanks in advance!!!

 

IsoCAM

0 Likes
670 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni

Can you post an example part file that illustrates what you're trying to do?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 4

isocam
Collaborator
Collaborator

I have attached a simple ipt file (in a zip file) showing a "Knurled" surface. What I need to know is the Diameter of the Knurled surface and the start point & End point of the surface. So, for example, the diameter of the Knurled surface, in this example actually is 32.38 with a start point of 16.28 and an endpoint of 27.87

 

Can this be done by Inventors VBA?

 

Many thanks

 

IsoCAM

0 Likes
Message 4 of 4

ekinsb
Alumni
Alumni

Here's a small VBA program that does what you want.  I added some additional checks that aren't actually needed for the example you provided but will handle cases where the cylinder that has the knurling has some additional cuts and isn't a clean cylinder.

 

Public Sub GetKnurledInfo()
    ' Get the active part document.
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
   
    ' Query the attributes to see if there is a FaceColor
    ' attribute with the value "Metal-Steel (Knurled)"
    Dim attribSets As AttributeSetsEnumerator
    Set attribSets = partDoc.AttributeManager.FindAttributeSets( _
                        "com.autodesk.inventor.FaceAttributes", _
                        "FaceColor", "Metal-Steel (Knurled)")
                       
    ' Check to make sure any attribute sets were found.
    If attribSets.count = 0 Then
        MsgBox "The part does not contain any knurled faces."
        Exit Sub
    End If
   
    ' Iterate through the found attribute sets.
    Dim i As Integer
    For i = 1 To attribSets.count
        ' Get the face from the current attribute set.
        Dim knurledFace As face
        Set knurledFace = attribSets.Item(i).Parent.Parent
       
        ' Make sure the face is a cylinder.
        If knurledFace.SurfaceType = kCylinderSurface Then
            ' Get the diameter from the cylinder.
            Dim cyl As Cylinder
            Set cyl = knurledFace.Geometry
            Dim diameter As Double
            diameter = cyl.Radius * 2
           
            ' Get the extent of the knurl by getting the circular edges
            ' at each end of the cylinder and using their centers as
            ' the extents.
            Dim extent1 As Point
            Dim extent2 As Point
            Dim checkLoop As EdgeLoop
            For Each checkLoop In knurledFace.EdgeLoops
                If checkLoop.IsOuterEdgeLoop Then
                    ' Find a circle or arc on the edge.
                    Dim checkEdge As Edge
                    For Each checkEdge In checkLoop.Edges
                        If checkEdge.GeometryType = kCircleCurve Then
                            Dim checkCircle As Inventor.Circle
                            Set checkCircle = checkEdge.Geometry
                            If extent1 Is Nothing Then
                                Set extent1 = checkCircle.center
                            Else
                                Set extent2 = checkCircle.center
                            End If
                        ElseIf checkEdge.GeometryType = kCircularArcCurve Then
                            Dim checkArc As Inventor.Arc3d
                            Set checkArc = checkEdge.Geometry
                            If extent1 Is Nothing Then
                                Set extent1 = checkArc.center
                            Else
                                Set extent2 = checkArc.center
                            End If
                        End If
                    Next
                End If
            Next
           
            Dim uom As UnitsOfMeasure
            Set uom = partDoc.UnitsOfMeasure
            Dim result As String
            result = "Knurled Face:" & vbCrLf & "   Diameter: " & _
                      uom.GetStringFromValue(diameter, kDefaultDisplayLengthUnits) & _
                      vbCrLf & "   Point 1: " & ShowPoint(extent1, uom) & vbCrLf & _
                      "   Point 2: " & ShowPoint(extent2, uom)
            MsgBox result
            Debug.Print result
        End If
    Next
End Sub

Private Function ShowPoint(InPoint As Point, uom As UnitsOfMeasure) As String
    ShowPoint = uom.GetStringFromValue(InPoint.X, kDefaultDisplayLengthUnits) & _
                ", " & uom.GetStringFromValue(InPoint.Y, kDefaultDisplayLengthUnits) & _
                ", " & uom.GetStringFromValue(InPoint.Z, kDefaultDisplayLengthUnits)
End Function


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes