Obtaining toolpath feedrate and geometry from a STEP-NC file using the SPRI web application
Vincent Marchetti
email: vmarchetti@kshell.com
June 22, 2010
Figure 1: Sequence of views derived from a STEP-NC file used to extract feedrate and geometry for a machining toolpath

This example will demonstrate how to extract the feedrate property and the geometry of a toolpath from a STEP-NC file using the views derived by the SPRI web application. A series of HTTP calls to the web application retrieves views; and XML processing (in this example, using XSLT stylesheets) extracts URLs for further views or the requested explicit data. The procedure starts with the root url which is obtained when the file is uploaded to the server; for this demonstration the root url of a demonstration STEP-NC file is used.

The following steps navigate the content of the STEP-NC file. The implementation displayed here uses the command line utility xsltproc that processes an XML file downloaded from a URL (passed as command line argument) according to an XSLT stylesheet. In the examples given here the XSLT stylesheets are essentially used as simple wrappers to evaluate an XPath expression that searches and returns a value from the XML file. These examples could be readily translated into any programming environment that supports HTTP client calls and evaluating XPath expressions against XML models, including the Python language and Visual Basic

For this example the feedrate and geometry will be retrieved for a toolpath which is identified by the pair of name attribute values for the toolpath and for the workingstep which contains the toolpath. This example will be presented as a series of command line calls (invoked from a terminal) with the returned values written to the terminal; in a production environment these individual steps would be glued together along with procedures for handling errors such as invalid name arguments.

1: Obtain URL for workplans view

The first step is to obtain the dataset view and from that to extract the url for the workplans view. The dataset view is the directory to the top-level views of the STEP file, and for STEP-NC files one such view is the workplans views. The dataset view is an XML file in which links to views are represented according to the XLink standard. An XML element can contain two attributes with names in the standard XLink namespace: a href attribute, whose value is the url to the view and a role attribute, which is an arbitrary key identifying what type of view it is. The value of the role attribute for the workplans view is https://www.kshell.com/role/spri/stepnc/workplans -- this key has the form of a URI to ensure uniqueness. The following XSLT stylesheet find_workplans.xsl searches the dataset view for an XML element with this value of the role attribute and prints the corresponding href attribute; the location of the workplans view.

<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink">

<xsl:param name="role">https://www.kshell.com/role/spri/stepnc/workplans</xsl:param> <xsl:output method="text" encoding="ISO-8859-1"/>

<xsl:template match="/"> <xsl:value-of select="descendant::*[./@xlink:role=$role]/@xlink:href"/> </xsl:template>

</xsl:stylesheet>

This XSLT stylesheet can be applied from a terminal shell with the xsltproc executable, with the URL for the dataset (the root url) as an additional command line argument.

xsltproc find_workplans.xsl http://spri.kshell.com/group/demo/dm03122010a ⇢ http://spri.kshell.com/view/stepnc/workplans/con/dm03122010a

2: Obtain URL for workingstep view

The workplans view linked from the dataset view is a hierarchical representation of the machining workplans-workingstep instances in the file. Each workingstep element also contains a link (coded according to the XLink standard) to a workingstep view with more detailed content to that machining workingstep. For this example the required workingstep is identified by the value of its name. The XSLT stylesheet find_workingstep.xsl searches the workplans view for the workingstep with that name and returns the URL for the workingstep view.

<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:stepnc="https://www.kshell.com/ns/stepnc">

<xsl:param name="name"/><!-- value of parameter 'name' passed in as command line argument --> <xsl:param name="role">https://www.kshell.com/role/spri/stepnc/workingstep</xsl:param> <xsl:output method="text" encoding="ISO-8859-1"/>

<xsl:template match="/"> <xsl:value-of select="descendant::stepnc:workingstep[ normalize-space(stepnc:name)=normalize-space($name) and @xlink:role = $role ]/@xlink:href"/> </xsl:template>

</xsl:stylesheet>

Following is the terminal log for invoking this script, with the required workingstep name entered as a command line argument; along with the workplans URL obtained from the previous step. The URL for the required workingstep is returned and written to terminal.

xsltproc --stringparam name "OP 19 Spot Drilling M6 (4x) [ Y-) Spot Drill 10" \ find_workingstep.xsl \ http://spri.kshell.com/view/stepnc/workplans/con/dm03122010a ⇢ http://spri.kshell.com/view/stepnc/workingstep/con/dm03122010a/69643737383130

3: Extract feedrate from workingstep view

The workingstep view contains values for the properties of a machining workingstep and its toolpaths in an XML model. Properties and toolpaths are identified by their STEP name values. The following XSLT stylesheet get_toolpath_feedrate.xsl searches a workingstep view for the property 'feedrate' of the toolpath with a specified name (entered from the command line) and writes the value of that property to terminal.

<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:stepnc="https://www.kshell.com/ns/stepnc">

<xsl:param name="name"/><!-- value of parameter 'name' passed in as command line argument --> <xsl:param name="role">https://www.kshell.com/role/spri/stepnc/workingstep</xsl:param> <xsl:output method="text" encoding="ISO-8859-1"/>

<xsl:template match="/"> <xsl:value-of select="descendant::stepnc:toolpath[ normalize-space(stepnc:name)=normalize-space($name) ] /stepnc:property[stepnc:name='feedrate'] /stepnc:representation/stepnc:measure_representation /stepnc:value"/> </xsl:template>

</xsl:stylesheet>

Following is the terminal log for invoking this script with the workingstep view URL as returned from the previous step.

xsltproc --stringparam name "WS 30 TP 126" \ get_toolpath_feedrate.xsl \ http://spri.kshell.com/view/stepnc/workingstep/con/dm03122010a/69643737383130 ⇢ 1000

4: Obtain URL for toolpath geometry

The workingstep view obtained in step 2 also contains links to representations of the geometry for toolpaths in that workingstep. As before these links are extracted by searching for links with the appropriate role attribute (in the XLink namespace) in the toolpath XML element with the required toolpath name. This search is carried out with the XSLT stylesheet find_toolpath_geometry.xsl

<?xml version="1.0" encoding="ISO-8859-1"?> <!-- --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:stepnc="https://www.kshell.com/ns/stepnc">

<xsl:param name="name"/><!-- value of parameter 'name' passed in as command line argument --> <xsl:param name="role">https://www.kshell.com/role/spri/stepnc/toolpath/x3d</xsl:param> <xsl:output method="text" encoding="ISO-8859-1"/>

<xsl:template match="/"> <xsl:value-of select="descendant::stepnc:toolpath[ normalize-space(stepnc:name)=normalize-space($name) and @xlink:role=$role ]/@xlink:href"/> </xsl:template>

</xsl:stylesheet>

The stylesheet invoked from the command line, with the same workingstep URL and toolpath name as for step 3 returns the URL for the toolpath geometry view.

xsltproc --stringparam name "WS 30 TP 126" \ find_toolpath_geometry.xsl \ http://spri.kshell.com/view/stepnc/workingstep/con/dm03122010a/69643737383130 ⇢ http://spri.kshell.com/view/stepnc/toolpath/x3d/dm03122010a/69643539353831

Toolpath geometry is returned as an X3D file; a web standard format for geometric data appropriate for visualization. The representation of toolpath geometry is complete enough to support evaluating it's length and so in conjunction with the feedrate returned in step 3 the time required to complete that toolpath motion as part of the workingstep. The SPRI server returns the toolpath X3D file encoded as XML; a formatted version of the X3D file returned from the above example is in toolpath.x3d.