Vertical Dimensioning and Revit API QAS Research

Today, I highlight yet another interesting Revit API discussion forum thread and list my ongoing research links on implementing a Revit API question answering system:

Creating Vertical Dimensioning

A summary of the discussion thread on how to create dimension line that is not parallel to detail line, answered by Fair59:

Question: I am trying to create a dimension line that measures the Z component of a sloped detail line.

I can do this manually in the Revit user interface but cannot figure out how to do it with the API.

I've used RevitLookup to compare the differences in the dimension lines.

The ReferenceArray is the same; the main difference seems to be the Curve property which I'm assuming is set with the Line property when I call NewDimension(Section, Line, ReferenceArray).

Here is my current (failing) code:

  XYZ point3 = new XYZ( 417.8, 80.228, 46.8 );
  XYZ point4 = new XYZ( 417.8, 80.811, 46.3 );

  Line geomLine3 = Line.CreateBound( point3, point4 );

  //Plane geomPlane = new Plane( XYZ.BasisX, XYZ.Zero ); // 2016

  Plane geomPlane = Plane.CreateByNormalAndOrigin( 
    XYZ.Zero, XYZ.BasisX ); // 2017

  usingTransaction tx = new Transaction( doc ) )
  {
    tx.Start( "tx" );
    SketchPlane sketch = SketchPlane.Create( doc, geomPlane );

    DetailLine line3 = doc.Create.NewDetailCurve( 
      viewSection, geomLine3 ) as DetailLine;

    ReferenceArray refArray = new ReferenceArray();
    refArray.Append( line3.GeometryCurve.GetEndPointReference( 0 ) );
    refArray.Append( line3.GeometryCurve.GetEndPointReference( 1 ) );
    XYZ dimPoint1 = new XYZ( 417.8, 80.118, 46.8 );
    XYZ dimPoint2 = new XYZ( 417.8, 80.118, 46.3 );
    Line dimLine3 = Line.CreateBound( dimPoint1, dimPoint2 );

    Dimension dim = doc.Create.NewDimension( 
      viewSection, dimLine3, refArray );

    tx.Commit();
  }

The line I'm sending into NewDimension is along the Z axis, but the dimension line I'm getting back is sloped parallel to the detail line and gives the length of the entire detail line when I want just its Z component. Using RevitLookup, I see the Curve Direction has non-zero components for both Y and Z: (0, 0.759, -0.651). When I create the line I want in Revit manually, the Curve has a Direction of (0, 0, 1) and gives just the length of the Z component of the sloped detail line.

Here is an image of the section with the sloped detail line at the bottom right. It shows the dimension I created with the API (labelled with length of 0' - 9 7/32") and the one I created manually that I want to create with the API (labelled as 0' - 6"):

Creating vertical dimensioning

I think I am in the correct plane. I am in the Y-Z plane with the X axis perpendicular to the plane and trying to measure a dimension in the Z direction. This works with a detail line that has end points with the same Y or Z coordinate, but is not working with the detail line with end points with different Y and Z coordinates, although the X coordinates are the same, so still in the Y-Z plane.

I did more debugging in the code and found that the Dimension object returned by doc.Create.NewDimension is correct and what I want. For example, it has the value string of "0' - 6\"" which is the length of the detail line in the Z direction as I expect. But after the call to Transaction.Commit, the Dimension object changes. For example, the value string changes to "0' - 9 7/32\"", which is the total length of the detail line.

So, the call to Transaction.Commit is changing the Dimension object and forcing the dimension line to be parallel to the detail line. I tried setting the Dimension property IsLocked to true before calling Commit, hoping that would fix the problem, but that does something even more odd. Here is an image to showing the new output, which has a line with the correct value string but parallel to the detail line instead of only in the Z direction:

Creating vertical dimensioning

Answer: I examined your code and see that you are not using the geomPlane variable.

I found this method that will result in a "stable" dimension with a correct direction and value:

  XYZ point3 = new XYZ( 417.8, 80.228, 46.8 );
  XYZ point4 = new XYZ( 417.8, 80.811, 46.3 );

  Line geomLine3 = Line.CreateBound( point3, point4 );
  Line dummyLine = Line.CreateBound( XYZ.Zero, XYZ.BasisY );

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

    DetailLine line3 = doc.Create.NewDetailCurve( 
      viewSection, geomLine3 ) as DetailLine;

    DetailLine dummy = doc.Create.NewDetailCurve( 
      viewSection, dummyLine ) as DetailLine;

    ReferenceArray refArray = new ReferenceArray();
    refArray.Append( dummy.GeometryCurve.Reference );
    refArray.Append( line3.GeometryCurve.GetEndPointReference( 0 ) );
    refArray.Append( line3.GeometryCurve.GetEndPointReference( 1 ) );
    XYZ dimPoint1 = new XYZ( 417.8, 80.118, 46.8 );
    XYZ dimPoint2 = new XYZ( 417.8, 80.118, 46.3 );
    Line dimLine3 = Line.CreateBound( dimPoint1, dimPoint2 );

    Dimension dim = doc.Create.NewDimension( 
      viewSection, dimLine3, refArray );

    doc.Delete( dummy.Id );
    tx.Commit();
  }

