Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GetUGridLineIds() returns null

4 REPLIES 4
Reply
Message 1 of 5
dmaral
216 Views, 4 Replies

GetUGridLineIds() returns null

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;

                }

            }
        }
    }

}

 

 

dmaral_0-1672934904086.png

 

 

it shows me only these properties:

dmaral_0-1672936153078.png

 



Can you please help me about that?

 

4 REPLIES 4
Message 2 of 5
mhannonQ65N2
in reply to: dmaral

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();

 

Message 3 of 5
dmaral
in reply to: mhannonQ65N2

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.

dmaral_0-1672937220337.png

 

Message 4 of 5
mhannonQ65N2
in reply to: dmaral

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.

Message 5 of 5
dmaral
in reply to: mhannonQ65N2

If I try to store them in a variable then it is shown as null but if I use curtainGrid.GetUGridLineIds() in a funtion, it works.. :S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report