Print at Dec 24, 2025, 8:23:19 AM View all posts in this thread on one page
Posted by PacWood at Apr 11, 2018, 7:42:07 AM
setSelectedLevel gives an Error
Hello,

I am attempting to select a level in a building via the API.

Below is a snippet of code that successfully runs until
the last line is reached.


var HOME;
var HPC = viewHome("viewerCanvas",
homeUrl,
onerror,
onprogression,
{ roundsPerMinute: 0,
navigationPanel: "default",
levelsAndCamerasListId: "levelsAndCameras",
selectableLevels: ["Level 1", "Level 2"],
activateCameraSwitchKey: true
});

HOME = HPC.getHome();

var theLevels = HOME.getLevels();
var levelName = theLevels[0].getName();
console.log('levelName: '+levelName);
var objLevel = theLevels[0];
console.log(objLevel);
HOME.setSelectedLevel("Level 1", objLevel);


At the line:

HOME.setSelectedLevel("Level 1", objLevel);


A javascript error occurs, which is:

"Error: TypeError: m.getElevation is not a function"


However, the code prints the object 'objLevel'

console.log(objLevel);


I can see in the console log, the object 'objLevel' shows
there is a function named "getElevation".

Does anyone have an idea why there is an error of
"getElevation is not a function"
and yet there is a function named "getElevation" in the object
that is being passed to HOME.setSelectedLevel() ?

Below is a screen shot of the console output.





thank you for your help.

Posted by Puybaret at Apr 11, 2018, 11:07:21 AM
Re: setSelectedLevel gives an Error
Sorry, the JSDoc of setSelectedLevel isn't clear and will be fixed in the next version.
setSelectedLevel takes only one parameter:
HOME.setSelectedLevel(objLevel);

----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by PacWood at Apr 11, 2018, 4:38:54 PM
Re: setSelectedLevel gives an Error
Thank you very much for your help and example code.

The program works now.