This repository demonstrates how to embed Forge Viewer inside Power BI report by custom visual
- Forge Account: Learn how to create a Forge Account, activate subscription and create an app at this tutorial. Get Forge client id, Forge client secret.
- Prepare a source model and translate with Forge web services by other Forge Viewer samples. Verify it can be loaded in a general web app successfully. Make a note with its URN.
- Switch to the project forge-model-properties-excel. Install the packages
- Input Forge client id, client secret, Forge bucket key, model urn in the environment or config file.
- In line 55 of index.js, ensure which properties you want to extract. The default are dbid and material. You may check the correct property name of your model firstly.
- Run the script (or start debugging)
Node index.js
- After a while, one excel file will be available in the root folder of the project. The time depends on the size of the model properties json. If large file, it may take more time.
- In Power BI app, import the excel file as data source.
- Create report from the data source. Insert one table view, selecting dbid and material from field view. Note: please switch dbid type to Don't Summarize
- Insert one pie chart, selecting material as Legend and material count as Values.
-
Follow the steps to setup environment of PowerBI custom visual. Note: install pbiviz 2.5.0. And install certification with the help document.
npm i -g [email protected]
-
Follow the tutorial to create a new project of custom visual and test/debug it in PowerBI.
-
Ensure to create an SSL certificate
-
Switch to the project forgePowerbiView. Install the packages.
-
Prepare 2legged token for loading model in Forge Viewer
a. Manually generate a token by other tool. Input token and URN to the file visual.ts line 11
b. OR, prepare a custom endpoint on your server for generating token on demand. see visual.ts line 8 In the endpoint, please enable Access-Control-Allow-Origin .The code below is a demo in my local server, which is based on the sample of LearnForge tutorial
// GET /api/forge/oauth/token - generates a public access token (required by the Forge viewer). router.get('/token', async (req, res, next) => { res.header("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); try { const token = await getPublicToken(); res.json({ access_token: token.access_token, expires_in: token.expires_in }); } catch(err) { next(err); } });
-
build the project by the script below
pbiviz package
Note: if you want to use some latest methods of Forge Viewer, yet the typeScript class has not defined them, you may try to manually add them to index.d.ts.
```
node_modules/@types/forge-viewer/index.d.ts
```
The distributed file *PowerBI_ForgeViewer_Visual.pbiviz will be generated at dist folder. Load the visual package in Power BI visuals box. Insert one instance, select dbid from fields. It will take some time for the custom visual to load the model in Viewer.
- Or, run the script below will start debug mode. Ensure the developer model is enabled with your PowerBI account. Insert an instance of developer visual. Select dbid from fields.. Similarly it will take some time for the custom visual to load the model in Viewer.
pbiviz start
- Insert a table visual, selecting all columns of the data.
- Insert an instance of Pie Visual, selecting Material as , and Material count as value.
- Click one row of table view, the corresponding single objects in Forge Viewer will be isolated. Select a material in pie view, the corresponding group of objects in Forge Viewer will be isolated.