Request

Response

    Autodesk.Viewing
    Version 8 preview
    This page documents a preview of the Viewer SDK v8. APIs and content can still change before the final release.

    AggregatedView

    AggregatedView implements a viewing application based on Viewer3D. Its purpose is to provide functionality around Viewer3D to facilitate implementation of viewer application workflows like switching between different views or toggling models on/off dynamically.

    Examples of AggregatedView functionality include:

    1. Facilitate use in react: Just set an array of nodes from React property and AggregatedView takes care to make sure that models are loaded and shown/hidden as needed.
    2. LRU-Caching of models: Keep models in memory for fast switches, but unload unused models if memory is critical
    3. Extensions: Setting up a couple of useful default extensions (can be customized or switched off where wanted)
    4. Home camera: Setting a home view camera that considers multiple models.
    5. Application State management: Facilitates some state management, e.g.

      1. Setting a camera without having to care whether the model is already loaded or not.
      2. Starting Walk-mode without having to care whether BIMWalk extension is already loaded.
      3. Allow toggling visibility of a model without having to care about the loading state of the model.
    6. GlobalOffsets: Choose globalOffset automatically, but identically for all models to make sure that they are placed consistently.
    7. View Switches: Allow visibility toggling (hide/show) versus full view switches (switchView(nodes)), the latter including proper reset of camera, UI, and extensions
    8. Diff Setups: Just set diffOptions to setup change visualization of aggregated views.

    new AggregatedView()

    Examples

    const view = new Autodesk.Viewing.AggregatedView();
    // Initialize the aggregatedView with the HTML element and the options object
    await view.init(viewerElement, options);
    

    Methods

    init(parentDiv, options)

    Initializes the AggregatedView and loads the following predefined extensions: Autodesk.CrossFadeEffects, Autodesk.AEC.LevelsExtension, Autodesk.ModelStructure, Autodesk.AEC.HyperlinkExtension, Autodesk.AEC.Minimap3DExtension, Autodesk.AEC.CanvasBookmarkExtension and Autodesk.AEC.DropMeExtension The initialization can also be customized with the options object.

    To initialize the viewer without loading the specified extension please reference initViewerInstance.

    Parameters

    Expand all
    parentDiv*
    HTMLDivElement
    The div element in which the viewer will be initialized
    options
    Object
    Configuration options for aggregated view
    viewerConfig
    Object
    Used for initializing GuiViewer3D. This is the options object that is passed into either Viewer3D or GuiViewer3D
    disableBookmarks
    boolean
    Disable display of visual bookmarks
    clusterfck
    Object
    Dependency-Injection of clusterfck library (enables clustering of Bookmark icons)
    viewerStartOptions
    Object
    Options passed to the viewer initialization process
    ignoreGlobalOffset
    boolean
    Forces globalOffset to undefined for all loaded models. Effect of this is that all models are auto-centered using the model bbox. Note that this does only work if you never show more than one 3D viewable at once
    unloadUnfinishedModels
    boolean
    By setting unloadUnfinishedModels, when calling hide(bubbleNode), it will unload models that haven’t been fully loaded. Used in order to reduce amount of file loaders when switching between models
    useDynamicGlobalOffset
    boolean
    If true, the globalOffset is applied dynamically after loading
    cameraValidator
    boolean
    Called with a (camera, model) when using a model camera as start or home camera. This allows for clients to apply optional custom repairs for models with messy camera data
    propagateInputEventTypes
    Array.<string>
    By default, LMV ToolController “eats” all handled events so that they don’t reach any other widgets. Specify an array of event types that you want this behaviour disabled for. For example [‘mouseup’, ‘mousedown’] allows alloy to detect mouse outside clicks to close pending dropdown menus
    createModelAlignmentService*
    function
    Factory function to create AlignmentService implementation for loading/saving model transforms. See AlignmentServices above for details
    getCustomLoadOptions
    function
    Allows for applying custom options to be used for all model loading. The callback returns an options object that is applied by default in all model-load calls. The signature should look like: function(BubbleNode)=>Object
    viewerUnits
    string
    If specified, all models are re-scaled from model units to this unit. Must be a GNU unit format string, e.g. “m”.
    forceWorldUpDirection
    Array.<number>
    If specified, the world up direction is forced to the given vector. Models with different world up directions in the manifest are rotated to align with the given vector. Must be an array of three numbers, e.g. [0, 1, 0].
    multiViewerFactory
    MultiViewerFactory
    Optional multi viewer factory. Used to create multiple viewers with shared resources
    useConsolidation
    boolean
    Optional flag to enable / disable mesh consolidation. Defaults to true.
    * Required

    Returns

    typedescription
    Promise
    • returns a promise once all of the specified extensions are loaded.

    initViewerInstance(parentDiv, options)

    Initialize a new viewer instance.

    To initialize the viewer and load the default extensions please see init.

    Parameters

    parentDiv*
    HTMLDivElement
    The div element in which the viewer will be initialized
    options
    Object
    The same options object that is passed into the init method
    * Required

    reset()

    Resets tools, UI, camera, and refPoint. This method should be called when an explicit view switch occurred instead of just toggling visibility of models.

    getModel(node)

    Finds a model for the given bubbleNode or key. To get all visible models, use viewer.getVisibleModels(). To make sure that the model is loaded reference getModelAndWait.

    Parameters

    node*The Bubble node to use to get the model
    * Required

    Returns

    typedescription
    Model
    • The model that corresponds to the bubbleNode

    Examples

    const nodes = view.getVisibleNodes();
    // Get the model of the first bubble node.
    const model = view.getModel(nodes[0]);
    

    getModelAndWait(node, checkIfVisible)

    Find a model for given bubbleNode or key. If the model is not available yet, wait until it’s ready.

    Parameters

    node*The Bubble node to use to get the model
    checkIfVisible
    Boolean
    If true, will wait until model is also visible
    * Required

    Returns

    typedescription
    Promise
    • the promise resolves once the model is loaded with the model instance

    Examples

    const model = await view.getModelAndWait(node);
    

    isEmpty()

    Returns true if there are no visible bubble nodes.

    Returns

    typedescription
    Boolean
    • returns true if all nodes are invisible

    show(bubbleNode, customLoadOptions)

    Makes sure that a model is loaded and shown

    To get the bubbleNode from a URN please reference Document.load.

    Parameters

    bubbleNode*The node to load and show in the viewer
    customLoadOptions
    Object
    Optional extra loadOptions to override/extend the default ones
    * Required

    Returns

    typedescription
    Promise
    • Returns a promise which resolves with the model

    Examples

    // Load a document from a documentId/URN
    Autodesk.Viewing.Document.load(documentId, (doc) => {
      // Find all of the 3D bubble nodes
      var nodes3D = doc.docRoot.search({ role: '3d', type: "geometry" });
    
      // Using aggregated view load and show the model.
      const model = await view.show(nodes3D[0]);
    });
    
    Show More

    hide(bubbleNode)

    Hides the model associated from the supplied bubble node.

    To show the model reference show.

    Parameters

    bubbleNode*The node to hide in the viewer
    * Required

    Examples

    view.hide(node);
    

    isVisible(bubbleNode)

    Returns true if the supplied bubble node is currently visible.

    Parameters

    bubbleNode*The BubbleNode to check the visibility of
    * Required

    Returns

    typedescription
    Boolean
    • true if the specified node is visible, false otherwise

    hideAll()

    Hide all of the models in the viewer.

    getVisibleNodes()

    Returns all of the visible bubble nodes.

    Returns

    typedescription
    Array.<BubbleNode>
    • An array of all of the visible nodes

    areAllNodes2D()

    Returns true if all of the nodes are 2D.

    Returns

    typedescription
    Boolean
    • returns true if all nodes are 2D, false otherwise.

    isOtgManifestMissing(bubbleNode)

    Checks if the Otg manifest for a 3D viewable is available and complete. If not, it reports an error and returns false.

    Parameters

    bubbleNode*The BubbleNode
    * Required

    Returns

    typedescription
    Boolean
    • true if the OTG manifest is missing.

    load(bubbleNode, customLoadOptions)

    Loads the model that is specified by the passed in bubbleNode parameter. Note this function will not show the model once it is loaded. To load and show the model reference the show method.

    Parameters

    bubbleNode*The BubbleNode
    customLoadOptions
    Object
    Optional extra loadOptions to override/extend the default ones
    * Required

    Returns

    typedescription
    Promise
    • The promise resolves with the loaded model

    unload(bubbleNode)

    Unload the model that corresponds with the passed in bubbleNode.

    Parameters

    bubbleNode*The BubbleNode to unload
    * Required

    Examples

    const nodes = view.getVisibleNodes();
    // Unload the first model
    view.unload(nodes[0]);
    

    unloadAll(itemFilter)

    Unload all of the models that are currently in the view.

    Parameters

    itemFilter
    function
    This callback is used to check if a model needs to be unloaded. This callback recieves an object describing the current view item and it should return a boolean

    Examples

    // This example will unload all invisible models.
    view.unloadAll((item) => {
      return !item.visible
    });
    

    setCameraGlobal(camera)

    Set camera in global coords.

    • The current global offset is automatically subtracted
    • You don’t have to specify all members, e.g., can leave out up or fov. Only defined values are replaced.
    • You can call it independent of loading state: If no model is loaded yet, the camera change is applied after first model add
    • Note that the call only has effect on current view, i.e., is discarded on reset/viewSwitch calls.

    Parameters

    Expand all
    camera*Camera view in global coordinates.
    ignoreGlobalOffset
    boolean
    If true, the current global offset is not subtracted.
    * Required

    setCamera(camera)

    Set the view from the passed in camera.

    Parameters

    camera*Camera view to apply. Note that the passed object may be modified.
    * Required

    startBimWalk()

    Starts the BIM walk tool. Under the hood this method will activate the BimWalk extension.

    stopBimWalk()

    Stop the BIM walk tool. Under the hood this method will deactivate the BimWalk extension.

    isBimWalkActive()

    Returns true if the BimWalk tool is active.

    Returns

    typedescription
    Boolean
    • true if the tool is active, false otherwise.

    switchView(bubbleNodes, diffConfig)

    Switches between bubble node models. This method will reset the view and then set the passed in nodes.

    Use this for explicit view switches. See setNodes() for params.

    Parameters

    bubbleNodes*
    BubbleNode, Array.<BubbleNode>
    The nodes to be shown
    diffConfig
    Object
    see the setNodes method for the diffConfig parameter
    * Required

    Returns

    typedescription
    Promise
    • The promise resolves with the loaded models

    setNodes(bubbleNodes, diffConfig)

    Load/Unload models so that the currently loaded models matches with the given list of svfs.

    Note: Use switchView() to do an explicit view switch (including resetting tools/camera). Use setNodes() to reconfigure which models are visible in the current view.

    Parameters

    Expand all
    bubbleNodes*
    BubbleNode, Array.<BubbleNode>
    The nodes to be shown
    diffConfig
    Object
    Options to activate diff views.
    primaryBubbles
    Array.<BubbleNode>
    A subset of ‘bubbleNodes’ that participates in the diff. If ‘bubbleNodes’ contains more, these will be ghosted. These nodes represent the current/as-is state
    diffBubbles
    Array.<BubbleNode>
    Length must match primaryBubbles. For each node primaryBubbles[i], diffBubbles[i] provides the corresponding “before” state to compare against
    diffIf svfs are sheet nodes, diff.supportModels must provide the bubbleNodes for the corresponding 3D support models. { diff, primary }
    primaryPrimary bubble node to do the diff comparison on
    autoDetect
    boolean
    If true, support models are automatically found - works for Revit models with master views
    * Required

    Returns

    typedescription
    Promise
    • The promise resolves with the loaded models

    isLoadDone()

    Returns true if all pending loading is finished. More concrete, it means that there is no…

    • model-root loading
    • geometry loading, or
    • propDbLoading pending or in progress.

    Reference waitForLoadDone.

    Returns

    typedescription
    Boolean
    • Returns true if all of the models in the view are fully loaded, false otherwise.

    waitForLoadDone()

    Returns a promise that resolves when isLoadDone() returns true.

    Returns

    typedescription
    Promise
    • resolves when all isLoadDone returns true.

    findDiffSupportModel(sheetNode)

    “Support models” are 3D models that augment 2D diffs for better results: Instead of comparing the 2D objects directly, the correspodning 3D counterparts are compared. This is more reliable and avoids false positives due to irrelevant plotting differences. We use master views as support models, because they contain all objects of a given phase.

    Given a bubble node referring to a 2D sheet node, this function returns the bubbleNode of the corresponding 3D master view that belongs to the same phase. This can be used as “support model” to obtain better results for 2D diff.

    Parameters

    sheetNode*A 2d bubble node
    * Required

    Returns

    typedescription
    BubbleNode
    • the coresponding 3d bubble node

    findDiffSupportModels(diffConfig)

    Find corresponding 3D model for each diff/primary The result will be stored in the passed in diffConfig. The results will be in diffConfig.supportBubbles.diff and diffConfig.supportBubbles.primary.

    For the diffConfig parameter reference setNodes.

    Parameters

    diffConfig*
    Object
    see the setNodes method for the diffConfig parameter
    * Required