Response: This solved the issue. I was able to adapt it to get the Y dimension of the sloped line as well. Thank you for the solution!

I wonder what happens if you delete the dummy line... will the stable reference remain? Probably not...

More Research on a Revit QAS

Back to my favourite current 'hobby' topic.

As I already reported, I would like to implement a question answering system for the Revit API and all aspects of Revit API usage and add-in programming:

Here are some new additions and further steps in my exploration:

QnA Maker

Matt Taylor added a comment to the last post, pointing out the Microsoft QnA Maker service that supports you in building, training and publishing a simple question and answer bot based on FAQ URLs, structured documents or editorial content in minutes:

I posted another comment on your last AI post that you may have missed. This is the link I thought would be of interest: Microsoft's new service turns FAQs into bots. Good luck with your quest!

Checking out further related news, I also noticed:

Yes, these do indeed look similar to my goal.

It seems I am on to a hot topic here...

First Steps with DeepDive

I installed Stanford DARPA DeepDive, ran through its tutorial and looked at some related papers:

The spouse_example used in the DeepDive tutorial and other examples I have seen so far don't look much like Q & A to me, so I took another look at alternatives.

YodaQA, DL-Learner and OWL

At a certain point, I went back to exploring alternative open source answering systems to see whether some other system might be more accessible:

DL-Learner sounds very much like what I need... this led me deeper into ontology again:

After a deeper look, it seems like an ontology might possibly be an overkill.

At least, it is insufficient on its own to implement a complex answering system.

Such as system would seem to require more generic, complex and fuzzy reactions than a pure ontology based one can provide.

I do not need to ask hard facts, like 'what is a ModelLine?'

I need fuzzier stuff like 'how do I set the view direction of a 3D view?'

Something like this looks like a good mix, but a bit dated:

Looking again at YodaQA, I see that it clearly states support for all three data source types: full text, database and ontology. That sounds perfect for my purposes, so I went ahead and followed the YodaQA installation instructions. Unfortunately, I have not yet been able to get an answer from the system, because it times out accessing the YodaQA system author's knowledge base in Prague.

In fact, two existing YodaQA GitHub issues pretty precisely match my needs:

Also, just a few days ago, Charles Miller asked about Using YodaQA with a non-Wikipedia source to implement a closed-domain QAS:

Has anyone used YodaQA for natural language processing? How easy is it to link to a document database other than Wikipedia?

We're thinking we can create a bot to use AI to analyse our developer and user documentation and provide a written or spoken answer in reply. YodaQA comes linked to Wikipedia for starters, but we'd need to link to our own source info. I'm trying to get an idea of the development time required to set up the AI and then to link to the database.

I am eagerly awaiting an answer to that question as well...

My Current Open Questions on Question Answering Systems

So, all in all, I am currently exploring both DeepDive and YodaQA. Both seem promising and not completely straightforward to use, expand, or adapt to a closed domain.

Here the main question I currently have and would love to hear an answer on:

Some obvious follow-up questions arise:

Let me reiterate the raw information sources available:

The mapping between these raw sources and the target knowledge base components appears obvious to me: