Warm tip: This article is reproduced from serverfault.com, please click

How do you collapse a category in PropertyPanel in Forge Viewer v7?

发布于 2020-12-01 20:23:46

I'm using the Forge Viewer to display properties on selected items in my model.

When an object is selected, I want to automatically show the properties panel but keep a category collapsed. Here's the code I'm using in an attempt to achieve this:

        viewer.addEventListener(
          Autodesk.Viewing.SELECTION_CHANGED_EVENT, 
          () => {
            const panel = viewer.getPropertyPanel();
            panel.setVisible(true);
            panel.setCategoryCollapsed("Category Name", true);
          },  
        );

The event is raised and the panel is shown, however, the function setCategoryCollapsed does not work (understandable as it was last documented in v5). Is there a similar function in v7 to collapse a category?

Questioner
mertcanb
Viewed
0
Adam Nagy 2020-12-02 22:26:08

That function expects an object with name and type properties - e.g. if I wanted to collapse the "Graphics" category, I could do it like this:

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

Have also just written a blog post about it now: Collapse category in the Property Panel