The Building Coder

Need to Commit Twice, Roomedit3dv3 and Forge

Lots of exciting news for today, like every day, once again on the pure Revit API, connecting the desktop and the cloud, and Autodesk Forge:

Isolating an Element in a Newly Created View Requires Two Transactions

The aim of isolating an element in a newly created view was discussed by Tuuletin, Revitalizer, Scott Wilson, FirstJet and Michal-sk in the Revit API discussion forum and resolved by an interesting workaround discovered by Michael Morris, Principal Engineer of the Revit development team.

This is another example in the series of situations with a special need to regenerate and handling transactions and transaction groups:

Question: My isolation of an element in a newly created view does not work.

I do the following:

  1. I have a set of elements to isolate els = System.Collections.Generic.List(ElementId).
  2. Then a view is created: view = ViewSection.CreateSection(doc, viewFamilyTypeId, BoundingBox).
  3. After that I try to isolate els: view.IsolateElementsTemporary(els).

If I open this view, the isolation mode is on (light blue frame is on), but nothing from els is isolated. The other view parameters (via get_Parameter) are accessible and writeable.

On the other hand, view.IsolateCategoriesTemporary() works fine!

What's the problem?

Answer: Perhaps you need a call to document.Regenerate or uiDocument.RefreshActiveView?

Response: No, this doesn't help.

More peculiarity: the 'reverse' method, View.HideElements, works perfectly!

Now, I see no other way to solve my task.

The first collector will include any element in model (including links).

The second collector will include elements to be isolated.

The third collector consists of the first collector with the excluded second collector.

Then, I just hide any element I don't want to be isolated by means of the third collector.

Seems like a very bad way to evade this bug...

Answer: Are the elements actually visible in the view if you don't enable the isolate?

Response: Yes, they are visible.

I create a new view (so, any graphic settings are set to default — all elements are visible), then I want to isolate some elements in this created view...

I have stopped seeking the solution. Maybe it is just a lack of the Revit 2015 API. Hope, this will be fixed in later versions.

Question 2: I would like to re-open this issue. It is still happening in Revit 2017. I have created a simple test case with macros embedded to show it in isolate_element_in_new_view.rvt:

Answer: I escalated this thread to an ADN case 12169975 [Isolate elements on a newly created view] and created an internal development issue REVIT-99069 [Isolate elements on a newly created view -- 12169975] for the development team to take a closer look. They say:

I can reproduce this issue. When just 1 transaction is used to create the new view and also to isolate the element, then the isolate element fails.

However, I can get the desired behaviour using two separate transactions as follows:

Is this an acceptable workaround?

Note: I also tried the attached file and macros in our internal development release cannot reproduce the behaviour there.

I tested macro test 2 which uses just 1 transaction to create the new view and isolate the wall, and when the screen updates the single wall is really and truly isolated in the new view.

So the workaround described above will not be needed forever.

Also, it appears the real issue here is that isolate element only works in the active view. For example, edit macro testOne to NOT activate floor plan Level 1. In the UI, open views Level 1 and Level 2 side by side, but make Level 2 be the active view. Run macro testOne. Notice that Level 1 view is not updated and the wall is not isolated.

So you need to activate the view before doing IsolateElementTemporary.

In fact, this appears to be needed for all uses of IsolateElementTemporary, regardless of if the view is newly created or not.

Response: Thanks for the work around.

I tried two transactions myself as well before, but it didn't work then.

The trick is, as you guys described, to set the active view to the new created view.

Here is the working snippet for those interested:

public void testTwo( UIDocument uidoc )
{
  Document doc = uidoc.Document;

  View newView;

  usingTransaction t = new Transaction( doc ) )
  {
    t.Start( "Trans" );

    // Get Floorplan for Level1 and copy its 
    // properties for ouw newly to create ViewPlan.

    View existingView = doc.GetElement( 
      new ElementId( 312 ) ) as View;

    // Create new Floorplan.

    newView = doc.GetElement( existingView.Duplicate( 
      ViewDuplicateOption.Duplicate ) ) as View;

    t.Commit();

    // Important to set new view as active view.

    uidoc.ActiveView = newView;

    t.Start( "Trans 2" );

    // Try to isolate a Wall. Fails.

    newView.IsolateElementTemporary( new ElementId( 317443 ) );

    t.Commit();
  }

  // Change the View to the new View.

  uidoc.ActiveView = newView;
}

It somewhat sucks having to commit twice and therefore having to regenerate twice. But the workaround is solid and does the job. Thanks guys!

Many thanks indeed to everybody involved in this exploration, especially to Michael for his in-depth research and effective workaround!

Forge Research Enquiry

An example of the many daily requests I receive and try to solve as efficiently and publicly as possible.

I am sorry that I cannot answer each issue in private and thank you for your understanding!

Question: I am conducting research related to Autodesk Forge and how we can collaborate with it.

I have several questions with regard to Forge.

Can we arrange a Skype conversation?

Answer: I avoid one-on-one conversations where possible, since most questions I encounter are of general interest to a large number of people.

