Take off object ot treeview

Take off object ot treeview

Anonymous
Not applicable
294 Views
1 Reply
Message 1 of 2

Take off object ot treeview

Anonymous
Not applicable
Hi
I have written a code that select an object and calculate the length, area and volume, then I created a form.
My problem is this: I want to create a form with tree view then select an object and take off that object to a node and assign length, area and volume to its child nodes. The process I mean, is something like Quantification Workbook in Navis. In the following, I have brought my code that calculate area.
Would you mind helping me with this?
 
 
Best Regards
Hamid
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.Attributes;
using System.Windows.Forms;
using System.Drawing;

namespace ClassArea
{
    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commanddata, ref string message, ElementSet elements)
        {

            UIApplication uiapp = commanddata.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            System.Windows.Forms.Form Fm = new Form1(uidoc);
            Fm.ShowDialog();
        }

    }
}
================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.Attributes;

namespace ClassArea
{
    public partial class Form1 : System.Windows.Forms.Form
    {
        public Form1(UIDocument uidoc)
        {
            InitializeComponent();
            CreateListViewData(uidoc);
        }

        void CreateListViewData(UIDocument uidoc)
        {

            Document doc = uidoc.Document;

            IList<Reference> pickedObjs = uidoc.Selection.PickObjects(ObjectType.Element, "Select elements");

            List<ElementId> ids = (from Reference r in pickedObjs select r.ElementId).ToList();

            using (Transaction tx = new Transaction(doc))
            {
                StringBuilder sb = new StringBuilder();
                tx.Start("transaction");

                if (pickedObjs != null && pickedObjs.Count > 0)
                {
                    foreach (ElementId eid in ids)
                    {
                        Element e = doc.GetElement(eid);
                        sb.Append("\nElement Type = " + e.Name);

                        // Calculate Area

                        Parameter parA = e.LookupParameter("Area");
                        string valStringA = parA.AsValueString();
                        double valDouble = parA.AsDouble();

                        //sb.Append("\nElement Area = " + valStringA);

                        // Calculate Volume

                        Parameter parV = e.LookupParameter("Volume");
                        string valStringV = parV.AsValueString();

                        // Calculate Length

                        Parameter parL = e.LookupParameter("Length");
                        string valStringL = parL.AsValueString();
                    }
                    //Autodesk.Revit.UI.TaskDialog.Show("Element Calculator", sb.ToString());
                }
                tx.Commit();
            }
        }
    }
}
0 Likes
295 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk

Sure, with pleasure.

 

I see that you clarified and simplified your question significantly and answered it here:

 

https://forums.autodesk.com/t5/revit-api-forum/assign-object-to-treenode-in-revit-api/m-p/9361467

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes