PatCatProf
Mechanical
- Oct 1, 2024
- 1
Hello,
I am new in this community, I need your help.
I would like to get makro which calculate how many holes I have in total project and additionaly how many holes ehit threaded, but unfortunatel I do not know how to get threades properly.
My code looks like:
Sub CATMain()
' Variable declaration
Dim doc
Dim part
Dim body
Dim shape
Dim i
Dim totalHoles
Dim threadedCount
' counters setup
totalHoles = 0
threadedCount = 0
' Get active document
Set doc = CATIA.ActiveDocument
' chcek type of document PartDocument
If TypeName(doc) = "PartDocument" Then
Set part = doc.Part
Set body = part.Bodies.Item(1) ' get first body
' check all bodies
For i = 1 To body.Shapes.Count
Set shape = body.Shapes.Item(i)
' check holes
If TypeName(shape) = "Hole" Then
totalHoles = totalHoles + 1
' Check if hole is threaded
On Error Resume Next
If Not shape.HoleType Is Nothing Then
If shape.HoleType = "Thread" Then
threadedCount = threadedCount + 1
End If
End If
On Error GoTo 0
End If
Next
' display results
MsgBox "Total quantity of holes: " & totalHoles & vbCrLf & "Threads: " & threadedCount
Else
MsgBox "THis is not proper file (CATPart)."
End If
End Sub
I am new in this community, I need your help.
I would like to get makro which calculate how many holes I have in total project and additionaly how many holes ehit threaded, but unfortunatel I do not know how to get threades properly.
My code looks like:
Sub CATMain()
' Variable declaration
Dim doc
Dim part
Dim body
Dim shape
Dim i
Dim totalHoles
Dim threadedCount
' counters setup
totalHoles = 0
threadedCount = 0
' Get active document
Set doc = CATIA.ActiveDocument
' chcek type of document PartDocument
If TypeName(doc) = "PartDocument" Then
Set part = doc.Part
Set body = part.Bodies.Item(1) ' get first body
' check all bodies
For i = 1 To body.Shapes.Count
Set shape = body.Shapes.Item(i)
' check holes
If TypeName(shape) = "Hole" Then
totalHoles = totalHoles + 1
' Check if hole is threaded
On Error Resume Next
If Not shape.HoleType Is Nothing Then
If shape.HoleType = "Thread" Then
threadedCount = threadedCount + 1
End If
End If
On Error GoTo 0
End If
Next
' display results
MsgBox "Total quantity of holes: " & totalHoles & vbCrLf & "Threads: " & threadedCount
Else
MsgBox "THis is not proper file (CATPart)."
End If
End Sub