2 Dec 2020

Collapse category in the Property Panel

There is a function called setCategoryCollapsed(category,collapsed) for collapsing a category in the Property Panel, but the documentation is not clear on what exactly it expects as input values:
https://forge.autodesk.com/en/docs/viewer/v2/reference/javascript/propertypanel/#setcategorycollapsed-category-collapsed 

Since we have access to the full source code of the Viewer (you usually reference the "*.min.js" version but if you remove the ".min" part from the file name you can also get the non-minified version), we can reference that from our code and debug into it. If we leave a breakpoint in the function we are interested in and collapse the category through the User Interface, then we can check how this function is supposed to be called:

Debugging into setCategoryCollapsed

I can see that it expects an object with name and type properties. If I call it in such a way then it works as expected ?

If I wanted to collapse e.g. the "Graphics" category (as shown in the picture at the top) then this is how I could do it:

const panel = viewer.getPropertyPanel();
panel.setVisible(true);
panel.setCategoryCollapsed({name: "Graphics", type: "category"}, true);

 

Related Article