'Unwrap Element' in Zero Touch Node

Hello,

I wrote a custom python script that is used for taking in a list of views, and elements of various types, and overriding their graphics settings to color them quickly.

I used a function in python called ‘UnwrapElement’ so that I could take a dynamo list of ‘ceiling’ elements and use members of revit’s ‘element’ class. I am now trying to do this in C#, is there a similar function for zero touch nodes in visual studio?

  • Jed

Could be useful to share what you have so far in regards to the zero touch node.

1 Like

We will need a little more than just a theoretical question. Also, I think you asked the same question on my blog. It would be nice to get a sample code…

I will skip the python code and actual functionality of what I’m trying to do, it takes up alot of space and is about 2 steps ahead of where the problem lies.

Here are some sample functions that demonstrate the problem (place inside a zero touch node):

   public static string inputTest1(object[] elements)
   {
         string output = elements.Count<object>().ToString();
         return output;
   }

    public static string inputTest2(Ceiling[] elements)
    {
           string output = elements.Count<Ceiling>().ToString();
           return output;
    }

    public static string inputTest3(object[] elements)
    {
           string output = "";
           try
           {
                foreach (object o in elements)
                {
                     Element e = o as Element;
                     output += e.Id.ToString();     
                }
           }
           catch (Exception e)
           {
                output += e.ToString();
           }
           return output;
    }

    public static string inputTest4(Ceiling[] elements)
    {
        string output = "";
        try
        {
               foreach (Ceiling c in elements)
               {
                    Element e = c as Element;
                    output += e.Id.ToString();
               }
        }
        catch (Exception e)
        {
               output += e.ToString();
        }
        return output;
    }

I have tried receiving the input as Revit Elements, Geometry, GeometryBase, and a few others without luck. Conrad, you mentioned using element.InternalElement, but I haven’t found a class that has that method available.

Does my problem make sense? I am simply trying to read in Revit Elements as Revit Elements…had a bit of trouble with this in python, and the solution was using the ‘UnwrapElement’ function

I have a similar method but I send in a list of elements and send out a list of lists. I have made a few changes for ceilings.

 public List<Object> input(List<Element> elements)
    {
        List<Object> dataList = new List<object>();

        List<string> CountAsList = new List<string>();
        List<ElementId> IDList = new List<ElementId>();
        List<Ceiling> CeilingList = new List<Ceiling>();
        List<string> CeilingNameList = new List<string>();

        CountAsList.Add(elements.Count.ToString());
        foreach (Element e in elements)
            IDList.Add(e.Id);

        foreach (Element e in elements)
        {
            Ceiling w = e as Ceiling;
            CeilingList.Add(w);
        }

        foreach (Element e in elements)
        {
            Ceiling w = e as Ceiling;
            CeilingNameList.Add(w.Name);
        }

        dataList.Add(CountAsList);
        dataList.Add(IDList);
        dataList.Add(CeilingList);
        dataList.Add(CeilingNameList);


        return dataList;
    }
1 Like
5 Likes

Thank you so much! This is what I was missing

Thank you Danny!

I made a generic method to do this. Thanks for the video reference. It help me.

        /// <summary>
        /// Unwraps a Dynamo Element to Revit API Element of generic type T
        /// </summary>
        /// <typeparam name="T">The class type of Revit API Element</typeparam>
        /// <param name="element">The Dynamo Element to be unwrapped</param>
        /// <returns>Unwrapped element</returns>
        public static T UnwrapElement<T>(Revit.Elements.Element element) where T : Autodesk.Revit.DB.Element
        {
            try
            {
                return element.InternalElement as T;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
3 Likes