Axial alignment of holes

Axial alignment of holes

GeorgK
Advisor Advisor
4,837 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,838 Views
42 Replies
Replies (42)
Message 21 of 43

GeorgK
Advisor
Advisor

@dg2405 Yes there are screws and pins in the holes. That would be the next step to check 🙂

0 Likes
Message 22 of 43

^_^clovis^_^
Advocate
Advocate

Wouldn't it be easier to derive a sketch with the hole position within each part?

0 Likes
Message 23 of 43

GeorgK
Advisor
Advisor

To compare the axis and the holes one after the other is the best way. I do not like to modify the parts.

0 Likes
Message 24 of 43

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK,

 

You mean, need to delete WorkAxis?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 25 of 43

^_^clovis^_^
Advocate
Advocate

what about 3D substract a part with the other one? . Is something stays over it means parts are not equal.

 

0 Likes
Message 26 of 43

GeorgK
Advisor
Advisor

Hi @chandra.shekar.g,

 

your code for checking all holes is really a time saver. The axis are very good to see the alignment. If the holes are in red or green and with a number with the clientgraphis this would improve the process to find it.

 

Public Sub SetFaceColor()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    ' Check to see if the client graphics already exist and delete them if they do.
    On Error Resume Next
    Dim graphics As ClientGraphics
    Set graphics = partDoc.ComponentDefinition.ClientGraphicsCollection.Item("ColorTest")
    If Err.Number = 0 Then
        graphics.Delete
        ThisApplication.ActiveView.Update
        Exit Sub
    End If
    On Error GoTo 0
    
    Dim selectedFace As face
    Set selectedFace = ThisApplication.CommandManager.Pick(kPartFaceFilter, "Select a face")
            
    ' They don't exist so create them.
    Set graphics = partDoc.ComponentDefinition.ClientGraphicsCollection.Add("ColorTest")
    Dim node As GraphicsNode
    Set node = graphics.AddNode(1)
    
    ' Create surface graphics using the selected face.
    Dim surfGraphics As SurfaceGraphics
    Set surfGraphics = node.AddSurfaceGraphics(selectedFace)
    
    ' Set the priority so that it will display on top of the real face.
    surfGraphics.DepthPriority = 3
    
    ' Define the color using rgb values.
    surfGraphics.Color = ThisApplication.TransientObjects.CreateColor(255, 10, 10, 1)
    
    ' Refresh the view.
    ThisApplication.ActiveView.Update
End Sub

 

http://modthemachine.typepad.com/my_weblog/2012/03/clientgraphics-text-on-each-planar-face.html

http://modthemachine.typepad.com/my_weblog/2012/03/surfacegraphics-select-primitives.html

 

 

Holes_Alignment.png

 

At the end there should be a table with all aligned holes. Is it possible to find holes which are not alignet in a radius from 1mm to other holes?

 

 The table could be a text-file or ClientGraphicsText.

 

 

Public Sub ClientGraphicsText()
    ' Set a reference to the document.  This will work with
    ' either a part or assembly document.
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

    ' Set a reference to the component definition.
    Dim oCompDef As ComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition

    ' Attempt to get the existing client graphics object.  If it exists
    ' delete it so the rest of the code can continue as if it never existed.
    Dim oClientGraphics As ClientGraphics
    On Error Resume Next
    Set oClientGraphics = oCompDef.ClientGraphicsCollection.Item("Text Test")
    If Err.Number = 0 Then
        oClientGraphics.Delete
    End If
    On Error GoTo 0
    ThisApplication.ActiveView.Update

    ' Create a new ClientGraphics object.
    Set oClientGraphics = oCompDef.ClientGraphicsCollection.Add("Text Test")

    ' Create a graphics node.
    Dim oNode As GraphicsNode
    Set oNode = oClientGraphics.AddNode(1)

    ' Create text graphics.
    Dim oTextGraphics As TextGraphics
    Set oTextGraphics = oNode.AddTextGraphics

    ' Set the properties of the text.
    oTextGraphics.Text = "This is the sample text. 123"
    oTextGraphics.Anchor = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)
    oTextGraphics.Bold = True
    oTextGraphics.Font = "Arial"
    oTextGraphics.FontSize = 40
    oTextGraphics.HorizontalAlignment = kAlignTextLeft
    oTextGraphics.Italic = True
    Call oTextGraphics.PutTextColor(0, 255, 0)
    oTextGraphics.VerticalAlignment = kAlignTextMiddle

    ' Update the view to see the text.
    ThisApplication.ActiveView.Update