Could you please first of all consult the existing online documentation, and then formulate your questions you have in writing?

With your concrete questions in hand, I will happily take them up with you personally or direct you to one of my colleagues.

Thank you for your understanding!

Response: I have already checked the websites. Here are my questions:

  1. Since the Forge platform is a set of cloud services: if I am developing an application for the desktop, e.g., Revit or NavisWorks, will this mean that the Forge Platform will not be relevant?
  2. Could you give some examples of companies/and apps that utilize the Data Management API? By using this API, can I access data from Revit via A360?
  3. Can the Model Derivative API translate the design into IFC format? Does it support IFC 4? Does it support the buildingSMART International standards for Model View Definitions, like reference view, design transfer view etc.?
  4. Can the Viewer render only SVF file format?
  5. Can you apply for the Forge Funding only if you are building apps using the Forge platform web services?

Answer: Thank you very much for your pertinent questions.

I discussed them with my colleagues, and we put together the following answers for you:

  1. Forge may be extremely important for a Revit or NavisWorks add-in or other desktop application. For instance, if your Revit add-in needs to use A360, or connect with any of your own or the Autodesk or other web services, Forge may be very important indeed. The number of web services is growing daily, and you should urgently consider implementing your own functionality along those lines as well. That is the whole point of my presentation on freeing your BIM data that I held at the Forge Developer Conference in June. You may want to make use of cloud services to address a larger audience with your application, and yet connect it back to the Revit BIM, cf. my newest sample on connecting the desktop and the cloud.
  2. If a CAD model is uploaded to A360 in a way that the references can be resolved, so it becomes viewable in the A360 UI, then it can be translated into SVF as well (in A360 this happens automatically), which will also trigger property generation for it that can be accessed through the Model Derivative endpoints as well as from the Viewer. Anyone uploading a file to translate for the viewer is using the Data Management API. Uploading a file is a necessary part of the translation service. Look at the Forge samples on GitHub and the Forge DevCon presentations:
  3. Not yet. The other way around is supported, IFC to Forge. We are in the process of adding IFC support to the MD API right now. Revit itself offers IFC4 support. What that means right now is:
  4. SVF for 3D and F2D for 2D views. The render format depends on the input format and its extension (obj, glTF, etc.). Different formats may interact slightly differently in the viewer regarding selection, metadata, etc. The viewer is primarily intended to read the single file format (what we generically refer to as SVF for both 2D and 3D models). The Model Derivative API allows you to convert all other formats into SVF. The viewer is not intended to be a standalone multi-format viewer – it is intended to be used in conjunction with the Model Derivative API.
  5. You can apply without necessarily using Forge API. You should definitely mention what Forge APIs and how you are planning to use them.

I hope this helps.

Connecting Desktop and Cloud – Roomedit3dv3 Live

On popular request, here are the various upcoming events at which I will be presenting on the topics of freeing your BIM data and Connecting the desktop and the cloud with a live roomedit3dv3 demonstration:

I hope to be able to meet you in person at one of these.

Could You Demo this Remotely?

I completed the roomedit3dv3 project and published a demo recording to show it in action.

One response via twitter includes another request for a non-public answer, which I am sorry to say I am unable to satisfy:

Question: Would you be willing to demo this remotely via web, maybe 45 mins...?

Answer: I would love to if I had the time to spare.

Unfortunately, I am rather busy trying to answer as many questions as possible for the whole community.

Therefore, I always prefer to discuss everything I do in public and enable the entire community to contribute and share when possible.

Here are the most effective ways to see the demo live and explore it in further depth yourself:

  1. Attend one of the demos at the upcoming public events listed above.
  2. Try it for yourself at home; that is probably the most effective approach of all. You can fork, clone, compile and install the Roomedit3dApp Revit add-in and either run my existing web instance roomedit3dv3, or get your own Autodesk forge app credentials and use those to deploy your own Heroku instance.

As I keep saying all too often now, please ask all your questions in public, e.g., Revit API related ones in the Revit API discussion forum and all Forge related issues on StackOverflow.

Connecting Desktop and Cloud Draft Handout

I completed an initial version of the handout document for my presentation on connecting the desktop and the cloud at the RTC Revit Technology Conference Europe in Porto the week after next.

Here is the complete PDF handout document s1_4_hand_connect_desktop_cloud_jtammik.pdf.

For your convenience, I extracted this sneak preview of the class description and table of contents:

Session 1.4 – Connecting any Desktop Application or Revit Add-in with Autodesk Forge and the Cloud

Class Description: We discuss the opportunities and advantages offered by accessing and interacting with BIM from the cloud, using both open source and Autodesk Forge web services and cloud-based APIs. We show how they can be accessed and used from any desktop application, including your Revit custom add-in. This provides access to powerful functionality to design, visualise, collaborate, make and use BIM and other CAD data. I present a Forge overview and my suite of examples connecting the desktop and the cloud, culminating in the newest 3D Forge round-trip real-time room editor.

Table of Contents:

I hope this is of interest and use to you!

Now I am really looking forward to a week's vacation before RTC!

RTC Europe 2016