Overview

The sample program below walks through a STEP-NC process using the Adaptive cursor, summarizes the general structure of the operations, and uses the FinderAPI to report details about the tools.

The Output

The output below was generated by running the program on one of the Boxy sample machining programs. In this case it was the 5-axis, 2 setup version.

boxy process Boxy 5-Axis 2-Setup Process
ALL TOOLS --------------------------
TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95223 machining_tool>
  mfg ident:  T1
  diameter:  16.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  61.0 Unit.MM
  flute length:  61.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95258 machining_tool>
  mfg ident:  T2
  diameter:  10.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  75.0 Unit.MM
  flute length:  75.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95293 machining_tool>
  mfg ident:  T6
  diameter:  26.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  75.0 Unit.MM
  flute length:  75.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95328 machining_tool>
  mfg ident:  T3
  diameter:  10.5 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  60.0 Unit.MM
  flute length:  60.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95363 machining_tool>
  mfg ident:  T4
  diameter:  5.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  60.0 Unit.MM
  flute length:  60.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95398 machining_tool>
  mfg ident:  T5
  diameter:  6.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  75.0 Unit.MM
  flute length:  75.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95433 machining_tool>
  mfg ident:  T7
  diameter:  50.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  60.0 Unit.MM
  flute length:  60.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95468 machining_tool>
  mfg ident:  T8
  diameter:  63.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  45.0 Unit.MM
  flute length:  45.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95503 machining_tool>
  mfg ident:  T9
  diameter:  80.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  40.0 Unit.MM
  flute length:  40.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95538 machining_tool>
  mfg ident:  T10
  diameter:  100.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  50.0 Unit.MM
  flute length:  50.0 Unit.MM
  taper angle:  0.0 Unit.DEG

TOOL:  <step.Object ARM USER_DEFINED_MILLING_TOOL #95573 machining_tool>
  mfg ident:  T11
  diameter:  16.0 Unit.MM
  length:  None Unit.UNKNOWN
  corner radius:  0.0 Unit.MM
  overall assembly length:  55.0 Unit.MM
  flute length:  55.0 Unit.MM
  taper angle:  0.0 Unit.DEG

