3

I had the need to retrieve the geometrical/technological attributes from the tools loaded in a Catia CATProcess machining project.

To do so, I came up with this piece of CATVBA code:

Dim MfgDoc1 As Document
On Error GoTo Erreur2
Set MfgDoc1 = CATIA.ActiveDocument
On Error GoTo 0
 
' Checks the extension of the loaded document
If Not (Right(MfgDoc1.Name, (Len(MfgDoc1.Name) - InStrRev(MfgDoc1.Name, "."))) = "CATProcess") Then GoTo Erreur


Set pprdocument1 = MfgDoc1.PPRDocument      ' Select the PPR level
Set activities1 = pprdocument1.Processes    ' Select the Process List
Set activity1 = activities1.Item(1)         ' Select the #1 item from the process list

Dim actName As String
actName = activity1.Name                    ' Retrieve name of #1 item

Set aProcess = MfgDoc1.GetItem(actName)

'---------------------------------------------------------------
' Scan through Process elements, looking for tool-changes
'---------------------------------------------------------------
    If (aProcess.IsSubTypeOf("PhysicalActivity")) Then
    Set childs = aProcess.ChildrenActivities
    quantity = childs.count
        If quantity <= 0 Then
          Exit Sub
        End If
    For i = 1 To quantity
      Set CurrentSetup = childs.Item(i)
        'MsgBox childs.Item(i).Name
      If (CurrentSetup.IsSubTypeOf("ManufacturingSetup")) Then
        '---------------------------------------------------------------
        '       Read the Programs  of the current Setup
        '---------------------------------------------------------------
        Set ProgramList = CurrentSetup.Programs
        NumberOfProgram = ProgramList.count
        For J = 1 To NumberOfProgram
            Set CurrentProgram = ProgramList.GetElement(J)
            '---------------------------------------------------------------
            '               Read the Activities of the current Program
            '---------------------------------------------------------------
            FileName = CurrentProgram.Name          ' Name of the Manufacturing Program [PP]
            
            Set ActivityList = CurrentProgram.Activities
            NumberOfActivity = ActivityList.count
                If (NumberOfActivity = 0) Then
                    MsgBox "The Process does not contain any machining operation!" & vbNewLine & vbNewLine & "Operation stopped.", vbInformation, "The file is empty"
                    Exit Sub
                End If
            For K = 1 To NumberOfActivity
                        
              Set CurrentActivity = ActivityList.GetElement(K)
              ActivityType = CurrentActivity.Type
              If (ActivityType = "ToolChange" Or ActivityType = "ToolChangeLathe") Then
                    count = count + 1
                    ' Read attributes from "CurrentTool" element called by "ToolChange" activity
                    Set CurrentTool = CurrentActivity.Tool
                    ToolNumber = CurrentTool.ToolNumber                                 ' Gives the numeric name of the "T" tool
                    ToolComment = CurrentTool.ToolType                                  ' Gives tool type es. "MfgEndMillTool"
                    
                    MFG_TOOL_NUMBER = CurrentTool.GetAttribute("MFG_TOOL_NUMBER").ValueAsString()
                    MFG_NOMINAL_DIAM = CurrentTool.GetAttribute("MFG_NOMINAL_DIAM").ValueAsString()
                    MFG_CUT_LENGTH = CurrentTool.GetAttribute("MFG_CUT_LENGTH").ValueAsString()
                    MFG_OVERALL_LGTH = CurrentTool.GetAttribute("MFG_OVERALL_LGTH").ValueAsString()
                    MFG_NB_OF_FLUTES = CurrentTool.GetAttribute("MFG_NB_OF_FLUTES").ValueAsString()
                    ' Exception for MFG_CONRER_RAD e MFG_NB_OF_FLUTES on tools without that attributes:
                    If Not ((CurrentTool.ToolType = "MfgCenterDrillTool") Or (CurrentTool.ToolType = "MfgSpotDrillTool") Or (CurrentTool.ToolType = "MfgDrillTool") Or (CurrentTool.ToolType = "MfgReamerTool") Or (CurrentTool.ToolType = "MfgBoringBarTool") Or (CurrentTool.ToolType = "MfgTapTool") Or (CurrentTool.ToolType = "MfgMultiDiamDrillTool") Or (CurrentTool.ToolType = "MfgTwoSidesChamferingTool") Or (CurrentTool.ToolType = "MfgThreadMillTool") Or (CurrentTool.ToolType = "MfgCounterboreMillTool")) Then
                        MFG_CORNER_RAD = CurrentTool.GetAttribute("MFG_CORNER_RAD").ValueAsString()
                        'MFG_NB_OF_FLUTES = CurrentTool.GetAttribute("MFG_NB_OF_FLUTES").ValueAsString()
                        CATIAResult = "MFG_TOOL_NUMBER~" & MFG_TOOL_NUMBER & "|" & "MFG_NOMINAL_DIAM~" & MFG_NOMINAL_DIAM & "|" & "MFG_CUT_LENGTH~" & MFG_CUT_LENGTH & "|" & "MFG_OVERALL_LGTH~" & MFG_OVERALL_LGTH & "|" & "MFG_CORNER_RAD~" & MFG_CORNER_RAD & "|" & "MFG_NB_OF_FLUTES~" & MFG_NB_OF_FLUTES
                    Else
                        MFG_CORNER_RAD = 0
                        CATIAResult = "MFG_TOOL_NUMBER~" & MFG_TOOL_NUMBER & "|" & "MFG_NOMINAL_DIAM~" & MFG_NOMINAL_DIAM & "|" & "MFG_CUT_LENGTH~" & MFG_CUT_LENGTH & "|" & "MFG_OVERALL_LGTH~" & MFG_OVERALL_LGTH & "|" & "MFG_NB_OF_FLUTES~" & MFG_NB_OF_FLUTES & "|" & "MFG_CORNER_RAD~" & MFG_CORNER_RAD
                    End If
                    
                    
                    If (MFG_TOOL_NUMBER = "") Then
                        MFG_TOOL_NUMBER = 0
                    End If
                    If (MFG_NOMINAL_DIAM = "") Then
                        MFG_NOMINAL_DIAM = 0
                    End If
                    If (MFG_CUT_LENGTH = "") Then
                        MFG_CUT_LENGTH = 0
                    End If
                    If (MFG_OVERALL_LGTH = "") Then
                        MFG_OVERALL_LGTH = 0
                    End If
                    If (MFG_CORNER_RAD = "") Then
                        MFG_CORNER_RAD = 0
                    End If
                ...
                ...
                ...

            Next
        Next
    Next
                ...
                ...

The trick is to select the tool pointed by each tool-change activity. I was not able to cycle directly through the ResourcesList of the PPR (I've also tried with C# but apparently Catia does not allow to interact with the ResourcesList. Maybe it's available only with CAA dev tools.), the result is that I can get attributes only from resources linked by a PartOperations/MfgPrograms/Toolchanges

Radogost
  • 143
  • 5
  • 16
MVa
  • 31
  • 4

0 Answers0