修改打开逻辑
2026-09-08 17:07
10.3.35及以上版本,设置basePath或模型路径的代码参考main.js中initBasePath();initModelPath();
在window.onload方法中设置basePath指向控件包根目录以及配置相关路径,详情请参考js/main.js。
//修改basePath,指向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);
//10.3.35版本及以上,请查看main.js中的initBasePath();initModelPath();
在window.onload方法中加载命令配置,并设置模型路径以进行三维预览,详情请参考js/main.js。
10.2.8及以上版本,加载命令配置以及打开逻辑,请参考main_local.js中initOnline方法。
//修改basePath,指向SView demo的根目录
let basePath = window.location.href.slice(0,window.location.href.lastIndexOf("/")+1);
var path;
var isArray = false;
//修改模型路径
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 {
//没有配置文件的情况
let array = new Map();
array.set("fullClassName", "SView.Commands.OpenCommand");
openCommand = commandsManager.getCommand(SView.Commands.CommandNames.OPENSAMPLEFILE, array);
}
if (isArray == "false") {
//单个文件打开,直接设置openCommand.path的值
openCommand.path = path;
mainPath = openCommand.path;
}else{
//多文件打开,循环调用openCommand.addPath(),添加需要打开的模型路径
let paths = path.split(",");
for(let i=0;i<paths.length;i++){
openCommand.addPath(paths[i]);
}
}
//执行打开命令,打开模型
commandsManager.execute(SView.Commands.CommandNames.OPENSAMPLEFILE);
});

全部评论