Search code examples
autodesk-forgeautodesk-viewerautodesk-model-derivative

How to interact with spaces in Forge same as with elements?


I want to focus on a space like focus on an element given an id or GUID. I want some geometrical representation of the space such in Revit either in 3D or 2D. Some geometrical element that represents the space or room. To select, focus, hide, get properties, etc.

I can show all the elements that are in the space as a way to show the space in the model, but I do not want it because I want to interact with it and have the information related to the space or room.

Does this exist in Forge?


Solution

  • There is no difference between interacting with Revit rooms and normal objects. The APIs will be called are the same.

    Here is an example of getting rooms data used in https://aps.autodesk.com/blog/move-viewers-camera-rooms

    sync getRoomData() {
        const getRoomDbIds = () => {
            return new Promise((resolve, reject) => {
                this.viewer.search(
                    'Revit Rooms',
                    (dbIds) => resolve(dbIds),
                    (error) => reject(error),
                    ['Category'],
                    { searchHidden: true }
                );
            });
        };
    
        const getPropertiesAsync = (dbId) => {
            return new Promise((resolve, reject) => {
                this.viewer.getProperties(
                    dbId,
                    (result) => resolve(result),
                    (error) => reject(error),
                );
            });
        }
    
        const data = [];
    
        try {
            const roomDbIds = await getRoomDbIds();
            if (!roomDbIds || roomDbIds.length <= 0) {
                throw new Error('No Rooms found in current model');
            }
    
            for (let i = 0; i < roomDbIds.length; i++) {
                const dbId = roomDbIds[i];
                const propData = await getPropertiesAsync(dbId);
    
                data.push({
                    id: propData.externalId,
                    dbId,
                    name: propData.name
                });
            }
    
        } catch (ex) {
            console.warn(`[RoomListPanel]: ${ex}`);
            throw new Error('Failed to extract room data');
        }
    
        return data;
    }
    

    And another one of Creating a section box among rooms' bounding box:

    However, here are some pre-requesties:

    • To show Revit rooms in 2D views, you must create Color Schemes for rooms/spaces/area. (use non-white colors)
    • Revit rooms are visible in 2D views only. To see it in 3D views in the viewer, you must request and load the master views in the viewer. You can find my explanations here: https://www.youtube.com/watch?v=GgW9gBCRrWg