Lookup Ideas, Jigs and ACC Docs Access

Today, we look at a request for new ideas for enhancing RevitLookup, implementing a pickpoint rubber band and opening BIMs on ACC Docs:

Request for RevitLookup Ideas

Do you have any ideas for RevitLookup enhancements?

A lot of exciting functionality has already been worked on in the dev and dev_winui branches. We expect to see that coming out quite soon.

Meanwhile, Roman Nice3point opened a discussion for collecting RevitLookup Ideas. Your contributions there are welcome. Thank you!

Transient Elements for Jig

A couple of ideas on creating transient elements graphics similar to the AutoCAD jig functionality using the IDirectContext3DServer functionality or the temporary InCanvas graphics API were recapitulated in the Revit API discussion forum thread on drawing line visible on screen:

Pick point rubber band

Lorenzo Virone shared a different approach, creating and deleting database-resident Revit elements on the fly in a loop:

I faced a similar UI problem to create a rubber band between two points. I used two functions, Line.CreateBound and NewDetailCurve, inside a loop to create a line at the cursor position, refresh, and delete the line every 0.1 seconds, until the user chooses the second point. A little tricky, but it works fine for me, and Revit seems to execute these 2 functions very fast.

This trick will technically work with anything: create new elements on each mouse movement, refresh, delete the created elements and replace them with new ones. You can use either model or detail elements. It's easy to implement, because you just need to call the two methods, e.g., like this:

  1.   bool done = false;
  2.   List<ElementId> temp = new List<ElementId>();
  3.  
  4.   while (!done)
  5.   {
  6.     doc.Delete(temp);
  7.  
  8.     // Create temp elements
  9.     // Save their IDs in `temp`
  10.     // Set `done` to `true` when finished
  11.  
  12.     doc.regenerate();
  13.     uidoc.RefreshActiveView();
  14.     Thread.Sleep(500); // milliseconds
  15.   }
  16.  
  17.   // Your final elements are in `temp`

Many thanks to Lorenzo for sharing this nice solution.

Transient DirectShape Jig

Chuong Ho adds: This technique can also be used with a DirectShape element:

  1. using Autodesk.Revit.DB;
  2. using Autodesk.Revit.UI.Selection;
  3. using System.Collections.Generic;
  4. using Line = Autodesk.Revit.DB.Line;
  5. using Point = Autodesk.Revit.DB.Point;
  6.  
  7. var Doc = commandData.Application.ActiveUIDocument.Document;
  8.  
  9. using TransactionGroup trang = new TransactionGroup(Doc, "test");
  10. trang.Start();
  11. XYZ a = UIDoc.Selection.PickPoint(ObjectSnapTypes.None);
  12. SetPoint(a);
  13. XYZ b = UIDoc.Selection.PickPoint(ObjectSnapTypes.None);
  14. SetPoint(b);
  15. SetLine(a, b);
  16. XYZ p1 = UIDoc.Selection.PickPoint(ObjectSnapTypes.None);
  17. SetPoint(p1);
  18. XYZ p2 = UIDoc.Selection.PickPoint(ObjectSnapTypes.None);
  19. SetPoint(p2);
  20. bool isSamSide = IsSamSide(p1, p2, a, b);
  21. MessageBox.Show(isSamSide.ToString());
  22. trang.Assimilate();
  23.  
  24. // visualize a point
  25. void SetPoint(XYZ xyz)
  26. {
  27.   using (Transaction tran = new Transaction(Doc, "Add point"))
  28.   {
  29.     tran.Start();
  30.     Point point1 = Point.Create(xyz);
  31.     DirectShape ds =
  32.       DirectShape.CreateElement(Doc, new ElementId(BuiltInCategory.OST_GenericModel));
  33.     ds.SetShape(new List<GeometryObject>() { point1 });
  34.     tran.Commit();
  35.   }
  36. }
  37.  
  38. // visualize a line
  39. void SetLine(XYZ x1, XYZ x2)
  40. {
  41.   using (Transaction tran = new Transaction(Doc, "Add line"))
  42.   {
  43.     tran.Start();
  44.     Line line = Line.CreateBound(x1, x2);
  45.     DirectShape ds = DirectShape.CreateElement(
  46.       Doc, new ElementId(BuiltInCategory.OST_GenericModel));
  47.     ds.SetShape(new List<GeometryObject>() { line });
  48.     tran.Commit();
  49.   }
  50. }

Pick point rubber band

Many thanks to Chuong Ho for this addition!

Opening a Model in ACC Docs

We started out discussing opening a cloud model with Revit API in the Revit API discussion forum, but then moved it over to StackOverflow, the better place for such a cloud-related topic, where my colleague Eason Kang explains how to open files located in ACC Docs:

Question: My Visual Studio Revit API add-in open Revit files to export data in a batch. I can add many files which are on the networks and the plugin automatically opens them all. Is it possible to also open files that are in the ACC Docs cloud?

I know I can open AccDocs which were be already downloaded locally by searching for them in the collaboration cache folder, but how to open files which have not yet been downloaded?

Answer: Since you mention the collaboration cache folder, I assume you are using the Revit Cloud Worksharing model, a.k.a. C4R, the model for Autodesk Collaboration for Revit.

If so, you can make use of the APS Data Management API to obtain the projectGuid and modelGuid in the model version tip like this:

{
   "type":"versions",
   "id":"urn:adsk.wipprod:fs.file:vf.abcd1234?version=1",
   "attributes":{
      "name":"fileName.rvt",
      "displayName":"fileName.rvt",
      ...
      "mimeType":"application/vnd.autodesk.r360",
      "storageSize":123456,
      "fileType":"rvt",
      "extension":{
         "type":"versions:autodesk.bim360:C4RModel",
         ....
         "data":{
            ...
            "projectGuid":"48da72af-3aa6-4b76-866b-c11bb3d53883",
            ....
            "modelGuid":"e666fa30-9808-42f4-a05b-8cb8da576fe9",
            ....
         }
      }
   },
   ....
}

With those in hand, you can open the C4R model using Revit API like this:

  // where is your BIM360/ACC account based, US or EU?

  var region = ModelPathUtils.CloudRegionUS;

  var projectGuid = new Guid("48da72af-3aa6-4b76-866b-c11bb3d53883");
  var modelGuid = new Guid("e666fa30-9808-42f4-a05b-8cb8da576fe9");

  // For Revit 2023 and newer:

  var modelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(
    region, projectGuid, modelGuid );

  // For Revit 2019 - 2022:

  //var modelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(
  //  projectGuid, modelGuid );

  var openOptions = new OpenOptions();

  app.OpenAndActivateDocument( modelPath, openOptions ); // on desktop

  // on Design Automation for Revit or
  // to not activate the model on Revit desktop:

  // app.OpenDocumentFile( modelPath, openOptions );

You can also make use the Visual Studio APS Data Management package on NuGet for this. The Hubs Browser tutorial demonstrates its use.

References:

Many thanks to Eason for this comprehensive answer!

Stop Using JPEG

Moving away from Revit and its API to other interesting current news, Daniel Immke suggests that it’s the future – you can stop using JPEGs and presents an overview and rationale for some compelling alternatives, e.g., AVIF and WebP.

Stop Using Voice Id

Joseph Cox describes how he broke into a bank account with an AI-generated voice – some banks tout voice ID as a secure way to log into your account. He proves it's possible to trick such systems with free or cheap AI-generated voices.