Project Files

Visual Studio 2012 projects. Right-click to save

Print STEP-NC Tool Moves

The sample program below prints destination information for tool moves in a STEP-NC file. The program uses the the Finder to read the data and the Adaptive process cursor to iterate over the moves.

There are sample projects in C# and Visual Basic. The process cursor walks the process until it reaches the next requested event. By default, it just stops at tool moves. At each move, we examine the type of movement element on the process stack and print relevant information for a linear move, arc, or helix.

The Visual Basic version of the sample program is shown below.

Imports STEPNCLib

Sub Main()
    Dim finder As finder = New finder
    Dim ctl As Adaptive = New Adaptive

    '' Read a STEP-NC file
    finder.Open238("sample_file.stpnc")

    '' Start traversing the process within the file.
    '' Uses the active data from finder.
    ctl.StartProject()

    '' The Move event is the only one selected by default
    While ctl.Next() <> Adaptive.CtlEvent.DONE

	Select Case ctl.GetActiveType()

	    Case Adaptive.CtlType.MOVE
		Console.WriteLine("LINEAR MOVE")
		printend(ctl, ctl.GetMoveEnd())

	    Case Adaptive.CtlType.MOVE_ARC
		Console.WriteLine("ARC MOVE")
		printarc(ctl, ctl.GetMoveArc())
		printend(ctl, ctl.GetMoveEnd())

	    Case Adaptive.CtlType.MOVE_HELIX
		Console.WriteLine("HELIX MOVE")
		printarc(ctl, ctl.GetMoveArc())
		printend(ctl, ctl.GetMoveEnd())
	End Select
    End While
End Sub

The functions below print the destination coordinates, tool axis, and any arc parameters associated with the move. These are the most common parameters, but a position may have others, like surface normal or feed multiplier.

Sub printend(ctl As Adaptive, p As UInteger)
    Dim a, b, c As Double
    ctl.GetPosXYZ(a, b, c, p)
    Console.Write("  END: XYZ: {0:0.0####} {1:0.0####} {2:0.0####}", a, b, c)

    ctl.GetPosDirZ(a, b, c, p)
    Console.Write("  ZDIR: {0:0.0####} {1:0.0####} {2:0.0####}", a, b, c)
    Console.WriteLine()
End Sub

'' Print arc center, radius, and direction for an arc move
''
Sub printarc(ctl As Adaptive, p As UInteger)
    Dim a, b, c As Double
    ctl.GetPosXYZ(a, b, c, p)
    Console.Write("  END: XYZ: {0:0.0####} {1:0.0####} {2:0.0####}", a, b, c)
    If ctl.GetArcIsCW(p) Then
	Console.Write("  ARC: CW")
    Else
	Console.Write("  ARC: CCW")
    End If

    ctl.GetArcCenter(a, b, c, p)
    Console.Write("  END: XYZ: {0:0.0####} {1:0.0####} {2:0.0####}", a, b, c)

    Console.Write("  RADIUS: {0:0.0####}", ctl.GetArcRadius(p))
    Console.Write("  ANGLE: {0:0.0####}", ctl.GetArcAngle(p))
    Console.WriteLine()
End Sub