Axial alignment of holes

Axial alignment of holes

GeorgK
Advisor Advisor
4,905 Views
42 Replies
Message 1 of 43

Axial alignment of holes

GeorgK
Advisor
Advisor

Hello together,

 

is there a way to calculate the axial alignment of holes to see if they fit?

 

Alignment.jpg

 

Thank you very much

 

Georg

0 Likes
4,906 Views
42 Replies
Replies (42)
Message 41 of 43

Anonymous
Not applicable

 I am currently working on a similar project. but I can't get the hole size checker to work hole alignment seem to work great and show in subfolder aligned and misaligned on side but there is nothing that says that hole sizes are with in spec. please help 

SUB MAIN()
        Dim m_Inventor As Inventor.Application
        m_Inventor = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

        Dim oDoc As AssemblyDocument
        oDoc = m_Inventor.ActiveDocument

        Dim oCompdef As AssemblyComponentDefinition
        oCompdef = oDoc.ComponentDefinition

        Dim oBody1 As SurfaceBody
        Dim oBody2 As SurfaceBody

        oBody1 = m_Inventor.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select first body")
        oBody2 = m_Inventor.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select a body to compare")

        Dim oFace As Face
        Dim oAxis As WorkAxis

        For Each oFace In oBody1.Faces

            If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
                oAxis = oCompdef.WorkAxes.AddFixed(oFace.Geometry.BasePoint, oFace.Geometry.AxisVector)

                Dim comparedFace As Face
                comparedFace = CompareFaces(oAxis, oBody2, oCompdef)

                If comparedFace Is Nothing Then
                    oAxis.Name = oAxis.Name & "_misaligned"
                Else
                    Dim oHoleFeature1 As HoleFeature
                    oHoleFeature1 = oFace.CreatedByFeature

                    Dim dia1 As Double
                    dia1 = oHoleFeature1.HoleDiameter.Value
                    dia1 = dia1 * 10 'Converting cm to mm

                    Dim oHoleFeature2 As HoleFeature
                    oHoleFeature2 = comparedFace.CreatedByFeature

                    Dim dia2 As Double
                    dia2 = oHoleFeature2.HoleDiameter.Value
                    dia2 = dia2 * 10 'Converting cm to mm

                    If Math.Round(dia1, 4) = Math.Round(dia2, 4) Then
                        Debug.Print("Hole diameter of plate 1 = " & dia1 & " compared with Hole diameter of plate 2 = " & dia2 & " => OK - Default")
                    ElseIf Math.Round(dia1, 4) >= Math.Round(dia2, 4) And Math.Round(dia1, 4) <= Math.Round(dia2, 4) + 0.5 Then
                        Debug.Print("Hole diameter of plate 1 = " & dia1 & " compared with Hole diameter of plate 2 = " & dia2 & " => OK - Special Type")
                    Else
                        Debug.Print("Hole diameter of plate 1 = " & dia1 & " compared with Hole diameter of plate 2 = " & dia2 & " => Not OK")
                    End If

                End If

            End If

        Next

        Dim oPane As BrowserPane
        oPane = oDoc.BrowserPanes.ActivePane

        Dim alignedNodes As ObjectCollection
        alignedNodes = m_Inventor.TransientObjects.CreateObjectCollection

        Dim misAlignedNodes As ObjectCollection
        misAlignedNodes = m_Inventor.TransientObjects.CreateObjectCollection

        For i = 4 To oCompdef.WorkAxes.Count
            oAxis = oCompdef.WorkAxes.Item(i)
            Dim misaligned As Boolean
            misaligned = EndsWith(oAxis.Name, "misaligned")

            Dim oNode As BrowserNode

            If misaligned = True Then
                oNode = oPane.GetBrowserNodeFromObject(oAxis)
                misAlignedNodes.Add(oNode)
            Else
                oNode = oPane.GetBrowserNodeFromObject(oAxis)
                alignedNodes.Add(oNode)
            End If

        Next

        Dim alignedAxes As BrowserFolder
        alignedAxes = oPane.AddBrowserFolder("Aligned Axes", alignedNodes)

        Dim misAlignedAxes As BrowserFolder
        misAlignedAxes = oPane.AddBrowserFolder("MisAligned Axes", misAlignedNodes)

    End Sub

    Public Function CompareFaces(ByVal oAxis1 As WorkAxis, ByVal oBody As SurfaceBody, ByVal compDef As AssemblyComponentDefinition) As Face
        For Each oFace As Face In oBody.Faces
            If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
                Dim oAxis As WorkAxis

                oAxis = compDef.WorkAxes.AddFixed(oFace.Geometry.BasePoint, oFace.Geometry.AxisVector)

                If oAxis.Line.IsColinearTo(oAxis1.Line) Then
                    oAxis.Delete()
                    Return oFace
                    Exit Function
                Else
                    oAxis.Delete()
                End If
            End If
        Next
        Return Nothing
    End Function

    Public Function EndsWith(str As String, ending As String) As Boolean
        Dim endingLen As Integer
        endingLen = Len(ending)
        EndsWith = (Microsoft.VisualBasic.Right(Trim(UCase(str)), endingLen) = UCase(ending))
    End Function

 

0 Likes
Message 42 of 43

graypointsoftware
Contributor
Contributor

@GeorgK

 

I have just released my new app (Hole Check Lite) that does exactly this! Check it out on the App Store and let me know what you think.

 

https://apps.autodesk.com/INVNTOR/en/Detail/Index?id=1768260766574491015 

0 Likes
Message 43 of 43

gopinathmY575P
Advocate
Advocate

Hi sir, This code is working fine. But i need to check for an assembly which has multiple plate,pin,e.t.c?

is it possible to check like as interference checking

0 Likes