Example #1
0
 public List<List<ElementId>> this[dynRevitTransactionNode node]
 {
     get
     {
         if (!storedElementIds.ContainsKey(node))
         {
             storedElementIds[node] = new List<List<ElementId>>()
             {
                 new List<ElementId>()
             };
         }
         return storedElementIds[node];
     }
 }
Example #2
0
 /// <summary>
 /// Utility method used with auto-generated assets for storing ElementIds generated during evaluate.
 /// Handles conversion of el
 /// </summary>
 /// <param name="node"></param>
 /// <param name="result"></param>
 public static void StoreElements(dynRevitTransactionNode node, List<object> results)
 {
     foreach (object result in results)
     {
         if (typeof (Element).IsAssignableFrom(result.GetType()))
         {
             node.Elements.Add(((Element) result).Id);
         }
         else if (typeof (ElementId).IsAssignableFrom(result.GetType()))
         {
             node.Elements.Add((ElementId) result);
         }
         else if (typeof (List<Element>).IsAssignableFrom(result.GetType()))
         {
             ((List<Element>) result).ForEach(x => node.Elements.Add(((Element) x).Id));
         }
         else if (typeof (List<ElementId>).IsAssignableFrom(result.GetType()))
         {
             ((List<ElementId>) result).ForEach(x => node.Elements.Add((ElementId) x));
         }
     }
 }
Example #3
0
        /// <summary>
        /// Invoke an API method, using the node's lacing strategy to build lists of arguments
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="args">The incoming Values on the node.</param>
        /// <param name="api_base_type">The API's base type whose method we will invoke.</param>
        /// <param name="pi">An array of parameter info for the method.</param>
        /// <param name="mi">The method info for the method.</param>
        /// <param name="return_type">The expected return type from the method.</param>
        /// <returns></returns>
        public static Value InvokeAPIMethod(dynRevitTransactionNode node, FSharpList<Value> args, Type api_base_type, ParameterInfo[] pi, MethodBase mi, Type return_type)
        {
            //if any argument are a list, honor the lacing strategy
            //compile a list of parameter lists to be used in our method invocation
            List<List<object>> parameters = null;

            switch (node.ArgumentLacing)
            {
                case LacingStrategy.Single:
                    parameters = GetSingleArguments(args, pi);
                    break;
                case LacingStrategy.Shortest:
                    parameters = GetShortestArguments(args, pi);
                    break;
                case LacingStrategy.Longest:
                    parameters = GetLongestArguments(args, pi);
                    break;
                default:
                    parameters = GetSingleArguments(args, pi);
                    break;
            }

            var invocationTargetList = new List<object>();

            if (api_base_type == typeof(Autodesk.Revit.Creation.Document) ||
                api_base_type == typeof(Autodesk.Revit.Creation.FamilyItemFactory) ||
                api_base_type == typeof(Autodesk.Revit.Creation.ItemFactoryBase))
            {
                if (dynRevitSettings.Doc.Document.IsFamilyDocument)
                {
                    invocationTargetList.Add(dynRevitSettings.Doc.Document.FamilyCreate);
                }
                else
                {
                    invocationTargetList.Add(dynRevitSettings.Doc.Document.Create);
                }
            }
            else if (api_base_type == typeof(Autodesk.Revit.Creation.Application))
            {
                invocationTargetList.Add(dynRevitSettings.Revit.Application.Create);
            }
            else
            {
                if (!mi.IsStatic && !mi.IsConstructor)
                {
                    if (args[0].IsList)
                    {
                        invocationTargetList.AddRange(((Value.List)args[0]).Item.Select(x => DynamoTypeConverter.ConvertInput(x, api_base_type)));
                    }
                    else
                    {
                        //the first input will always hold the instance
                        //whose methods you want to invoke
                        invocationTargetList.Add(DynamoTypeConverter.ConvertInput(args[0], api_base_type));
                    }
                }
            }

            //object result = null;
            List<object> results = null;

            //if the method info is for a constructor, then
            //call the constructor for each set of parameters
            //if it's an instance method, then invoke the method for
            //each instance passed in.
            results = mi.IsConstructor ?
                parameters.Select(x => ((ConstructorInfo) mi).Invoke(x.ToArray())).ToList() :
                invocationTargetList.SelectMany(x => parameters.Select(y => mi.Invoke(x, y.ToArray())).ToList()).ToList();

            dynRevitUtils.StoreElements(node, results);

            return ConvertAllResults(results);
        }
Example #4
0
 public bool HasElements(dynRevitTransactionNode node)
 {
     return storedElementIds.ContainsKey(node);
 }