Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
ekinsb
in reply to: nmunro

That's actually expected because the code is getting the mesh being used for the display of the body.  For a transient body, there isn't a display mesh.  Instead you can calculate a new mesh.  Theres a CalculateFacets method that can be used instead, but when I was testing it, it's failing to, which is a bug.  However, there is also a CalculateFacetsWithOptions method and that is working.  Here's the modified version of the function.

 

Public Function TightRangeBox(Body As Inventor.SurfaceBody) As Inventor.Box
    ' Calculate a new mesh.
    Dim vertexCount As Long
    Dim facetCount As Long
    Dim vertexCoords() As Double
    Dim normalVectors() As Double
    Dim vertexIndices() As Long
    Dim options As NameValueMap
    Set options = ThisApplication.TransientObjects.CreateNameValueMap
    Call Body.CalculateFacetsWithOptions(0.005, options, vertexCount, facetCount, vertexCoords, normalVectors, vertexIndices)
    'Call Body.CalculateFacets(0.005, vertexCount, facetCount, vertexCoords, normalVectors, vertexIndices)
    
    ' Loop through the vertices and build up the range box.
    Dim minX As Double
    Dim maxX As Double
    Dim minY As Double
    Dim maxY As Double
    Dim minZ As Double
    Dim maxZ As Double
    minX = vertexCoords(0)
    maxX = vertexCoords(0)
    minY = vertexCoords(1)
    maxY = vertexCoords(1)
    minZ = vertexCoords(2)
    maxZ = vertexCoords(2)
    Dim i As Integer
    For i = 1 To vertexCount - 1
        If vertexCoords(i * 3) < minX Then
            minX = vertexCoords(i * 3)
        End If
        
        If vertexCoords(i * 3) > maxX Then
            maxX = vertexCoords(i * 3)
        End If
    
        If vertexCoords(i * 3 + 1) < minY Then
            minY = vertexCoords(i * 3 + 1)
        End If
        
        If vertexCoords(i * 3 + 1) > maxY Then
            maxY = vertexCoords(i * 3 + 1)
        End If
    
        If vertexCoords(i * 3 + 2) < minZ Then
            minZ = vertexCoords(i * 3 + 2)
        End If
        
        If vertexCoords(i * 3 + 2) > maxZ Then
            maxZ = vertexCoords(i * 3 + 2)
        End If
    Next
    
    Dim newBox As Box
    Set newBox = ThisApplication.TransientGeometry.CreateBox()
    newBox.MinPoint = ThisApplication.TransientGeometry.CreatePoint(minX, minY, minZ)
    newBox.MaxPoint = ThisApplication.TransientGeometry.CreatePoint(maxX, maxY, maxZ)
    
    Set TightRangeBox = newBox
End Function

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