I’m trying to admin different saved set of parameters each one with a different input file (dwg).
I want to control the start of the session regarding the parameters with initialParameterValues. OK
But I need help to start the session with a different dwg file. (I say different because the model have its own default dwg file).
This code example explains how to set the value of file parameters through the API.
And this one explains how to set initial parameter values when starting a session.
This should give you everything you need to setup a file parameter as initial value when loading the viewer.
I followed the code example to upload a dwg file parameter.
I debuged the code line by line and an error arises when executes session.customize()
Uncaught (in promise) undefined bundle.js:195880:95
rejected bundle.js:195880
(Async: promise callback)
step bundle.js:195881
fulfilled bundle.js:195879
(Async: promise callback)
step bundle.js:195881
fulfilled bundle.js:195879
(Async: promise callback)
step bundle.js:195881
fulfilled bundle.js:195879
(Async: promise callback)
step bundle.js:195881
fulfilled bundle.js:195879
(Async: promise callback)
step bundle.js:195881
__awaiter bundle.js:195882
__awaiter bundle.js:195878
index.ts:14
index.ts:88
bundle.js:195954
bundle.js:195956
Could you share a minimal code example (on codepen or code sandbox) that can help us reproduce the issue so we can investigate it?
I could find a way to upload a dwg file with the mime thing.
Now it’s working.
It seems a good way to you?
Thanks
// get the file input
const fileInputParameter = session.getParameterByName(“MyParameterName”)[0] as IFileParameterApi;
// load dwg file
const dwgBlob = await (await fetch(“/files/parcela2.dwg”)).blob();
// Create a File object from the Blob
const fileName = “MyFile.dwg”; // You can dynamically determine the file name if needed
const mimeType = guessMimeTypeFromFilename(fileName)[0]; // Use your existing function to guess the MIME type
const dwgFile = new File([dwgBlob], fileName, {
type: mimeType
});
// Now set this file as the value of your parameter
fileInputParameter.value = dwgFile;
await session.customize();
This should work. You could also skip guessing the mime type and directly hard code application/dxf
when you create the file.