Sub CATMain()
Dim objProduct As Part
Dim objProductMat As Part
Dim intNbParts As Integer
Dim i As Integer
Dim intNbEdges As Integer
Dim doc, sel, spa, ref, measurable
Dim inputObjectType(0)
Dim j As Integer
StartCATIA
If Err.Number <> 0 Then
Exit Sub
End If
StartEXCEL
If Err.Number <> 0 Then
Exit Sub
End If
Set objGCATIASelection0 = objGCATIADocument0.Selection
Set objGCATIAProduct0 = objGCATIADocument0.Product
If objGCATIASelection0.Count = 0 Then
objGCATIASelection0.Search "(CATLndSearch.Part),all"
End If
intNbParts = objGCATIASelection0.Count
For i = 1 To intNbParts
Set objProduct = Nothing
Set objProductMat = Nothing
Set objProduct = objGCATIASelection0.Item(i).Value
Set objProductMat = objGCATIASelection0.Item(i)
Err.Clear
'On Error Resume Next
Dim objInertia As Inertia
On Error Resume Next
Set objInertia = objProduct.GetTechnologicalObject("Inertia")
Dim getMass As String
getMass = objInertia.Mass
Dim partName As String
partName = objProduct.Name
'Dim Mat As Material
'Dim oManager As MaterialManager
'Set oManager = objProductMat.GetItem("CATMatManagerVBExt")
'oManager.GetMaterialOnPart objProductMat.ReferenceProduct.Parent.Part,Mat
'matName = Mat.Name
Dim Coordinates(2)
objInertia.GetCOGPosition Coordinates
Set sel = CATIA.ActiveDocument.Item(i)
Set spa = doc.GetWorkbench("SPAWorkbench")
'// Now for the second loop
sel.Search "Topology.CGMEdge,all"
intNbEdges = sel.Count
MsgBox intNbEdges
For j = 1 To intNbEdges
Set myCircle = sel.Item(j)
If myCircle.Type = "TriDimFeatEdge" Then
Set ref = sel.Item(j).Reference
Set measurable = spa.GetMeasurable(ref)
Dim oCoordinates(2)
measurable.GetCenter oCoordinates
Dim Radius As Long
Radius = measurable.Radius
MsgBox "x = " & oCoordinates(0) & Chr(10) & "y = " & oCoordinates(1) & Chr(10) & "z = " & oCoordinates(2) & Chr(10) & "Diametre = " & 2 * Radius
Err.Clear
End If
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepX, oCoordinates(0) & "mm"
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepY, oCoordinates(1) & "mm"
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepZ, oCoordinates(2) & "mm"
Next
intGReportCurrentRow = intGReportCurrentRow + 1
InsertAnEXCELRowAt (intGReportCurrentRow)
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleMass, getMass
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleMaterial, matName
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGX, Coordinates(0) & "mm"
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGY, Coordinates(1) & "mm"
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleCOGZ, Coordinates(2) & "mm"
'WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepX, oCoordinates(0) & "mm"
'WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepY, oCoordinates(1) & "mm"
'WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitleDepZ, oCoordinates(2) & "mm"
WriteToEXCELRunSheet intGReportCurrentRow, strGReportTitlePartName, partName
Next
intGReportCurrentRow = intGReportCurrentRow + 1
InsertAnEXCELRowAt (intGReportCurrentRow)
End Sub '/////////////////////////////////////////////////////////// CATMain