Hello guys,
I am writing a function that returns GridLines of the selected curtain wall. It is very weird that I can't see all methods and properties of the selected element. In my case it gives me nothing...
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Revit.Auswahlhilfe
{
/// <summary>
/// Interaktionslogik für FassadenRasterModelView.xaml
/// </summary>
public partial class FassadenRasterModelView : Window
{
readonly UIDocument document;
public ExternalEvent ExEvent { get; set; }
readonly string[] oben_unten = { "Oben -> Unten", "Unten -> Oben" };
readonly string[] rechts_links = { "Rechts -> Links", "Links -> Rechts" };
private bool reverse = false;
public FassadenRasterModelView(UIDocument doc)
{
document = doc;
InitializeComponent();
}
private void vertikaleRaster_Checked(object sender, RoutedEventArgs e)
{
//horizontaleRaster.IsChecked = false;
if(labelRichtung != null)
{
labelRichtung.Text = rechts_links.First();
reverse = false;
}
}
private void horizontaleRaster_Checked(object sender, RoutedEventArgs e)
{
//vertikaleRaster.IsChecked = false;
if(labelRichtung != null)
{
labelRichtung.Text = oben_unten.First();
reverse = false;
}
}
private void rasterAuswahl_Click(object sender, RoutedEventArgs e)
{
try
{
if(ExEvent != null)
{
ExEvent.Raise();
Reference selektiertesElement = document.Selection.PickObject(ObjectType.Element, new FassadenFilter());
Document currentDoc = document.Document;
Element element = currentDoc.GetElement(selektiertesElement);
if (element != null)
{
rasterAuswahl.Content = element.Name;
if (element is Wall)
{
Wall wall = (Wall)element;
CurtainGrid curtainGrid = wall.CurtainGrid;
if(curtainGrid != null)
{
if (vertikaleRaster.IsChecked == true)
{
List<ElementId> uGridLines = curtainGrid.GetUGridLineIds() as List<ElementId>;
if (reverse)
{
//IEnumerable<ElementId> ReverseduGridLines = uGridLines.Reverse();
//IList<ElementId> elementsToSelect = (IList<ElementId>)TakeEveryNthItem(ReverseduGridLines.ToList(), ((int)slider.Value), ((int)sliderVersatz.Value));
//document.Selection.SetElementIds(elementsToSelect);
}
}
if (horizontaleRaster.IsChecked == true)
{
ICollection<CurtainGridLine> vGridLines = (ICollection<CurtainGridLine>)curtainGrid.GetVGridLineIds().Select(i => currentDoc.GetElement(i));
}
}
}
}
else rasterAuswahl.Content = "Fassade auswählen";
}
}
catch
{
}
}
public static IList TakeEveryNthItem(IList list, int n, int offset = 0)
{
return list.Cast<object>().Where((_, i) => (i + 1 - offset) % n == 0).ToList();
}
private class FassadenFilter : ISelectionFilter
{
public bool AllowElement(Element elem)
{
if(elem.Category != null)
{
if(elem is Wall)
{
Wall wall = (Wall)elem;
if(wall.CurtainGrid != null)
{
return true;
}
}
else if(elem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Roofs)
{
FootPrintRoof roof = elem as FootPrintRoof;
if(roof != null)
{
if (roof.CurtainGrids != null)
{
return true;
}
}
}
}
return false;
}
public bool AllowReference(Reference reference, XYZ position)
{
return false;
}
}
private void richtungButton_Click(object sender, RoutedEventArgs e)
{
if (vertikaleRaster.IsChecked == true)
{
if(reverse == true)
{
labelRichtung.Text = rechts_links.First();
reverse = !reverse;
}
else
{
labelRichtung.Text = rechts_links.Last();
reverse = !reverse;
}
}
if(horizontaleRaster.IsChecked == true)
{
if (reverse == true)
{
labelRichtung.Text = oben_unten.First();
reverse = !reverse;
}
else
{
labelRichtung.Text = oben_unten.Last();
reverse = !reverse;
}
}
}
}
}
it shows me only these properties:
Can you please help me about that?
This is probably because you are casting it to a List<ElementId>. You should just use its actual type (ICollection<ElementId>) or use the var keyword to save some typing.
ICollection<ElementId> uGridLines = curtainGrid.GetUGridLineIds();
Hello,
thanks for the reply. It did not help in the beginning when I used ICollection. On forum I saw as IList and tried it out.. Same result.
Your breakpoint on line 78 is being hit before line 78 executes so your variable will be null until after it executes. Try setting a breakpoint on line 79 to see the result of line 78.
Can't find what you're looking for? Ask the community or share your knowledge.