End Sub

 

If System.IO.File.Exists("c:\Temp\Bohrungen.txt") Then
	System.IO.File.Delete("c:\Temp\Bohrungen.txt")
End If


Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("c:\Temp\Bohrungen.txt", True)

..........................
..........................
	
	
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")
	file.WriteLine("Hole diameter of plate 1 = " & "Ø" & dia1 & " - " & oHoleFeature1.ExtendedName & " compared with Hole diameter of plate 2 = " & "Ø" & dia2 & " - " & oHoleFeature2.ExtendedName & " => 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")
	file.WriteLine("Hole diameter of plate 1 = " & "Ø" & dia1 & " - " & oHoleFeature1.ExtendedName & " compared with Hole diameter of plate 2 = " & "Ø" & dia2 & " - " & oHoleFeature2.ExtendedName & " => OK - Special Type")
Else
	Debug.Print("Hole diameter of plate 1 = " & dia1 & " compared with Hole diameter of plate 2 = " & dia2 & " => Not OK")
	file.WriteLine("Hole diameter of plate 1 = " & "Ø" & dia1 & " - " & oHoleFeature1.ExtendedName & " compared with Hole diameter of plate 2 = " & "Ø" & dia2 & " - " & oHoleFeature2.ExtendedName & " => Not OK")
End If

	

