Select Levels from drop down list of revit 3D view

Select Levels from drop down list of revit 3D view

Anonymous
Not applicable
1,175 Views
3 Replies
Message 1 of 4

Select Levels from drop down list of revit 3D view

Anonymous
Not applicable

Hello,

 

I want to create drop down list in windows form which contain all levels from the project which is used in that project(ground floor, first floor like that..).

 

For that I create a windows form(as I attached image ) which is the addin application for revit.

 

How I load all the levels in form load event when we click on revit addin for a particualr project.

 

Example:-

 

1st drop down has a string 

2nd drop down conatins levels(if I select 1st floor level)

 

If I select both item from drop down list then click on join button the it join only first floor elements(wall and column) .It could not join other levels element(wall and column).

 

 

This is the code I using without selecting levels(not contain level drop down list)

 

Form Code:-

using System;
using System.Windows.Forms;

using Autodesk.Revit.UI;


namespace JoinGeometry
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public partial class Form2 : Form
{
ExternalCommandData commandData;

public Form2(ExternalCommandData commandDatax)
{
commandData = commandDatax;
InitializeComponent();
}


//------------------------JOIN------------------------------------------------------------------------
private void button1_Click(object sender, EventArgs e)
{

if (comboBox1.SelectedItem == "Wall" && comboBox2.SelectedItem == "Column")
{
try
{
WCjoin wcj = new WCjoin();
wcj.Execute(commandData);
label2.Text = "WALL COLUMN JOINED";
}
catch (Exception g)
{
TaskDialog.Show("revit", "error is occured" + g);
}
}

}

 

 

 

WCjoin code:-

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace JoinGeometry
{
[Transaction(TransactionMode.Manual)]
class WCjoin
{
bool check;
public Result Execute(ExternalCommandData commandData)
{


UIApplication uiApp = commandData.Application;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;

 

//--get walls on the active view-----------

FilteredElementCollector collWalls = new FilteredElementCollector(doc, doc.ActiveView.Id);
collWalls.OfClass(typeof(Wall));

foreach (Wall w in collWalls)
{

FilteredElementCollector collColumnsOnThisWall = new FilteredElementCollector(doc, doc.ActiveView.Id);

collColumnsOnThisWall.OfClass(typeof(FamilyInstance));
collColumnsOnThisWall.OfCategory(BuiltInCategory.OST_StructuralColumns);

BoundingBoxXYZ bb = w.get_BoundingBox(doc.ActiveView);
Outline outline = new Outline(bb.Min, bb.Max);
BoundingBoxIntersectsFilter bbfilter =
new BoundingBoxIntersectsFilter(outline);
collColumnsOnThisWall.WherePasses(bbfilter);

foreach (FamilyInstance column in collColumnsOnThisWall)
{
using (Transaction t = new Transaction(doc, "Join All Walls/Column"))
{
t.Start();

check=JoinGeometryUtils.AreElementsJoined(doc, w, column);
if(check==true)
{

}
else
{
JoinGeometryUtils.JoinGeometry(doc, w, column);
}

t.Commit();
}

}

}
return Result.Succeeded;
}
}
}

 

 

 

And how should I extarct levels from revit to dropdown list

 

In this code what changes should I do for achieve my goal

 

 

 

 

 

 

 

0 Likes
1,176 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

Dear Payalorna,

 

I find your question pretty incomprehensible, but maybe this previous discussion and the various links that it refers to will help:

 

http://forums.autodesk.com/t5/revit-api/sort-levels-by-elevation/m-p/5407203

 

I summarised the discussion and added my contribution to it on The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2014/11/webgl-goes-mobile-and-sorted-level-retrieval.html#3

 

I also added my code snippet suggestion to The Building Coder samples:

 

https://github.com/jeremytammik/the_building_coder_samples

 

Cheers,

 

Jeremy



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

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hello,

 

  I create a combobox and show all levels from the project.I have one problem how to select one level from combobox list of item.What should I write in this code.

 

 

This is the code:  (this is written in page load event)

 

 

UIApplication appi = commandData.Application;
UIDocument uidoc = appi.ActiveUIDocument;
Document doc = uidoc.Document;
IList<Level> levellist = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast<Level>().ToList();


foreach (Level vs in levellist)
{
List<string> list = new List<string>();
list.Add(vs.Name);
if (!comboBox1.Items.Contains(vs.Name)) comboBox1.Items.Add(vs.Name);

}

0 Likes
Message 4 of 4

Anonymous
Not applicable

If I want to join wall and column from that selected levels which I selected from combobox. How I do this?

 

I successfully join wall and column without using levels. when I select the level from combobox(which is in the windows form class) and click the join button it execute following class code(class name is WCjoin.class) and join only that level wall and column instead of join all wall and column in the active view.

 

Here is the code for join all wall and column from active view:

 


using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;


namespace JoinGeometry
{
[Transaction(TransactionMode.Manual)]
class WCjoin
{
bool check;
public Result Execute(ExternalCommandData commandData)
{
UIApplication uiApp = commandData.Application;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;

FilteredElementCollector collWalls = new FilteredElementCollector(doc,doc.ActiveView.Id);
collWalls.OfClass(typeof(Wall));

foreach (Wall w in collWalls)
{
FilteredElementCollector collColumnsOnThisWall = new FilteredElementCollector(doc, doc.ActiveView.Id);

collColumnsOnThisWall.OfClass(typeof(FamilyInstance));
collColumnsOnThisWall.OfCategory(BuiltInCategory.OST_StructuralColumns);

BoundingBoxXYZ bb = w.get_BoundingBox(doc.ActiveView);
Outline outline = new Outline(bb.Min, bb.Max);
BoundingBoxIntersectsFilter bbfilter =
new BoundingBoxIntersectsFilter(outline);
collColumnsOnThisWall.WherePasses(bbfilter);

foreach (FamilyInstance column in collColumnsOnThisWall)
{
using (Transaction t = new Transaction(doc, "Join All Walls/Column"))
{
t.Start();

check = JoinGeometryUtils.AreElementsJoined(doc, w, column);
if (check == true)
{

}
else
{
JoinGeometryUtils.JoinGeometry(doc, w, column);
}

t.Commit();
}
}
}
return Result.Succeeded;
}
}
}

0 Likes