Autodesk Inventor VBA: detect auto-mitered corners? - Stack Overflow

admin2025-04-16  8

I'm trying to write a sub to essentially check if more than 1 flange was added during the addition of a 'flange feature' to a sheet metal part and if so, were there any that shared a vertex. Essentially, I'm looking for anywhere the corners come together in a nice seam as this indicates that part needs to be welded. I already have a sub that checks for the 'corner seam' feature but when you add 2 flanges side-by-side in the same feature, Inventor automatically adds the same geometry a corner seam would add, but without the feature. I came up with code to look for non-planer or cylindrical faces on the flange since the bend faces get twisted, but the same happens when the base flange isn't square. Is there any way to access the auto-mitered corner feature or... see if the sketches of the flanges share a vertex? Here's the code I currently have working, though not sure this helps at all. Every attempt to look at coinciding vertices just results in too many compile errors of mismatch types and properties that don't exist. Here's the closest I think I've come, but again just a ton of compile errors.

Sub CheckFlangeFeature()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheetMetalCompDef As SheetMetalComponentDefinition
    Set oSheetMetalCompDef = oDoc.ComponentDefinition
    
    Dim oFeatures As SheetMetalFeatures
    Set oFeatures = oSheetMetalCompDef.Features
    
    ' Access the FlangeFeatures collection
    Dim oFlangeFeatures As Object
    Set oFlangeFeatures = oFeatures.FlangeFeatures
    
    Dim oFlangeFeature As Object
    Dim i As Integer
    
    For i = 1 To oFlangeFeatures.Count
        Set oFlangeFeature = oFlangeFeatures.Item(i)
        
        ' Check if the flange feature added more than one flange
        If oFlangeFeature.Faces.Count > 9 Then
            Debug.Print "Flange feature " & oFlangeFeature.Name & " added more than one flange."
            
            ' Check if the sketches of the flanges share a common vertex
            If FlangesShareCommonVertex(oFlangeFeature) Then
                Debug.Print "Flanges in feature " & oFlangeFeature.Name & " share a common vertex."
            End If
        End If
    Next i
End Sub

Function FlangesShareCommonVertex(oFlangeFeature As Object) As Boolean
    Dim oSketch1 As PlanarSketch
    Dim oSketch2 As PlanarSketch
    Dim oVertex1 As SketchPoint
    Dim oVertex2 As SketchPoint
    
    ' Get the sketches of the flanges
    Set oSketch1 = oFlangeFeature.Definition.Sketches.Item(1)
    Set oSketch2 = oFlangeFeature.Definition.Sketches.Item(2)
    
    For Each oVertex1 In oSketch1.SketchPoints
        For Each oVertex2 In oSketch2.SketchPoints
            If oVertex1.Geometry.IsEqualTo(oVertex2.Geometry) Then
                FlangesShareCommonVertex = True
                Exit Function
            End If
        Next oVertex2
    Next oVertex1
    
    FlangesShareCommonVertex = False
End Function
转载请注明原文地址:http://anycun.com/QandA/1744810634a87939.html