Ini File, Localisation and Torsion Tools Two

More Revit API tutorial material and tools plus a couple of hints from the Revit API discussion forum and the Forge blog:

Torsion Tools Two

Continuing right on from the fruitful collection of videos and tutorials presented yesterday, an update to the Torsion Tools add-in template with code examples for common tools introduced last week:

Autodesk Revit 2020 API Visual Studio Solution Template with Code Examples for Common Tools. Update #2 walks through the added tools to copy legends, schedules, and reference views from a linked model.

The Copy Legends and Schedules tools allow you to select the Link to copy them from, then select the Legends or Schedules you would like to copy. It will check whether they already exist in the project and prompt you if they do.

The Linked Views tool allows you to select a linked model, title block, viewport type and then the views you would like from the linked model. It creates a drafting view in the current document with the name, detail number and sheet of the linked model.

TorsionTools GitHub repo

Many thanks to Torsion Tools for creating and sharing this powerful resource!

Retrieve Path to Revit.ini

A small note from the Revit API discussion forum thread on adding project template to 'New Project' via API by Peter @cig_ad Ciganek:

The Autodesk.Revit.ApplicationServices.Application property CurrentUsersDataFolderPath returns the path where Revit.ini is located.

Updated NeXLT Localization URL

In another small not from the Revit API discussion forum thread on the localization website, Susan Renna points out the new URL:

You can find the Autodesk NeXLT localization website here:

Volume and Area of Triangulated Solid

Finally, a useful generic pure geometry utility that might come in handy in the Revit environment as well to calculate the volume of a 3D mesh object, the surface of which is made up triangles:

Reading this paper, it is actually a pretty simple calculation.

The trick is to calculate the signed volume of a tetrahedron – based on your triangle and topped off at the origin. The sign of the volume comes from whether your triangle is pointing in the direction of the origin (The normal of the triangle is itself dependent upon the order of your vertices, which is why you don't see it explicitly referenced below).

This all boils down to the following simple function:

  public float SignedVolumeOfTriangle(Vector p1, Vector p2, Vector p3) {
    var v321 = p3.X*p2.Y*p1.Z;
    var v231 = p2.X*p3.Y*p1.Z;
    var v312 = p3.X*p1.Y*p2.Z;
    var v132 = p1.X*p3.Y*p2.Z;
    var v213 = p2.X*p1.Y*p3.Z;
    var v123 = p1.X*p2.Y*p3.Z;
    return (1.0f/6.0f)*(-v321 + v231 + v312 - v132 - v213 + v123);

A driver uses it to calculate the volume of the mesh:

  public float VolumeOfMesh(Mesh mesh) {
    var vols = from t in mesh.Triangles
      select SignedVolumeOfTriangle(t.P1, t.P2, t.P3);
    return Math.Abs(vols.Sum());

Adam Nagy picked this up and used it to calculate volume and surface area in the Forge viewer, verifying that the resulting values match the corresponding properties provided by Inventor:

Volume and surface area in the Forge viewer