Hello all,
I am trying to write an add-in that brings up a WindowsForm that has a list of check boxes that the user can select to determine which levels (and reference planes) they want to be removed from the project. I have created an ArrayList with the Element Ids for both the levels and planes. It is listed below as ArrayList.cs. I have also listed my the class I am trying to use to delete the elements. It is labeled BasementDeleteElements.cs. I am struggling with getting the asementDeleteElements.cs to access the array and then to use the variables in the array as the Element Ids for Revit to delete. I am very new to C# and would appreciate all the help I can get.
ArrayList.cs
using System;
using System.Collections;
using System.Collections.Generic;
class ArrayListLevels
{
// Main Method
public static void Main(String[] args)
{
#region Basment
// create basement array list
ArrayList BasementList = new ArrayList();
// add elements to array list
BasementList.Add("1600991");
BasementList.Add("1601000");
BasementList.Add("1600999");
BasementList.Add("1600996");
BasementList.Add("1600997");
BasementList.Add("1600998");
#endregion
#region Level one
// create level one array list
ArrayList OneList = new ArrayList();
// add elements to array list
OneList.Add("1460");
OneList.Add("1363089");
OneList.Add("1534822");
OneList.Add("1363104");
OneList.Add("1362898");
OneList.Add("1363074");
#endregion
#region Level Two
// create level two array list
ArrayList TwoList = new ArrayList();
// add elements to array list
TwoList.Add("1287144");
TwoList.Add("1363704");
TwoList.Add("1534823");
TwoList.Add("1363719");
TwoList.Add("1363560");
TwoList.Add("1363689");
#endregion
#region Level Three
// create level three array list
ArrayList ThreeList = new ArrayList();
// add elements to array list
ThreeList.Add("1287185");
ThreeList.Add("1364100");
ThreeList.Add("1534824");
ThreeList.Add("1364115");
ThreeList.Add("1363988");
ThreeList.Add("1364085");
#endregion
#region Level Four
// create level four array list
ArrayList FourList = new ArrayList();
// add elements to array list
FourList.Add("1287204");
FourList.Add("1671040");
FourList.Add("1671042");
FourList.Add("1671041");
FourList.Add("1364404");
FourList.Add("1671039");
#endregion
#region Level Five
// create level five array list
ArrayList FiveList = new ArrayList();
// add elements to array list
FiveList.Add("1287223");
FiveList.Add("1671045");
FiveList.Add("1671047");
FiveList.Add("1671046");
FiveList.Add("1364499");
FiveList.Add("1671044");
#endregion
#region Level Six
// create level six array list
ArrayList SixList = new ArrayList();
// add elements to array list
SixList.Add("1287241");
SixList.Add("1671050");
SixList.Add("1671052");
SixList.Add("1671051");
SixList.Add("1364600");
SixList.Add("1671049");
#endregion
#region Level Seven
// create level seven array list
ArrayList SevenList = new ArrayList();
// add elements to array list
SevenList.Add("1287259");
SevenList.Add("1671055");
SevenList.Add("1671057");
SevenList.Add("1671056");
SevenList.Add("1364732");
SevenList.Add("1671054");
#endregion
#region Level Eight
// create level eight array list
ArrayList EightList = new ArrayList();
// add elements to array list
EightList.Add("1287278");
EightList.Add("1671060");
EightList.Add("1671062");
EightList.Add("1671061");
EightList.Add("1364825");
EightList.Add("1671059");
#endregion
#region Roof
// create roof array list
ArrayList RooftList = new ArrayList();
// add elements to array list
RooftList.Add("62406");
#endregion
}
}
BasementDeleteElements.cs
#region Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
#endregion
namespace LevelDeleteForm
{
#region Basement Level
class BasementDeleteElements
{
public void DeleteElement(Document doc)
{
Element element = FindElementByName(doc, typeof(Level), "1600991");
using (Transaction t = new Transaction(doc, "Delete element"))
{
t.Start();
doc.Delete(element.Id);
t.Commit();
}
}
public void DeleteElements(Document doc)
{
List<Level> levels = GetLevels(doc);
List<ElementId> idSelection = new List<ElementId>();
foreach (Level l in levels)
{
Element e = l as Element;
idSelection.Add(e.Id);
}
using (Transaction t = new Transaction(doc, "Delete element"))
{
t.Start();
doc.Delete(idSelection);
t.Commit();
}
}
public List<Level> GetLevels(Document doc)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> Levels = collector.OfClass(typeof(Level)).ToElements();
List<Level> List_Levels = new List<Level>();
foreach (Level l in Levels)
{
List_Levels.Add(l);
}
return List_Levels;
}
public Element FindElementByName(Document doc, Type targetType, string targetName)
{
return new FilteredElementCollector(doc).OfClass(targetType).FirstOrDefault<Element>(e => e.Name.Equals(targetName));
}
}
#endregion
}
1. Search the Internet
2. For instance, for 'access variable c# module'
3.. First hit: https://stackoverflow.com/questions/22216253/access-variable-from-another-method-in-another-class
Can't find what you're looking for? Ask the community or share your knowledge.