Message 1 of 2
Take off object ot treeview
Not applicable
03-02-2020
03:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.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();
}
}
}
}
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();
}
}
}
}