MAIN WORKPLAN --------------------------
 WORKPLAN Machine Group-1
   WORKPLAN Setup 1 Machining of Face X+, Y+, X-, Y-, Z+   
     WORKPLAN OP 1 Face Milling [ X+]   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X+] End Mill 16-A   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X+] Face Mill 50   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X+] Face Mill 63   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X+] Face Mill 80   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X+] Face Mill 100   
     MACHINING_WORKINGSTEP OP 2 Rough Circle Milling Hole 26 [ X+] End Mill 16-A    
     WORKPLAN OP 3 Face Milling [ Y+]   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y+] End Mill 16-A   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y+] Face Mill 50   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y+] Face Mill 63   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y+] Face Mill 80   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y+] Face Mill 100   
     MACHINING_WORKINGSTEP OP 4 Rough Circle Milling Hole 26 [ Y+] End Mill 16-A   
     WORKPLAN OP 5 Face Milling [ X-]   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X-] End Mill 16-A  
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X-] Face Mill 50   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X-] Face Mill 63   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X-] Face Mill 80   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ X-] Face Mill 100   
     MACHINING_WORKINGSTEP OP 6 Rough Circle Milling Hole 26 [ X-] End Mill 16-A   
     WORKPLAN OP 7 Face Milling [ Y-]   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y-] End Mill 16-A  
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y-] Face Mill 50   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y-] Face Mill 63   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y-] Face Mill 80   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Y-] Face Mill 100   
     MACHINING_WORKINGSTEP OP 8 Rough Pocket Milling [ Y-] End Mill 16-A   
     WORKPLAN OP 9 Fine Pocket Contour Milling [ Y-]   
       MACHINING_WORKINGSTEP      - Alternative Fine  Pocket Contour Milling ( Y-] End Mill 16-A   
       MACHINING_WORKINGSTEP      - Alternative Fine Pocket Contour Milling [ Y-] End Mill 16-B   
     WORKPLAN OP 10 Face Milling [ Z+]   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z+] End Mill 16-A   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z+] Face Mill 50   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z+] Face Mill 63   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z+] Face Mill 80   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z+] Face Mill 100   
     MACHINING_WORKINGSTEP OP 11 Spot Drilling M6 (4x) [ Z+) Spot Drill 10   
     MACHINING_WORKINGSTEP OP 12 Spot Drilling M6 (4x) [ Y-) Spot Drill 10   
     MACHINING_WORKINGSTEP OP 13 Spot Drilling Hole 10.5 [ X-) Spot Drill 10   
     MACHINING_WORKINGSTEP OP 14 Spot Drilling Hole 10.5 [ Y+) Spot Drill 10   
     MACHINING_WORKINGSTEP OP 15 Spot Drilling Hole 10.5 [ X+) Spot Drill 10   
     WORKPLAN Engraving [ X+]   
       MACHINING_WORKINGSTEP      - Alternative Engraving Boxy@Boeing - Northwood [ X+] Spot Drill 10   
       MACHINING_WORKINGSTEP      - Alternative Engraving Boxy@Boeing - Okuma [ X+] Spot Drill 10   
       MACHINING_WORKINGSTEP      - Alternative Engraving Boxy@Bath [ X+] Spot Drill 10   
       MACHINING_WORKINGSTEP      - Alternative Engraving Boxy@CCAT [ X+] Spot Drill 10   
       MACHINING_WORKINGSTEP      - Alternative Engraving Boxy@Scania [ X+] Spot Drill 10   
       MACHINING_WORKINGSTEP      - Alternative Engraving Boxy@KTH - Mazak [ X+] Spot Drill 10   
       MACHINING_WORKINGSTEP      - Alternative Engraving Boxy@KTH - Tricept [ X+] Spot Drill 10   
     MACHINING_WORKINGSTEP OP 16 Drilling Hole 10.5 [ X+) Drill 10.5   
     MACHINING_WORKINGSTEP OP 17 Drilling Hole 10.5 [ Y+) Drill 10.5   
     MACHINING_WORKINGSTEP OP 18 Drilling Hole 10.5 [ X-) Drill 10.5   
     MACHINING_WORKINGSTEP OP 19 Rough Pocket Milling [ Z+] End Mill 16-A   
     WORKPLAN OP 20 Fine Pocket Contour Milling [ Z+]   
       MACHINING_WORKINGSTEP      - Alternative Fine  Pocket Contour Milling ( Z+] End Mill 16-A   
       MACHINING_WORKINGSTEP      - Alternative Fine Pocket Contour Milling [ Z+] End Mill 16-B    
     MACHINING_WORKINGSTEP OP 21 Drilling M6 (4x) [ Z+) Drill 5   
     MACHINING_WORKINGSTEP OP 22 Drilling M6 (4x) [ Y-) Drill 5   
     MACHINING_WORKINGSTEP OP 23 Tapping M6 (4x) [ Y-) Tap M6   
     MACHINING_WORKINGSTEP OP 24 Tapping M6 (4x) [ Z+) Tap M6   
     WORKPLAN OP 25 Finishing Hole 26 [ X+]   
       MACHINING_WORKINGSTEP      - Alternative Fine Boring Hole 26 [ X+] Boring Tool 26 M7   
       MACHINING_WORKINGSTEP      - Alternative Fine Circle Milling Hole 26 [ X+] End Mill 16-B   
     WORKPLAN OP 26 Finishing Hole 26 [ Y+]   
       MACHINING_WORKINGSTEP      - Alternative Fine Boring Hole 26 [ Y+] Boring Tool 26 M7   
       MACHINING_WORKINGSTEP      - Alternative Fine Circle Milling Hole 26 [ Y+] End Mill 16-B   
     WORKPLAN OP 27 Finishing Hole 26 [ X-]   
       MACHINING_WORKINGSTEP      - Alternative Fine Boring Hole 26 [ X-] Boring Tool 26 M7   
       MACHINING_WORKINGSTEP      - Alternative Fine Circle Milling Hole 26 [ X-] End Mill 16-B   
   WORKPLAN Setup 2 Machining of Face Z-   
     WORKPLAN OP 28 Face Milling [ Z-]   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z-] End Mill 16-A   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z-] Face Mill 50   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z-] Face Mill 63   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z-] Face Mill 80   
       MACHINING_WORKINGSTEP      - Alternative Face Milling [ Z-] Face Mill 100   
     MACHINING_WORKINGSTEP OP 29 Rough Pocket Milling [ Z-] End Mill 16-A   
     WORKPLAN OP 30 Fine Pocket Contour Milling [ Z-]   
       MACHINING_WORKINGSTEP      - Alternative Fine  Pocket Contour Milling ( Z-] End Mill 16-A   
       MACHINING_WORKINGSTEP      - Alternative Fine Pocket Contour Milling [ Z-] End Mill 16-B    
     MACHINING_WORKINGSTEP OP 31 Spot Drilling M6 (4x) [ Z-) Spot Drill 10   
     MACHINING_WORKINGSTEP OP 32 Drilling M6 (4x) [ Z-) Drill 5   
     MACHINING_WORKINGSTEP OP 33 Tapping M6 (4x) [ Z-) Tap M6   

