Validate Roof Type and View OBJ on Android

I spent some time exploring how to view the output generated by the OBJ exporter on an Android tablet.

Viewing an OBJ Model on Android

That proved to be easy. I installed the KiwiViewer open-source visualization app, which supports OBJ, and used Dropbox to upload the OBJ export of my Revit model to the Internet, from where I could access it on the tablet from anywhere. Anywhere with a wifi Internet link, that is.

It works fine as far as the pure geometry defined in the OBJ file is concerned. Unfortunately, the separate MTL material file was ignored, eliminating the colour and transparency information.

The viewer displays other models with colour and other rendering information perfectly well, so I'll explore how those are defined appropriately next.

Alternatively, I'll have to implement my own viewer. That may be the easiest route to go in order to achieve something useful, since that will soon require identifying the original Revit elements in the viewer, e.g. to communicate information from the tablet device back to the original Revit model. For example, I might want to pick a building element and add a comment to it on the tablet, then have that information integrated back into the original document. I hope to look at something like that soon.

Validate the Roof Type Compound Structure for the Little House

I also happened to run the 'little house' command provided by the Xtra ADN training labs again and was a bit surprised that the roof did not appear as expected.

Exploring the resulting model in more depth, I notice that the roof was in fact being created successfully, but was not visible in the graphic view.

I tracked it down to the roof type being used. The sample just picks the first roof type encountered, which happened to be 'sloped glazing'. This type has zero entries in its compound structure, or even worse, no compound structure defined at all.

After adding a check for a valid compound structure to the type selection code, the roof appeared again:

Little house 3D view

Here is the plan view as well, although that does not show the roof, of course:

Little house plan view

This is the code checking for a valid compound structure in the list of roof types returned by the filtered element collector, then creating the roof and adding the slope to it:

  // Add a floor, a roof and the roof slope:
  bool structural = false;
  Floor floor = createDoc.NewFloor( 
    profile, structural );
  List<Element> roofTypes 
    = new List<Element>( 
        doc, typeof( RoofType ), 
        BuiltInCategory.OST_Roofs ) );
  Debug.Assert( 0 < roofTypes.Count, 
    "expected at least one roof type"
    + " to be loaded into project" );
  // Ensure that we get a valid roof type. 
  // In Revit 2013, the first one encountered 
  // is sloped glazing with zero entries in
  // its compound layers; actually, the entire
  // compound structure is null:
  RoofType roofType = roofTypes
      t => null != t.GetCompoundStructure() );
  ModelCurveArray modelCurves 
    = new ModelCurveArray();
  FootPrintRoof roof 
    = createDoc.NewFootPrintRoof( profile, 
      levelTop, roofType, out modelCurves );
  // Regenerate the model after roof creation, 
  // otherwise the calls to set_DefinesSlope and 
  // set_SlopeAngle throwing the exception "Unable
  // to access curves from the roof sketch."
  // The argument to set_SlopeAngle is NOT an 
  // angle, it is really a slope, i.e. relation 
  // of height to distance, e.g. 0.5 = 6" / 12", 
  // 0.75  = 9" / 12", etc.
  double slope = 0.3;
  foreach( ModelCurve curve in modelCurves )
    roof.set_DefinesSlope( curve, true );
    roof.set_SlopeAngle( curve, slope );

Here is containing the complete source code, Visual Studio solution, and RvtSamples include file to load my version of the ADN Revit API training labs including the additional commands defined by the Xtra projects, among them the little house creation lab described above.

Updated ADN Revit API Training Material

This ties in very nicely with another little item: as Mikako just pointed out on the AEC DevBlog, the Revit API 2013 training labs material on the Revit Developer Center in the public Autodesk Developer Network site has been updated and is available for download in the 'Samples and Documentation' section. Here is also a direct link to it.

As Mikako points out, this is the material that we use for classroom trainings. If you know the basic of .NET programming and are interested in learning the Revit API, it also provides a good starting point for self-learning, since both source code and documents describing the steps to perform are included.