Hello Chandra,
Thank you very much for your help.
To compare the holes is more than to compare the diameter.
Some examples:
Plate 1: / Plate 2:
M6 / Ø 6,1 => OK - special type
M6 / Ø 6,2 => OK - special type
M6 / Ø 6,3 => OK - special type
M6 / Ø 6,4 => OK - special type
M6 / Ø 6,5 => OK - special type
M6 / Ø 6,6 => OK - default
M5 / Ø 5,5 => OK - default
Ø 5,5 / Ø 5,5 => OK - default
Ø 4 / Ø 5,5 => nOK
With the
ExtendedName = (Zylindrische Senkung Ø6,5 mm x 3,4 mm, Ø5,50000000 mm Durch alle Tiefe)
I get all the information to compare the holes and see if they match. Therefore I thougt of a hole list for plate 1 /plate2 and the compared holes.
Maybe the best way is to compare a list with two rows for holes that match together. If the hole from plate 1 and plate 2 match the list everthing is OK or not. Maybe you have other ideas?
Best regards
Georg
' Selecting 2 bodies Or plates
' Creating work axis for all holes in both bodies Or plates
' Comparing each work axis of one body Or plate with all work axis of another body Or plate. If there are any misalignment, then work axis will be renamed to "misaligned".
' For recognizing misalignment, work axes of second body are deleted.
Dim m_inventorApp As Inventor.Application = Nothing
' Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
'###########################
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim oTrans As Transaction
oTrans = m_inventorApp.TransactionManager.StartTransaction(m_inventorApp.ActiveDocument, "Bohrungen prüfen")
Dim oDoc As AssemblyDocument
oDoc = m_inventorApp.ActiveDocument
Dim oCompdef As AssemblyComponentDefinition
oCompdef = oDoc.ComponentDefinition
Dim oBody1 As SurfaceBody
Dim oBody2 As SurfaceBody
oBody1 = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select first body")
oBody2 = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select a body to compare")
Dim oFace As Face
Dim oAxis As WorkAxis
Dim oAxisColl1 As ObjectCollection
oAxisColl1 = m_inventorApp.TransientObjects.CreateObjectCollection()
For Each oFace In oBody1.Faces
If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
oAxis = oCompdef.WorkAxes.AddFixed(oFace.Geometry.BasePoint, oFace.Geometry.AxisVector)
Call oAxisColl1.Add(oAxis)
Debug.Print(oFace.CreatedByFeature.ExtendedName)
End If
Try
'If oFace.CreatedByFeature.Type = ObjectTypeEnum.kHoleFeatureObject Then
Dim oHoleFeature As HoleFeature
oHoleFeature = oFace.CreatedByFeature
Debug.Print("'############################")
Debug.Print("Name - erste Wahl = " & oHoleFeature.Name)
Debug.Print("ExtendedName = " & oHoleFeature.ExtendedName)
'Debug.Print("ExtentType = " & oHoleFeature.ExtentType)
Debug.Print("HoleDiameter 1 = " & oHoleFeature.HoleDiameter.Value)
Debug.Print("'############################")
'End If
Catch ex As Exception
End Try
Next
Dim oAxisColl2 As ObjectCollection
oAxisColl2 = m_inventorApp.TransientObjects.CreateObjectCollection()
For Each oFace In oBody2.Faces
If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
oAxis = oCompdef.WorkAxes.AddFixed(oFace.Geometry.BasePoint, oFace.Geometry.AxisVector)
Call oAxisColl2.Add(oAxis)
'MsgBox(oFace.CreatedByFeature.ExtendedName)
End If
Try
'If oFace.CreatedByFeature.Type = ObjectTypeEnum.kHoleFeatureObject Then
Dim oHoleFeature As HoleFeature
oHoleFeature = oFace.CreatedByFeature
Debug.Print("'############################")
Debug.Print("Name - zweite Wahl = " & oHoleFeature.Name)
Debug.Print("ExtendedName = " & oHoleFeature.ExtendedName)
'Debug.Print("ExtentType = " & oHoleFeature.ExtentType)
Debug.Print("HoleDiameter 2 = " & oHoleFeature.HoleDiameter.Value)
Debug.Print("'############################")
'End If
Catch ex As Exception
End Try
Next
Call CompareAxes(oAxisColl1, oAxisColl2)
Dim i As Integer
For i = 1 To oAxisColl2.Count
oAxis = oAxisColl2.Item(i)
Call oAxis.Delete()
Next
Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes.ActivePane
Dim alignedNodes As ObjectCollection
alignedNodes = m_inventorApp.TransientObjects.CreateObjectCollection
Dim misAlignedNodes As ObjectCollection
misAlignedNodes = m_inventorApp.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)
oTrans.End()
End Sub
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
Sub CompareAxes(oAxisColl1 As ObjectCollection, oAxisColl2 As ObjectCollection)
Dim oAxis1 As WorkAxis
Dim oAxis2 As WorkAxis
Dim aligned As Boolean
Dim i As Integer
Dim j As Integer
For i = 1 To oAxisColl1.Count
aligned = False
oAxis1 = oAxisColl1.Item(i)
For j = 1 To oAxisColl2.Count
oAxis2 = oAxisColl2.Item(j)
If oAxis1.Line.IsColinearTo(oAxis2.Line) Then
aligned = True
Exit For
End If
Next
If aligned = False Then
oAxis1.Name = oAxis1.Name & "_misaligned"
End If
Next
End Sub