The Program

This sample program reads a file, then prints all tools and a brief, indented process overview. You can use this as a starting point for digging into other details.

The tool printing function loops over all tool objects in the file and uses the FinderAPI to report on some properties like length and diameter.

The process printing function uses the Adaptive cursor to summarize the general structure of the operations. The cursor moves through a machining process, stopping at tool changes, the start or end of workplans, working steps, operations, and toolpaths, or even individual tool moves. Our example only stops at the high-level parts of the process, but my stopping at each tool move, you can make CNC control codes with the Generate class.

import sys
from steptools import step
from steptools.step import FinderAPI as find

def print_process(D) -> None:
    print(MAIN WORKPLAN --------------------------)

    CUR = step.Adaptive()
    CUR.start_project(D)

    # Select only workplan start/stop, and individual workingsteps
    CUR.set_wanted_all(False)
    CUR.set_wanted(step.CtlEvent.EXEC_WORKPLAN_START)
    CUR.set_wanted(step.CtlEvent.EXEC_WORKPLAN_END)
    CUR.set_wanted(step.CtlEvent.EXEC_SELECT_START)
    CUR.set_wanted(step.CtlEvent.EXEC_SELECT_END)
    CUR.set_wanted(step.CtlEvent.EXEC_WORKSTEP_START)

    INDENT = 0
    while CUR.next():
        E = CUR.event()
        OBJ = CUR.get_active_exec()
        
        if (
                E == step.CtlEvent.EXEC_WORKPLAN_START or
                E == step.CtlEvent.EXEC_SELECT_START
        ):
            # print workplan, then increase indent
            print (   * INDENT, step.arm_type(OBJ), OBJ.name)
            INDENT += 1
        elif (
                E == step.CtlEvent.EXEC_WORKPLAN_END or
                E == step.CtlEvent.EXEC_SELECT_END
        ):
            # decrease indent but do not print
            INDENT -= 1
        else:
            # print workingstep
            print (   * INDENT, step.arm_type(OBJ), OBJ.name)



def print_tools(D) -> None:
    print(ALL TOOLS --------------------------)
    for T in step.DesignCursor(D, machining_tool):
        print(TOOL: , T)
        print(  mfg ident: , find.get_tool_identifier(T))
        print(  diameter: ,
              find.get_tool_diameter(T),
              find.get_tool_diameter_unit(T))
        print(  length: ,
              find.get_tool_length(T),
              find.get_tool_length_unit(T))
        print(  corner radius: ,
              find.get_tool_corner_radius(T), 
              find.get_tool_corner_radius_unit(T))
        
        VAL = find.get_tool_overall_length(T)
        if VAL is not None:
            print(  overall assembly length: ,
                  find.get_tool_overall_length(T), 
                  find.get_tool_overall_length_unit(T))

        VAL = find.get_tool_flute_length(T)
        if VAL is not None:
            print(  flute length: ,
                  find.get_tool_flute_length(T),
                  find.get_tool_flute_length_unit(T))
            
        VAL = find.get_tool_taper_angle(T)
        if VAL is not None:
            print(  taper angle: ,
                  find.get_tool_taper_angle(T), 
                  find.get_tool_taper_angle_unit(T))

        VAL = find.get_tool_tip_angle(T)
        if VAL is not None:
            print(  tip angle: ,
                  find.get_tool_tip_angle(T), 
                  find.get_tool_tip_angle_unit(T))

        print()
        
    
def main() -> int:
    Summarize a STEP-NC Process
    args = iter(sys.argv)           # Parse command line arguments
    PROG = next(args)
    SRC = next(args, None)

    if SRC is None:
        print(no input file specified, file = sys.stderr )
        sys.exit(1)

    D = step.open_project(SRC)

    print_tools(D)
    print_process(D)
    
    return 0

if __name__ == __main__:
    sys.exit(main())