class Dimensions
{
public int b { get; set; }
public int d { get; set; }
public int CutLength { get; set; }
}
Public void FramingID()
{
var DimList = new List<Dimensions>();
DimList.Add(new Dimensions { b = 2, d = 4, CutLength=10});
DimList.Add(new Dimensions { b = 10,d = 5, CutLength=20});
DimList.Add(new Dimensions { b = 4, d = 6, CutLength=30});
DimList.Add(new Dimensions { b = 4, d = 2, CutLength=40});
DimList.Add(new Dimensions { b = 2, d = 2, CutLength=50});
DimList.Add(new Dimensions { b = 6, d = 4, CutLength=60});
DimList.Add(new Dimensions { b = 2, d = 2, CutLength=70});
DimList.Add(new Dimensions { b = 2, d = 5, CutLength=80});
DimList.Add(new Dimensions { b = 6, d = 2, CutLength=80});
DimList.Add(new Dimensions { b = 2, d = 2, CutLength=50});
var Order = from m in DimList orderby m.b, m.d, m.CutLength select m;
var Order = from m in DimList orderby m.b, m.d, m.CutLength select m;
foreach (var n in Order)
{
Console.WriteLine( n.b.ToString() + " x " + n.d.ToString() + " x " + n.CutLength.ToString());
}
}
result:
2 x 2 x 50
2 x 2 x 50
2 x 2 x 70
2 x 4 x 10
2 x 5 x 80
4 x 2 x 40
4 x 6 x 30
6 x 2 x 80
6 x 4 x 60
10 x 5 x 20
I am trying to create a multilevel list using the same logic in the code above but the difference is that the values in the list are not predefined values a. The result intended in the code below is the same as the code above but the values cannot be predefined They are values that require to be searched from a group of elements and then be added to the list and be arranged in ascending order accordingly How can I add the values from the list as integers without using a for loop or a foreach loop as both will no work with the ordering as values will be added separately Thanks
class Dimensions
{
public int b { get; set; }
public int d { get; set; }
public int CutLength { get; set; }
}
Public void FramingID()
{
var doc = Application.ActiveUIDocument.Document;
FilteredElementCollector Collector = new FilteredElementCollector(doc);
ICollection<Element> StructuralFraming = Collector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_StructuralFraming).ToList();
List<int> bIntegerList = (from Element element in StructuralFraming select Convert.ToInt32(doc.GetElement(element.GetTypeId()).LookupParameter("b").AsValueString())).ToList();
List<int> dIntegerList = (from Element element in StructuralFraming select Convert.ToInt32(doc.GetElement(element.GetTypeId()).LookupParameter("d").AsValueString())).ToList();
List<int> ClIntegerList = (from Element element in StructuralFraming select Convert.ToInt32(element.LookupParameter("Cut Length").AsValueString())).ToList();
var DimList = new List<Dimensions>();
DimList.Add(new Dimensions { b = bIntegerList, d = dIntegerList, CutLength = ClIntegerList});
var Order = from m in DimList orderby m.b, m.d, m.CutLength select m;
foreach (var n in Order)
{
TaskDialog.Show("TEST", n.b.ToString() + " x " + n.ToString() + " x " + n.ToString());
}
}
List<int> bIntegerList = new List<int> { 2, 5, 6, 3, 4 };
List<int> dIntegerList = new List<int> { 20, 60, 30, 40, 50 };
List<int> ClIntegerList = new List<int> { 300, 300, 200, 500, 600 };
var wrapperList = bIntegerList.Zip(dIntegerList, (b, d) => new { b, d });
var dimListReal = wrapperList.Zip(ClIntegerList, (w, cl) => new Dimensions() { b = w.b, d = w.d, CutLength = cl });
var Order = from m in dimListReal orderby m.b, m.d, m.CutLength select m;
foreach (var n in Order)
{
Console.WriteLine("Test working " + n.b.ToString() + " x " + n.d.ToString() + " x " + n.CutLength.ToString());
}
from revit
var doc = Application.ActiveUIDocument.Document;
FilteredElementCollector Collector = new FilteredElementCollector(doc);
ICollection<Element> StructuralFraming = Collector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_StructuralFraming).ToList();
List<int> bIntegerList = new List<int> (from Element element in StructuralFraming select Convert.ToInt32(doc.GetElement(element.GetTypeId()).LookupParameter("b").AsValueString())).ToList();
List<int> dIntegerList = new List<int>(from Element element in StructuralFraming select Convert.ToInt32(doc.GetElement(element.GetTypeId()).LookupParameter("d").AsValueString())).ToList();
List<int> ClIntegerList = new List<int>(from Element element in StructuralFraming select Convert.ToInt32(element.LookupParameter("Cut Length").AsValueString())).ToList();
var wrapperList = bIntegerList.Zip(dIntegerList, (b, d) => new { b, d });
var dimListReal = wrapperList.Zip(ClIntegerList, (w, cl) => new Dimensions() { b = w.b, d = w.d, CutLength = cl });
var Order = from m in dimListReal orderby m.b, m.d, m.CutLength select m;
foreach (var n in Order)
{
TaskDialog.Show("Test", n.b.ToString() + " x " + n.d.ToString() + " x " + n.CutLength.ToString());
}
So you must have some identifier that relates the 3 dimensions as part of the same entity. Here we have ElementX
that represents a Dimension. It can be b
or d
or CutLength
. Each ElementX
has an identifier that binds him to other dimension value. Example, if you submit a new Trio of dimensions it will look like:
ElementX dimensionB = new ElementX { Xvalue = 10 , Id = 999 }
ElementX dimensionD = new ElementX { Xvalue = 80 , Id = 999 }
ElementX dimensionCutLength = new ElementX { Xvalue = 800 , Id = 999 }
And there is the testing code
static void Main(string[] args)
{
List<ElementX> bIntegerList = new List<ElementX> { new ElementX { Xvalue = 6, Id = 77},
new ElementX { Xvalue = 3, Id = 66 },
new ElementX { Xvalue = 8, Id = 65 } };
List<ElementX> dIntegerList = new List<ElementX> { new ElementX { Xvalue = 30, Id = 66},
new ElementX { Xvalue = 60, Id = 77 },
new ElementX { Xvalue = 80, Id = 65 } };
List<ElementX> ClIntegerList = new List<ElementX> { new ElementX { Xvalue = 800, Id = 65},
new ElementX { Xvalue = 600, Id = 77 },
new ElementX { Xvalue = 300, Id = 66 } };
var wrapperList = bIntegerList.Join(dIntegerList,
x => x.Id,
y => y.Id,
(x, y) => new { b = x.Xvalue, d = y.Xvalue, Id = y.Id }).ToList();
var dimList = wrapperList.Join(ClIntegerList,
x => x.Id,
cl => cl.Id,
(x, cl) => new Dimensions { b = x.b, d = x.d, CutLength = cl.Xvalue }).ToList();
var Order = from m in dimList orderby m.b, m.d, m.CutLength select m;
foreach (var n in Order)
{
Console.WriteLine("Test working " + n.b.ToString() + " x " + n.d.ToString() + " x " + n.CutLength.ToString());
}
Output