Launching a TerraExplorer Executable Tool
This example demonstrates how to launch an external executable tool asynchronously using ICreator81.CreateCommandLineProcessAsync. The user is prompted to select a specific file or directory through an IApplication81 OpenFileDialog, and the selected path is then passed as a parameter to SLMeshConverter.exe.
async function convert3DMLTo3DTiles() {
try {
// A. Get input 3DML file and output folder from user
const in3DMLFileJson = awaitSGWorld.Application.openFileDialog(false, "3dml files (*.3dml)|*.3dml");
const out3DTilesFolderJson = awaitSGWorld.Application.openFileDialog(true, "");
// B. Extract "key" values from JSON
const in3DMLFilePath = extractKeyFromJson(in3DMLFileJson);
const outFolderPath = extractKeyFromJson(out3DTilesFolderJson);
// C. Build and execute command
const command = `SLMeshConverter.exe -cmd convert -in "${in3DMLFilePath}" -out "${outFolderPath}" -f b3dm`;
const process = SGWorld.Creator.createCommandLineProcessAsync(command)
.onStdout(stdoutHandler)
.onStderr(stderrHandler)
.onExit(exitHandler);
} catch (ex) {
alert("Exception: " + ex.message);
}
}
const stringBuilder = [];
function stdoutHandler(data) {
stringBuilder.push(data);
}
function stderrHandler(data) {
stringBuilder.push(data);
}
function exitHandler(exitCode) {
console.log("Process exited with code:", exitCode);
console.log("SUMMARY Log:\n" + stringBuilder.join(""));
}
function extractKeyFromJson(json) {
try {
const parsed = JSON.parse(json);
return parsed.key;
} catch (e) {
console.error("Failed to parse JSON:", e);
return "";
}
}