diff --git a/documents/DeveloperGuide/CodeExamples.md b/documents/DeveloperGuide/CodeExamples.md index 0e156bb896..fb43fae766 100644 --- a/documents/DeveloperGuide/CodeExamples.md +++ b/documents/DeveloperGuide/CodeExamples.md @@ -167,28 +167,22 @@ for elem in doc.traverseTree(): ~~~{.js} import MaterialX from './JsMaterialXCore.js'; -MaterialX().then(async (_module) => { - // Get the MaterialX namespace. - const mx = _module.getMaterialX(); - +MaterialX().then(async (mx) => { // Read a document from disk. const doc = mx.createDocument(); - // Note: The xmlStr should be defined. - await mx.readFromXmlString(doc, xmlStr); + await mx.readFromXmlFile(doc, 'ExampleFile.mtlx'); // Traverse the document tree in depth-first order. const elements = doc.traverseTree(); - let elem = elements.next(); - while(elem) { + for (let elem of elements) { // Display the filename of each image node. - if (elem instanceof mx.Node) { - const param = elem.getParameter('file'); + if (elem.isANode('image')) { + const param = elem.getInput('file'); if (param) { filename = param.getValueString(); console.log('Image node ' + elem.getName() + ' references ' + filename); } } - elem = elements.next(); } } ~~~ @@ -300,4 +294,4 @@ MaterialX().then(async (_module) => { }); }); } -~~~ \ No newline at end of file +~~~ diff --git a/source/JsMaterialX/test/codeExamples.spec.js b/source/JsMaterialX/test/codeExamples.spec.js index 92aefb5729..901fd3b592 100644 --- a/source/JsMaterialX/test/codeExamples.spec.js +++ b/source/JsMaterialX/test/codeExamples.spec.js @@ -95,7 +95,7 @@ describe('Code Examples', () => { for(let elem of elements) { elementCount++; // Display the filename of each image node. - if (elem instanceof mx.Node) { + if (elem.isANode('image')) { nodeCount++; const input = elem.getInput('file'); if (input) { @@ -107,7 +107,7 @@ describe('Code Examples', () => { } } expect(elementCount).to.equal(21); - expect(nodeCount).to.equal(5); + expect(nodeCount).to.equal(1); expect(fileCount).to.equal(1); });