Outside the Box

check out command-line sample

Wil Maier
iTwin.js
3 min readDec 16, 2019

--

Updated on: March 2, 2020

“How can you sign-in without a dialog?”

Any app that connects to the iModelHub needs to present a sign-in dialog. But what if you just want to write a command-line app to perform a query?

My colleague was trying to solve a similar dilemma. His imodel-unity-example communicates with a command line app. He was trying to update the app to interact with iModelHub but faced the same sign-in issue. As this has already been deployed for use with Microsoft HoloLens and VR headsets like Oculus Rift, HTC Vive, and Oculus Quest, it has gotten a lot of attention.

I wonder what kind of model she is looking at!

So how could apps like this sign-in and browse for a model in iModelHub without having a frontend?

I wasn’t sure this was going to be possible.

All we had to work with was an existing app that we could scavenge for the necessary UI code. But how could we popup a sign-in dialog and return the authentication token?

Hmm. This was going to take some creative thinking!

The concept we finally came up with was to build the dialog as an electron app. If you are not familiar with electron, it allows you to package and run a web app as a desktop app. Now we had a plan! This could allow us to create a popup dialog in a separate process, return the needed information to the app, and then close it.

Anyway, after proving that we could return a sign-in token from one app and use it for authentication in another app, we knew it could be done!

Once we finished developing this popup app, we packaged it so that it could easily be installed and integrated as an npm package in any Node.js app.

And here you see it in action:

The happy ending to this story is that we have decided to make this iModel selector utility available to anyone that needs it. For example, it could enable you to write a command-line app to query an iModel and produce a report. That’s exactly what the included sample does.

To use iModel Selector, all you need to do is call a function with a few parameters:

It will open the popup dialog and once it has completed, it will return the authentication string and model id needed to open an iModel.

If you are ready to jump in, checkout this sample command-line app to see how easy it is to use.

Happy coding!

<- previous post | home | next post ->

--

--