Hours of frustration. So I have all these great plans to develop my “click here and view in Navisworks” ideas. Dozens of good plans and I am thwarted by it only running once. Googling, there are other people with other apps that “only work once” when you are connecting to RUNNING instances of them via ActiveX.
Bottom line: when using GetObject “Navisworks.Document.10”) and ensuring you can connect to the 2nd, 3rd, 4th, etc. times, you have to choose ‘document.StayOpen’. This sets a special flat in the ROT table (keep reading) to tell it not to go away when you are done with it. You application wil LOOK like it is running and it is, but the reference to it being ‘grab-able’ is gone. Microsoft applications have Application.UserControl = True, which does the same thing, this (on hour #3 of researching what was going on) inspired me to see if navisworks had anything. Nope, nothing – it didn’t work – EXCEPT for the StayOpen is not a property but a method that sets this flag to True. Holy smokes – it all works and every time now. I CAN COMPLETE MY DREAMS I HAVE IN MY HEAD NOW!!! The motivation, is that we have to give a presentation to the customer’s VP. No pressure 1 week before we are doing this. I will be working the weekend to impress the client’s VP and having a job for the next little while.
Links and learning to follow – you can stop reading now if you wish.
So bottom line, thedocument.StayOpen method – and do this after Document.Visible = True. Yes all the documentation is there, it is just hidden under 20 layer of bare bones API documentation or .chm file ON YOUR HARD DRIVE under the API directory for Navisworks.
Ok – this might seem obvious, but it isn’t because I did a whole 2 days worth of investigations with really bad spaghetti code. When I cam in after the weekend to make this slick class-based awesomeness – NOTHING WORKED. So something had that flag turned on to strong and I know why in hindsight.
Does anyone else have this issue? Yes – lots of people and not necessarily Navisworks Simulate 2013 (or roamer.exe) – but all sorts of apps
- Navisworks example with my reply after I got it working.
- Registering items in the ROT – I wondered can I re-register it a few times each time I ran it to make it know I was still interested the “next time”
- there is a flag called weak or strong – and it not being a strong ROT entry is what was messing me up here and other people in other apps. The weak entry is the default entry (really!?) yes.
- How to look at the existing ROT . I made my own c# code to see what was in the ROT table. I CAN SEE IT DISAPPEAR. This article gave me hope.
- even the cool c++ kids could do it … therefore so can I (except c++ gives me a headache)
- What is the MS Office “User control’ property – holy smokes! … does Navis have one of these too? Crap- it does -oh look there is the (*)&$# documentation saying it does – hidden under 20 layers of bare bones API documentation. Just to rub salt into the wound, other cool kids already are using it too.
Well, I am smarter now. So knowing about and understanding the ROT (Running Object Table) and it hails from COM days long ago when I didn’t do this stuff, was key to understanding my issue. That is where the getObject goes to see the GUID of the English “Navisworks.Document.10” class. You can do a find in Regedit of this Class GUID to see how all this fits together (it is like a DNS for windows). If is sees it, it grabs it and you can control it. Excel has it, Word has it, PPT has it, AutoCAD has it etc, etc. etc. BUT … each item in the ROT table when it is created can be created with a weak or strong reference. Using .StayOpen after a .Visible on the Navisworks document object sets it to a strong one and that instance of Navis will be available for automation every time.