m_Inventor.StatusBarText = "Ausgabe in  c:\Temp\Bohrungen.txt"
file.Close()
Process.Start("c:\Temp\Bohrungen.txt"

To check all the hole variations is very complex. How could I check if there is any srew or pin etc. in the hole and get the name? Do I need to use the AnalyzeInterference or is there any other possibility?

 

 

https://forums.autodesk.com/t5/inventor-customization/collision-tapped-holes-and-srews/m-p/6493440#M...

 

 

Georg

 

0 Likes
Message 27 of 43

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK,

 

Try the following VB.net code which lists all aligned and misaligned hole. It also writes to text file.

 

Private Sub Body_Faces()
        Dim m_Inventor As Inventor.Application
        m_Inventor = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

        If System.IO.File.Exists("c:\Temp\Bohrungen.txt") Then
            System.IO.File.Delete("c:\Temp\Bohrungen.txt")
        End If


        Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("c:\Temp\Bohrungen.txt", True)

        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 oFace1 As Face
        Dim oFace2 As Face
        Dim oFaceColl1 As ObjectCollection
        oFaceColl1 = m_Inventor.TransientObjects.CreateObjectCollection()
        Dim oFaceColl2 As ObjectCollection
        oFaceColl2 = m_Inventor.TransientObjects.CreateObjectCollection()
        Dim oAxis1 As WorkAxis
        Dim oAxisColl1 As ObjectCollection
        oAxisColl1 = m_Inventor.TransientObjects.CreateObjectCollection()
        Dim oAxis2 As WorkAxis
        Dim oAxisColl2 As ObjectCollection
        oAxisColl2 = m_Inventor.TransientObjects.CreateObjectCollection()

        For Each oFace1 In oBody1.Faces
            If oFace1.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
                oAxis1 = oCompdef.WorkAxes.AddFixed(oFace1.Geometry.BasePoint, oFace1.Geometry.AxisVector)

                If IsAxisDuplicate(oAxis1, oAxisColl1) = False Then

                    oAxisColl1.Add(oAxis1)
                    oFaceColl1.Add(oFace1)

                Else
                    oAxis1.Delete()
                End If
            End If
        Next

        For Each oFace2 In oBody2.Faces
            If oFace2.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
                oAxis2 = oCompdef.WorkAxes.AddFixed(oFace2.Geometry.BasePoint, oFace2.Geometry.AxisVector)

                If IsAxisDuplicate(oAxis2, oAxisColl2) = False Then

                    oAxisColl2.Add(oAxis2)
                    oFaceColl2.Add(oFace2)

                Else
                    oAxis2.Delete()
                End If
            End If
        Next

        For i As Integer = 1 To oAxisColl1.Count
            oAxis1 = oAxisColl1.Item(i)
            Dim j As Integer = 0
            j = CompareAlignment(oAxis1, oAxisColl2)
            If j > 0 Then
                oFace1 = oFaceColl1.Item(i)
                oFace2 = oFaceColl2.Item(j)
                CompareFace(oFace1, oFace2, file)
                oFace1.AttributeSets.Add("Aligned")
                oFace2.AttributeSets.Add("Aligned")
            End If
        Next

        For Each oFace1 In oFaceColl1
            If oFace1.AttributeSets.Count = 0 Then
                Dim oHoleFeature As HoleFeature
                oHoleFeature = oFace1.CreatedByFeature

                Dim dia As Double
                dia = oHoleFeature.HoleDiameter.Value * 10 ' Converting cm to mm
                file.WriteLine("Hole diameter of plate 1 = " & "Ø" & dia & " - " & oHoleFeature.ExtendedName & " => misaligned")
            End If
        Next

        For Each oFace2 In oFaceColl2
            If oFace2.AttributeSets.Count = 0 Then
                Dim oHoleFeature As HoleFeature
                oHoleFeature = oFace2.CreatedByFeature

                Dim dia As Double
                dia = oHoleFeature.HoleDiameter.Value * 10 ' Converting cm to mm
                file.WriteLine("Hole diameter of plate 2 = " & "Ø" & dia & " - " & oHoleFeature.ExtendedName & " => misaligned")
            End If
        Next

        CleanAxis(oAxisColl1)
        CleanAxis(oAxisColl2)

        m_Inventor.StatusBarText = "Ausgabe in  c:\Temp\Bohrungen.txt"
        file.Close()
        Process.Start("c:\Temp\Bohrungen.txt")

    End Sub
    Public Sub CleanAxis(ByVal oAxisColl As ObjectCollection)
        For Each oAxis As WorkAxis In oAxisColl
            oAxis.Delete()
        Next
    End Sub
    Public Sub CompareFace(ByVal oFace1 As Face, ByVal oFace2 As Face, ByVal file As System.IO.StreamWriter)

        Dim oHoleFeature1 As HoleFeature
        oHoleFeature1 = oFace1.CreatedByFeature

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

        Dim oHoleFeature2 As HoleFeature
        oHoleFeature2 = oFace2.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")
            file.WriteLine("Hole diameter of plate 1 = " & "Ø" & dia1 & " - " & oHoleFeature1.ExtendedName & " compared with Hole diameter of plate 2 = " & "Ø" & dia2 & " - " & oHoleFeature2.ExtendedName & " => 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")
            file.WriteLine("Hole diameter of plate 1 = " & "Ø" & dia1 & " - " & oHoleFeature1.ExtendedName & " compared with Hole diameter of plate 2 = " & "Ø" & dia2 & " - " & oHoleFeature2.ExtendedName & " => OK - Special Type")
        Else
            Debug.Print("Hole diameter of plate 1 = " & dia1 & " compared with Hole diameter of plate 2 = " & dia2 & " => Not OK")
            file.WriteLine("Hole diameter of plate 1 = " & "Ø" & dia1 & " - " & oHoleFeature1.ExtendedName & " compared with Hole diameter of plate 2 = " & "Ø" & dia2 & " - " & oHoleFeature2.ExtendedName & " => Not OK")
        End If
    End Sub
    Public Function CompareAlignment(ByVal oAxis As WorkAxis, ByVal oAxisCollection As ObjectCollection) As Integer
        For i As Integer = 1 To oAxisCollection.Count
            Dim axis As WorkAxis
            axis = oAxisCollection.Item(i)
            If oAxis.Line.IsColinearTo(axis.Line) Then
                Return i
                Exit Function
            End If
        Next

        Return 0
    End Function

    Public Function IsAxisDuplicate(ByVal oAxis As WorkAxis, ByVal oAxisColl As ObjectCollection) As Boolean
        If oAxisColl.Count > 0 Then
            For i As Integer = 1 To oAxisColl.Count
                Dim Axis As WorkAxis
                Axis = oAxisColl.Item(i)
                If Axis.Line.IsColinearTo(oAxis.Line) Then
                    Return True
                End If
            Next
            Return False
        Else
            Return False
        End If
    End Function

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 28 of 43

GeorgK
Advisor
Advisor

@dg2405

 

Hello Daniel,

 

there are screws and pins in the holes. It would be great to get the updated version of your collision checker.

 

Georg

0 Likes
Message 29 of 43

Anonymous
Not applicable

Hi @chandra.shekar.g,

 

 

Sir
your all codes for (hole alignment) is very useful for our ongoing project thank you so much.

its working fine but my requirement explained below.

 

hole alignment code it will check in only axial direction,i need all directions.

Please find the attached image.

 

Thank you
Regards
Naveen

 

0 Likes
Message 30 of 43

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

The attached image is unclear to me. Can you please explain in detail?

 

"Need to check in all direction" means what?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 31 of 43

Anonymous
Not applicable

Hello Sir

 

My requirement


After  run the macro it will create axis for all holes and cylindrical surface (like bend radius also it will create axis).

I need fix for this only it will check for hole feature.

 

In attached image heightened in blue clour axis ,after the macro axis will not create for this area and it will not check for hole alignment for
open holes (not mate any part).

 

Thank you
Reagrds
Naveen

 

 

 

0 Likes
Message 32 of 43

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

 

 

 

Correct me if I am wrong. You are trying create work axis only for hole feature to check alignment.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 33 of 43

Anonymous
Not applicable

Yes sir.

 

and please add the  code for co lour codeing if aligned hole for "green" and misaligned in "red "co lour.

 

 

0 Likes
Message 34 of 43

Anonymous
Not applicable

Sir

 

i am trying to explain my requirement in attached image.

 

Marked in red co lour holes surface not mate to any surface.

After run the macro this holes are going to generate the axis .

 

how to skip this kind of holes to create axis nad if part having bend radius for that also it will create axis.

 

Please support on this its very argent in my ongoing project.

 

My project contains very big assembly and most of the parts are curved surface.

 

Thank you
Reagrds
Naveen

 

0 Likes
Message 35 of 43

Anonymous
Not applicable
        Hole feature missing in mating part 
 

 

I am Naveen, working has a design engineer and beginner for Auto desk Inventor tool.

 

I am very glad to be a member of Auto desk Community, hope I will gain much more knowledge in Inventor customization by the experts in our community.

 

Regarding my post, in attached image having part A &  part B  one assembly file.
Part B having two holes but unfortunately designer miss the hole feature in Part A to assemble the two parts.

 

 

please tell me the logic code to detect or show the error message if mate part not having the hole feature & please find the attached images.

 

I Hope experts will give tell the logic code for my solution.

 

 

 

 

Thanks,

Naveen

0 Likes
Message 36 of 43

Anonymous
Not applicable

Hello Sir

 

Clearly i had explained my requirement in attached image.

 

 Please support on this.

 

Thank you
Reagrds
Naveen

0 Likes
Message 37 of 43

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

Try the following VBA code to compare hole feature.

 

Public Sub Body_Faces()
        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

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 38 of 43

b_sharanraj
Advocate
Advocate
Hi @chandra.shekar.g

I'm unable to use this code.

Which Software you are using? you said it is a VBA Code but I'm unable to execute it from Inventor VBA / Excel VBA / Microsoft Visual Basic


@chandra.shekar.g wrote:

Hi @Anonymous,

 

Try the following VBA code to compare hole feature.

 

Public Sub Body_Faces()
        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

 

Thanks and regards,


 

Regards

B.Sharan Raj

0 Likes
Message 39 of 43

Anonymous
Not applicable

Hi @chandra.shekar.g

 

Thank you so much sir

 

Thanks

Reagrds
Naveen

0 Likes
Message 40 of 43

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @b_sharanraj,

 

Sorry for miscommunication,

 

The code was in VB.net.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes