SView Help Center
English (US)

Modify the Open Logic

Author: sviewngts Last Updated: 2026-10-29 16:49

   For version 10.3.35 and later, refer to initBasePath() and initModelPath() in main.js for the code that sets the basePath or model path.

   In the window.onload method, set basePath to point to the root directory of the control package and configure the related paths. For details, see js/main.js.

// Modify basePath to point to the root directory of the SView demo
let basePath = window.location.href.slice(0, window.location.href.lastIndexOf("/") + 1);
let sysConfigPath = basePath + "config/systemParameters.json";
let docConfigPath = basePath + "config/documentParameters.json";
configManager.setCommandConfigPath(basePath + "config/commandParameters.json");
M3D.Config.Parameters.getInstance().setParameter(M3D.Config.licencePath, basePath + "lic");
M3D.Config.Parameters.getInstance().setParameter(M3D.Config.aniToolFileUrl, basePath);
M3D.Config.Parameters.getInstance().setParameter(M3D.Config.draggerFileUrl, basePath);
// For version 10.3.35 and later, see initBasePath() and initModelPath() in main.js

   In the window.onload method, load the command configuration and set the model path for 3D preview. For details, see js/main.js.

   For version 10.2.8 and later, refer to the initOnline method in main_local.js for loading the command configuration and the open logic.

// Modify basePath to point to the root directory of the SView demo
let basePath = window.location.href.slice(0, window.location.href.lastIndexOf("/") + 1);
var path;
var isArray = false;
// Modify the model path
path = basePath + "models/Wankel Engine.svlx"
configManager.loadCommandConfigs().then((ret) => {
 let commandsManager = sview0.sviewFrame.getCommandsManager();
 let openCommand = null;
 if (ret) {
  openCommand = commandsManager.getCommand(SView.Commands.CommandNames.OPENSAMPLEFILE);
 } else {
  // When there is no configuration file
  let array = new Map();
  array.set("fullClassName", "SView.Commands.OpenCommand");
  openCommand = commandsManager.getCommand(SView.Commands.CommandNames.OPENSAMPLEFILE, array);
 }
 if (isArray == "false") {
  // Single-file open: set the value of openCommand.path directly
  openCommand.path = path;
  mainPath = openCommand.path;
 } else {
  // Multi-file open: call openCommand.addPath() in a loop to add the model paths to open
  let paths = path.split(",");
  for (let i = 0; i < paths.length; i++) {
   openCommand.addPath(paths[i]);
  }
 }
 // Execute the open command to open the model
 commandsManager.execute(SView.Commands.CommandNames.OPENSAMPLEFILE);
});