#RTCEUR Wish 3 granted (part 1)! Multiple Element Revision Creation

Barrie asked: “Can you rev cloud all change elements in views on sheets and write update to rev cloud comments for tagging?”

This post shows how to prompt the user to select multiple elements then create a new revisions and a revision cloud around each element. A following post will discuss to what extent this could be automated to create revisions every time the model changes.

public void makeRevisionAndCloud()
{
    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = this.ActiveUIDocument.Document;
    Application app = this.Application;
    
    // get elements from user selection
    List<Element> elements = new List<Element>();
    
    // string of ids of the selected elements to use for Revision description
    string description = "";
    foreach (Reference r in uidoc.Selection.PickObjects(ObjectType.Element))
    {
        elements.Add(doc.GetElement(r));
        description += r.ElementId.IntegerValue + " ";
    }
    
    using (Transaction t = new Transaction(doc, "Make Revision & Cloud"))
    {
        t.Start();
        
        // create new revision
        Revision rev = Revision.Create(doc);
        rev.RevisionDate = DateTime.Now.ToShortDateString();
        rev.Description = description;
        rev.IssuedBy = app.Username;
            
        // use bounding box of element and offset to create curves for revision cloud
        foreach (Element e in elements)
        {
            BoundingBoxXYZ bbox = e.get_BoundingBox(doc.ActiveView);
            List<Curve> curves = new List<Curve>();
            double offset = 2;
            XYZ pt1 = bbox.Min.Subtract(XYZ.BasisX.Multiply(offset)).Subtract(XYZ.BasisY.Multiply(offset));
            XYZ pt2 = new XYZ(bbox.Min.X - offset, bbox.Max.Y + offset, 0);
            XYZ pt3 = bbox.Max.Add(XYZ.BasisX.Multiply(offset)).Add(XYZ.BasisY.Multiply(offset));;
            XYZ pt4 = new XYZ(bbox.Max.X + offset, bbox.Min.Y - offset, 0);
            curves.Add(Line.CreateBound(pt1, pt2));
            curves.Add(Line.CreateBound(pt2, pt3));
            curves.Add(Line.CreateBound(pt3, pt4));
            curves.Add(Line.CreateBound(pt4, pt1));
            
            // create revision cloud
            RevisionCloud cloud = RevisionCloud.Create(doc, doc.ActiveView, rev.Id, curves);
            
            // set Comments of revision cloud
            cloud.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
                .Set(e.GetType().Name + "-" + e.Name + ": " + doc.Application.Username);
            
            // tag the revision cloud
            IndependentTag tag = doc.Create.NewTag(doc.ActiveView, cloud, true, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, pt3);
            tag.TagHeadPosition = pt3.Add(new XYZ(2,2,0));
        }
        t.Commit();
    }
}
Advertisements

