0

I am trying to link part id's to PDF pages. At the moment I am test linking them by:

const page = results[0].selection[0] % 100;

Each part ID does now link to a page. However, it only works when I click on a part -> click off the part -> then click on another part. If you try to switch between parts it doesnt show the pdf.

I think there is something wrong with the pdf#page part. As I can switch between parts if I change the code and dont link to a page.

I noticed that the same issue happens on the demo: https://forge-digital-twin.autodesk.io/

Any ideas on how to solve this?

Many thank, Poppy

Here is my code:

function initDocument(facility) {
    // Only enable when exactly one part is selected
    const $alert =  $('#maintenance-docs div.alert');
    $alert.show();
    $('#maintenance-docs embed').hide()
    $('#maintenance-docs > .show-based-on-selection').hide();
    NOP_VIEWER.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT, function(ev) {
        const results = NOP_VIEWER.getAggregateSelection();
        if (results.length === 1 && results[0].selection.length === 1) {
            $alert.hide();
            const page = results[0].selection[0] % 100;
            console.log(page);
            $('#maintenance-docs > .show-based-on-selection').show();
            $('#maintenance-docs embed').attr('src', `/resources/Operation-manual-Sigg-Plant.pdf#page=${page}`).show();
            //$('#maintenance-docs embed').show();
        } else {
            $alert.show();
            $('#maintenance-docs > .show-based-on-selection').hide();
            $('#maintenance-docs embed').attr('src', '');
            //$('#maintenance-docs embed').hide();
        }
       
    });
    
}
Poppy
  • 5
  • 2
  • I don't see this code being used anywhere in the https://github.com/petrbroz/forge-digital-twin repo. Are you perhaps referring to a different sample code? – Petr Broz Feb 11 '21 at 09:54
  • Sorry for the confusion. I purely meant that the forge-digital-twin live demo has the same issue, where you cannot view the maintenance instructions if you click on one part after another. You must click off the part (and onto the background) and then click a part again. – Poppy Feb 11 '21 at 10:09
  • I've updated the forge-digital-twin sample code to always de-initialize the maintenance docs when selection changes: https://github.com/petrbroz/forge-digital-twin/commit/3984797a590ffa89b1fcf58f75651046b8840161. – Petr Broz Feb 11 '21 at 11:53
  • Perfect! I will take a look, thank you! – Poppy Feb 12 '21 at 12:22

1 Answers1

0

Try with

Autodesk.Viewing.SELECTION_CHANGED_EVENT

Inside the event function keep same functionality.

varunpatil
  • 428
  • 1
  • 3
  • 6