9 thoughts on “#RTCEUR Wish 3 granted (part 1)! Multiple Element Revision Creation

  1. This is great. You showed that you could track changes between two models and push that to a schedule. I was hoping that you could use the results from that to draw clouds around each of the changes detected and add the description of the change (new, moved, deleted) to the instance comments of each cloud. They could all be assigned to a single revision sequence that says ‘see clouded comments’. The clouds would want to be added to any view that is on a sheet.

    Thanks

    • Drawing a cloud around a deleted element is harder, because after the element is deleted there is not a simple way to get the location (or bounding box, as I did in this code sample) of the deleted element. All that Revit provides is the element id of the deleted element. To accomplish what I think you want, you would need to store somewhere (like an external database) the element id and location of every element that has a location. Then after the element is deleted, the API routine could look up its last location and use that to create the cloud. Doable, but more work.

  2. I am getting “the type name or namespace name ‘Revision’ could not be found (are you missing a using directive or assembly reference?)” error while executing .
    What is the assembly reference for this revision class, I am using Revit Structure 2014 in pc .

    Regards

    Amith

  3. Hi Harry,

    Thanks for sharing. I am getting 2 errors when i build i use Revit 2015. Its showing:

    “The type or namespace name ‘Create’ does not exist in the namespace ‘RevisionCloud’ (are you missing an assembly reference?) (CS0234)”

    “‘RevisionCloud’ is a ‘namespace’ but is used like a ‘type’ (CS0118) “

    • The revision API was added to Revit 2015, but you are using 2015 so that should not be the problem. Could you try 2016?

      Here is my full code from the macro’s module

      /*
      * Created by SharpDevelop.
      * User: harry_000
      * Date: 11/2/2015
      * Time: 5:45 AM
      *
      * To change this template use Tools | Options | Coding | Edit Standard Headers.
      */
      using System;
      using Autodesk.Revit.UI;
      using Autodesk.Revit.DB;
      using Autodesk.Revit.UI.Selection;
      using System.Collections.Generic;
      using System.Linq;
      using Autodesk.Revit.ApplicationServices;

      namespace revisionTest
      {
      [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
      [Autodesk.Revit.DB.Macros.AddInId("B82D15BA-6ADE-4B8B-BC72-F9F7B6B8928B")]
      public partial class ThisApplication
      {
      private void Module_Startup(object sender, EventArgs e)
      {

      }

      private void Module_Shutdown(object sender, EventArgs e)
      {

      }

      #region Revit Macros generated code
      private void InternalStartup()
      {
      this.Startup += new System.EventHandler(Module_Startup);
      this.Shutdown += new System.EventHandler(Module_Shutdown);
      }
      #endregion

      public void makeRevisionAndCloud()
      {
      UIDocument uidoc = this.ActiveUIDocument;
      Document doc = this.ActiveUIDocument.Document;
      Application app = this.Application;

      // get elements from user selection
      List elements = new List();

      // string of ids of the selected elements to use for Revision description
      string description = "";
      foreach (Reference r in uidoc.Selection.PickObjects(ObjectType.Element))
      {
      elements.Add(doc.GetElement(r));
      description += r.ElementId.IntegerValue + " ";
      }

      using (Transaction t = new Transaction(doc, "Make Revision & Cloud"))
      {
      t.Start();

      // create new revision
      Revision rev = Revision.Create(doc);
      rev.RevisionDate = DateTime.Now.ToShortDateString();
      rev.Description = description;
      rev.IssuedBy = app.Username;

      // use bounding box of element and offset to create curves for revision cloud
      foreach (Element e in elements)
      {
      BoundingBoxXYZ bbox = e.get_BoundingBox(doc.ActiveView);
      List curves = new List();
      double offset = 2;
      XYZ pt1 = bbox.Min.Subtract(XYZ.BasisX.Multiply(offset)).Subtract(XYZ.BasisY.Multiply(offset));
      XYZ pt2 = new XYZ(bbox.Min.X - offset, bbox.Max.Y + offset, 0);
      XYZ pt3 = bbox.Max.Add(XYZ.BasisX.Multiply(offset)).Add(XYZ.BasisY.Multiply(offset));;
      XYZ pt4 = new XYZ(bbox.Max.X + offset, bbox.Min.Y - offset, 0);
      curves.Add(Line.CreateBound(pt1, pt2));
      curves.Add(Line.CreateBound(pt2, pt3));
      curves.Add(Line.CreateBound(pt3, pt4));
      curves.Add(Line.CreateBound(pt4, pt1));

      // create revision cloud
      RevisionCloud cloud = RevisionCloud.Create(doc, doc.ActiveView, rev.Id, curves);

      // set Comments of revision cloud
      cloud.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
      .Set(e.GetType().Name + "-" + e.Name + ": " + doc.Application.Username);

      // tag the revision cloud
      IndependentTag tag = doc.Create.NewTag(doc.ActiveView, cloud, true, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, pt3);
      tag.TagHeadPosition = pt3.Add(new XYZ(2,2,0));
      }
      t.Commit();
      }
      }

      }
      }

  4. […] public void makeRevisionAndCloud() { UIDocument uidoc = this.ActiveUIDocument; Document doc = this.ActiveUIDocument.Document; Application app = this.Application; // get elements from user selection List<Element> elements = new List<Element>(); // string of ids of the selected elements to use for Revision description string description = ""; foreach (Reference r in uidoc.Selection.PickObjects(ObjectType.Element)) { elements.Add(doc.GetElement(r)); description += r.ElementId.IntegerValue + " "; } using (Transaction t = new Transaction(doc, "Make Revision & Cloud")) Read more […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s