Beispiel #1
0
 private static List <object> Flatten(object list, int amt, List <object> acc)
 {
     if (amt == 0)
     {
         if (MainTools.IsList(list))
         {
             foreach (object item in (System.Collections.IEnumerable)list)
             {
                 acc.Add(item);
             }
         }
         else
         {
             acc.Add(list);
         }
     }
     else
     {
         foreach (object item in (System.Collections.IEnumerable)list)
         {
             if (MainTools.IsList(item))
             {
                 var type = item.GetType();
                 acc = Flatten(item, amt - 1, acc);
             }
             else
             {
                 acc.Add(item);
             }
         }
     }
     return(acc);
 }
Beispiel #2
0
        /// <summary>
        /// Compacts single Clashtest list of ClashesTest
        /// </summary>
        /// <param name="input"></param>
        public IEnumerable <object> CompactClashes(object input)
        {
            var doc = Autodesk.Navisworks.Api.Application.ActiveDocument;

            if (input != null)
            {
                var t = input.GetType();

                if (t == typeof(SavedItemReference))
                {
                    var ClashFromReference = doc.ResolveReference(input as SavedItemReference) as ClashTest;
                    var clashes            = doc.GetClash();
                    clashes.TestsData.TestsCompactTest(ClashFromReference);
                    yield return(input);
                }
                if (MainTools.IsList(input))

                {
                    var listData = input as List <object>;
                    if (listData[0].GetType() == typeof(Autodesk.Navisworks.Api.Clash.ClashTest))
                    {
                        foreach (var ct in input as List <object> )
                        {
                            var ClashFromReference = doc.ResolveReference(ct as SavedItemReference) as ClashTest;
                            var clashes            = doc.GetClash();
                            clashes.TestsData.TestsCompactTest(ClashFromReference);

                            yield return(ct);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public List <object> RenameClashes(object Guids, object Names)
        {
            //Get clashes from document
            Document      doc            = Application.ActiveDocument;
            DocumentClash documentClash  = doc.GetClash();
            var           output         = new List <object>();
            var           TemplistOfTest = new List <ClashTest>();

            if (MainTools.IsList(Guids) && MainTools.IsList(Names))
            {
                var guidlist  = (List <object>)Guids;
                var namesList = (List <object>)Names;

                if (guidlist.Count == namesList.Count)
                {
                    for (int i = 0; i < guidlist.Count; i++)
                    {
                        Guid guid           = new Guid(guidlist[i].ToString().Replace("\"", ""));
                        var  clashReference = documentClash.TestsData.ResolveGuid(guid);
                        var  name           = namesList[i].ToString();
                        documentClash.TestsData.TestsEditDisplayName(clashReference, name);;
                        output.Add(clashReference);
                    }
                }
                else
                {
                    output.Add("Error, be sure you have same amount of guids and names");
                }
            }
            return(output);
        }
Beispiel #4
0
        /// <summary>
        /// Check each element of a list of string
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public List <object> Replace(object a, object b, object c)
        {
            List <object> output = new List <object>();

            if (MainTools.IsList(a) && MainTools.IsString(b) && MainTools.IsString(c))
            {
                foreach (var item in (System.Collections.IEnumerable)(a))
                {
                    if (MainTools.IsString(item))
                    {
                        string container = item as string;
                        output.Add(container.Replace(b.ToString(), c.ToString()));
                    }
                }
            }
            else
            {
                if (a.GetType() == typeof(string) && MainTools.IsString(b) && MainTools.IsString(c))

                {
                    string container = a as string;
                    output.Add(container.Replace(b.ToString(), c.ToString()));
                }
            }
            return(output);
        }
Beispiel #5
0
        //TODO: convert to tuple
        private Tuple <List <object>, List <object> > GetElementsInClashTest(object input)
        {
            if (input != null)
            {
                List <object> itemA = new List <object>();
                List <object> itemB = new List <object>();
                if (MainTools.IsList(input))
                {
                    foreach (var c in (System.Collections.IEnumerable)InputPorts[0].Data)
                    {
                        if (c.GetType() == typeof(ClashResult))
                        {
                            var clash = c as ClashResult;
                            itemA.AddRange(clash.CompositeItemSelection1);
                            itemB.AddRange(clash.CompositeItemSelection2);
                        }
                        if (c.GetType() == typeof(ClashResultGroup))
                        {
                            var group = c as ClashResultGroup;

                            itemA.AddRange(group.CompositeItemSelection1);
                            itemB.AddRange(group.CompositeItemSelection2);
                        }
                    }
                }

                return(new Tuple <List <object>, List <object> >(itemA, itemB));
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        public override void Calculate()
        {
            List <object> clashResultList = new List <object>();

            var input = InputPorts[0].Data;
            //Get clashes from document
            Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;

            //Check for null in input
            if (MainTools.IsList(input))
            {
                foreach (var i in (System.Collections.IEnumerable)input)
                {
                    if (i.GetType() == typeof(SavedItemReference))
                    {
                        ClashTest item = doc.ResolveReference(i as SavedItemReference) as ClashTest;
                        foreach (var t in item.Children)
                        {
                            clashResultList.Add(t);
                        }
                    }
                }
                OutputPorts[0].Data = clashResultList;
            }

            if (input.GetType() == typeof(SavedItemReference))
            {
                ClashTest item = doc.ResolveReference(input as SavedItemReference) as ClashTest;
                foreach (var t in item.Children)
                {
                    clashResultList.Add(t);
                }
                OutputPorts[0].Data = clashResultList;
            }
        }
Beispiel #7
0
        public static void ExportCSV(string filePath, object data)
        {
            using (var writer = new StreamWriter(System.IO.Path.GetFullPath(filePath)))
            {
                //TODO cast object to list
                foreach (var line in (System.Collections.IList)data)
                {
                    int count = 0;
                    if (MainTools.IsList(line))
                    {
                        var t = line.GetType();
                        var l = (System.Collections.IList)line;
                        foreach (var entry in l)
                        {
                            writer.Write(MainTools.Quoted((entry ?? "").ToString().Replace("\n", string.Empty)));
                            if (++count < l.Count)
                            {
                                writer.Write(",");
                            }
                        }
                        writer.WriteLine();
                    }
                    else
                    {
                        writer.Write(MainTools.Quoted((line ?? "").ToString().Replace("\n", string.Empty)));

                        writer.Write(",");

                        writer.WriteLine();
                    }
                }
            }
        }
Beispiel #8
0
        public List <object> getClashInfo(object input)
        {
            var output = new List <object>();


            if (MainTools.IsList(input))
            {
                foreach (var item in (IList <object>)input)
                {
                    var clash = item as IClashResult;
                    if (clash != null)

                    {
                        var name         = clash.DisplayName;
                        var status       = clash.Status;
                        var ApprovedBy   = clash.ApprovedBy;
                        var ApprovedTime = clash.ApprovedTime;
                        var AssignedTo   = clash.AssignedTo;
                        var Description  = clash.Description;

                        string grid  = null;
                        string level = null;
                        //DANGER WILL ROBINSON!!
                        string GUID = (clash as ClashResult) != null? (clash as ClashResult).Guid.ToString(): (clash as ClashResultGroup).Guid.ToString();
                        var    x    = clash.Center.X;
                        var    y    = clash.Center.Y;
                        var    z    = clash.Center.Z;

                        GridSystem gridSystem = Application.MainDocument.Grids.ActiveSystem;

                        if (gridSystem.ClosestIntersection(clash.Center) != null)
                        {
                            GridIntersection closestGridIntersection = gridSystem.ClosestIntersection(clash.Center);
                            grid  = closestGridIntersection.Line1.DisplayName + "-" + closestGridIntersection.Line2.DisplayName;
                            level = closestGridIntersection.Level.DisplayName;
                        }
                        output.Add(new List <object>()
                        {
                            name,
                            status,
                            ApprovedBy,
                            ApprovedTime,
                            AssignedTo,
                            Description,
                            grid,
                            level,
                            GUID,
                            x,
                            y,
                            z
                        });
                    }
                }
            }

            return(output);
        }
Beispiel #9
0
        private IList <object> Process(object input)
        {
            List <object> output = new List <object>();
            Document      doc    = Autodesk.Navisworks.Api.Application.ActiveDocument;

            if (input != null)
            {
                if (MainTools.IsList(input))
                {
                    foreach (var item in (System.Collections.IEnumerable)InputPorts[0].Data)
                    {
                        var iterator = item;

                        if (item.GetType() == typeof(SavedItemReference))
                        {
                            iterator = doc.ResolveReference(item as SavedItemReference);
                        }

                        try
                        {
                            var properties = iterator.GetType().GetProperties();
                            var prop       = new List <string>();
                            foreach (var p in properties)
                            {
                                prop.Add(p.Name);
                            }
                            output.Add(prop);
                        }
                        catch { output.Add(null); }
                    }
                }
                else
                {
                    var iterator = input;

                    if (input.GetType() == typeof(SavedItemReference))
                    {
                        iterator = doc.ResolveReference(input as SavedItemReference);
                    }

                    try
                    {
                        var properties = iterator.GetType().GetProperties();
                        var prop       = new List <string>();
                        foreach (var p in properties)
                        {
                            prop.Add(p.Name);
                        }
                        output.Add(prop);
                    }
                    catch { output.Add(null); }
                }
            }
            return(output as IList <object>);
        }
Beispiel #10
0
        public override void Calculate()
        {
            var input = InputPorts[0].Data;

            if (input != null)
            {
                if (MainTools.IsList(input))
                {
                    OutputPorts[0].Data = Transpose((System.Collections.IList)input);
                }
            }
        }
Beispiel #11
0
        public override void Calculate()
        {
            var input = InputPorts[0].Data;
            var path  = InputPorts[1].Data;

            if (input != null && path != null)
            {
                if (MainTools.IsList(input))
                {
                    var t = input.GetType();
                    ExportCSV(path.ToString(), input);
                }
            }
        }
Beispiel #12
0
        public override void Calculate()
        {
            var input = InputPorts[0].Data;
            var mask  = InputPorts[1].Data;

            if (input != null && mask != null)
            {
                if (MainTools.IsList(input) && MainTools.IsList(mask))
                {
                    var filtered = FilterByBoolMask(input as IList, mask as IList);
                    OutputPorts[0].Data = ((IEnumerable)filtered["in"]).Cast <object>().ToList();

                    OutputPorts[1].Data = ((IEnumerable)filtered["out"]).Cast <object>().ToList();
                }
            }
            GC.Collect();
        }
Beispiel #13
0
        /// <summary>
        /// Check each element of a list of string
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public List <object> Contains(object a, object b)
        {
            List <object> output = new List <object>();

            if (MainTools.IsList(a) & MainTools.IsString(b))
            {
                foreach (var item in (System.Collections.IEnumerable)(a))
                {
                    if (MainTools.IsString(item))
                    {
                        string container = item as string;
                        output.Add(container.Contains(b as string));
                    }
                }
            }
            return(output);
        }
Beispiel #14
0
        public override void Calculate()
        {
            List <object> output = new List <object>();

            if (InputPorts[0].Data != null)
            {
                var input     = InputPorts[0].Data;
                var values    = InputPorts[2].Data;
                var parameter = InputPorts[1].Data.ToString();
                if (MainTools.IsList(input) && MainTools.IsList(values))
                {
                    var ListA = (System.Collections.IList)input;
                    var ListB = (System.Collections.IList)values;

                    if (ListB.Count == ListA.Count)
                    {
                        try
                        {
                            oneToOne(input, values, parameter);
                        }

                        catch (Exception e)
                        {
                            output.Add(e.Message);
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                    try
                    {
                        manyToOne(input, values, parameter);
                    }
                    catch (Exception e)
                    {
                        var mm = e.Message;
                        output.Add(null);
                    }
                }
            }

            OutputPorts[0].Data = output;
        }
Beispiel #15
0
        public override void Calculate()
        {
            var input = InputPorts[0].Data;

            if (input != null)
            {
                var  tt     = input.GetType();
                bool istype = input.GetType() == typeof(SelectionSet);

                if (MainTools.IsList(input) || istype)
                {
                    //IList<SelectionSet> searchs = (IList<SelectionSet>)InputPorts[0].Data;

                    media.Color color = (media.Color)InputPorts[1].Data;

                    //Convert ARGB Alpha to normaliced transparency
                    double t            = ((-color.A / 255.0) + 1) * 100;
                    double transparency = t;

                    foreach (var s in (System.Collections.IEnumerable)input)
                    {
                        ApplyAppearance(s as SelectionSet, TransformColor(color), transparency);
                    }

                    OutputPorts[0].Data = (System.Collections.IEnumerable)input;
                }

                if (MainTools.IsList(input) && MainTools.ListContainsType(input, typeof(ModelItem)) || input is ModelItem)
                {
                    List <ModelItem> searchs = (List <ModelItem>)InputPorts[0].Data;

                    media.Color color = (media.Color)InputPorts[1].Data;

                    //Convert ARGB Alpha to normaliced transparency
                    double t            = ((-color.A / 255.0) + 1) * 100;
                    double transparency = t;


                    ApplyAppearance(searchs, TransformColor(color), transparency);

                    OutputPorts[0].Data = (List <ModelItem>)InputPorts[0].Data;
                }
            }
        }
Beispiel #16
0
        public override void Calculate()
        {
            List <object> output = new List <object>();

            if (InputPorts[0].Data != null)
            {
                var input     = InputPorts[0].Data;
                var parameter = InputPorts[1].Data;
                if (MainTools.IsList(input) && MainTools.IsList(parameter))
                {
                    var ListA = (System.Collections.IList)input;
                    var ListB = (System.Collections.IList)parameter;

                    if (ListB.Count == ListA.Count)
                    {
                        try
                        {
                            oneToOne(input, parameter);
                        }

                        catch (Exception e)
                        {
                            output.Add(e.Message);
                        }
                    }
                    else
                    {
                        ManyToSome(input, parameter);
                    }
                }
                else
                {
                    try
                    {
                    }
                    catch
                    {
                        output.Add(null);
                    }
                }
            }

            OutputPorts[0].Data = output;
        }
Beispiel #17
0
        public object StringResult(object a)
        {
            if (MainTools.IsList(a))
            {
                List <object> output = new List <object>();
                List <object> input  = a as List <object>;

                foreach (object x in input)
                {
                    output.Add(x.ToString().ToLower());
                }

                return(output);
            }
            else
            {
                return(a.ToString().ToLower());
            }
        }
Beispiel #18
0
        public override void Calculate()
        {
            var input  = InputPorts[0].Data;
            var output = new List <ModelItemCollection>();

            if (input != null)
            {
                var type = input.GetType();

                if (type == typeof(SelectionSet))
                {
                    var selectionSet = input as SelectionSet;

                    ModelItemCollection searchResults =
                        selectionSet.Search.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false);
                    output.Add(searchResults);
                }

                if (MainTools.IsList(input) && MainTools.ListContainsType(input, typeof(SelectionSet)))
                {
                    foreach (var item in input as List <SelectionSet> )
                    {
                        var selectionSet = item as SelectionSet;

                        ModelItemCollection searchResults =
                            selectionSet.Search.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false);
                        output.Add(searchResults);
                    }
                }
            }
            var objects = new List <object>();

            foreach (var item in output)
            {
                List <ModelItem> modelitems = new List <ModelItem>();
                foreach (var model in item)
                {
                    modelitems.Add(model);
                }
                objects.Add(modelitems);
            }
            OutputPorts[0].Data = objects;
        }
Beispiel #19
0
        /// <summary>
        /// Save object Document to object Path
        /// </summary>
        /// <param name="document"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        private object SaveAsNWF(object document, object path)
        {
            var output = new object();

            output = null;
            if (document != null && path != null && document.GetType() == typeof(Document))
            {
                if (MainTools.IsList(path))
                {
                    foreach (var item in (System.Collections.IEnumerable)path)
                    {
                        var      filepath = item.ToString();
                        Document doc      = document as Document;
                        try
                        {
                            doc.SaveFile(item.ToString());
                            output = document;
                        }
                        catch (Exception exc)
                        {
                        }
                    }
                }
                else
                {
                    var      filepath = path.ToString();
                    Document doc      = document as Document;

                    try
                    {
                        doc.SaveFile(path.ToString());
                        output = document;
                    }
                    catch (Exception exc)
                    {
                    }
                }
            }
            return(output);
        }
Beispiel #20
0
        private List<object> RefreshClashes(object input)
        {
            //Get clashes from document
            Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
            var testData = doc.GetClash().TestsData;
            var output = new List<object>();
            if (input != null)
            {


                if (MainTools.IsList(input))
                {


                    foreach (var item in (System.Collections.IEnumerable)input)
                    {

                        var ClashTest = doc.ResolveReference(item as SavedItemReference) as ClashTest;
                        var clash = doc.Clash as DocumentClash;
                        testData.TestsRunTest(ClashTest);
                        wait(1);
                        output.Add(item);
                    }

                }

                if (input.GetType() == typeof(SavedItemReference))
                {

                    var ClashTest = doc.ResolveReference(input as SavedItemReference) as ClashTest;
                    testData.TestsRunTest(ClashTest);
                    output.Add(input);
                }

            }



            return output;
        }
Beispiel #21
0
 public void recursion(object obj)
 {
     if (MainTools.IsList(obj))
     {
         foreach (var item in (System.Collections.IEnumerable)obj)
         {
             var t = item.GetType();
             if (MainTools.IsList(item))
             {
                 recursion(item);
             }
             else
             {
                 lines.Add(item.ToString());
             }
         }
     }
     else
     {
         lines.Add(obj.ToString());
     }
 }
Beispiel #22
0
        public object getLocationFromGrids(object input)
        {
            var output = new List <List <string> >();
            var grids  = new List <object>();
            var level  = new List <object>();
            var X      = new List <object>();
            var Y      = new List <object>();
            var Z      = new List <object>();

            if (MainTools.IsList(input))
            {
                foreach (var item in (IList <object>)input)
                {
                    if (item.GetType() == typeof(IClashResult))

                    {
                        var clash = item as IClashResult;

                        GridSystem gridSystem = Application.MainDocument.Grids.ActiveSystem;

                        if (gridSystem.ClosestIntersection(clash.Center) != null)
                        {
                            GridIntersection closestGridIntersection = gridSystem.ClosestIntersection(clash.Center);
                            grids.Add(closestGridIntersection.DisplayName);
                            level.Add(closestGridIntersection.Level.DisplayName);
                            X.Add(clash.Center.X);
                            Y.Add(clash.Center.Y);
                            Z.Add(clash.Center.Z);
                        }
                    }
                }
            }

            return(new List <List <object> >()
            {
                grids, level, X, Y, Z
            });
        }
Beispiel #23
0
        private IList <object> SetValuesToModelItems(object model, string category, string property, object value)
        {
            if (MainTools.IsList(model) &&
                category is string &&
                property is string &&
                value != null)
            {
                var           modelList  = (System.Collections.IList)model;
                List <object> modelItems = new List <object>();


                if (MainTools.IsList(value))
                {
                    var valueList = (System.Collections.IList)value;


                    if (modelList.Count == valueList.Count)
                    {
                        for (int i = 0; i < modelList.Count; i++)
                        {
                            var v = valueList[i].ToString();

                            SetValues(modelList[i] as ModelItem, category, property, v);
                            modelItems.Add(modelList[i] as ModelItem);
                        }
                    }
                }



                return(modelItems);
            }
            else
            {
                return(null);
            }
        }
Beispiel #24
0
        public void process(object Guids, object Names)
        {
            //Get clashes from document
            Document      doc           = Application.ActiveDocument;
            DocumentClash documentClash = doc.GetClash();

            var TemplistOfTest = new List <ClashTest>();

            if (MainTools.IsList(Guids) && MainTools.IsList(Names))
            {
                var guidlist  = (List <object>)Guids;
                var namesList = (List <object>)Names;

                if (guidlist.Count == namesList.Count)
                {
                    for (int i = 0; i < guidlist.Count; i++)
                    {
                        Guid guid           = new Guid(guidlist[i].ToString());
                        var  clashReference = documentClash.TestsData.ResolveGuid(guid);
                        documentClash.TestsData.TestsEditDisplayName(clashReference, namesList[i].ToString());
                    }
                }
            }
        }
Beispiel #25
0
        private IList <object> Process(Document doc, List <object> output)
        {
            if (InputPorts[0].Data != null)
            {
                var input      = InputPorts[0].Data;
                var properties = InputPorts[1].Data;
                if (MainTools.IsList(input))
                {
                    foreach (var item in (System.Collections.IEnumerable)input)
                    {
                        var iterator = item;

                        if (item.GetType() == typeof(SavedItemReference))
                        {
                            iterator = doc.ResolveReference(item as SavedItemReference);
                        }

                        if (MainTools.IsList(properties))
                        {
                            foreach (var prop in (System.Collections.IEnumerable)properties)
                            {
                                dynamic      d      = prop;
                                string       method = prop as string;
                                var          types  = iterator.GetType();
                                PropertyInfo props  = types.GetProperty(method);

                                object value = props.GetValue(iterator);

                                output.Add(value);
                            }
                        }
                        else
                        {
                            try
                            {
                                dynamic d      = properties;
                                string  method = properties as string;
                                method = d;
                                var          types = iterator.GetType();
                                PropertyInfo prop  = types.GetProperty(method);

                                object value = prop.GetValue(iterator);

                                output.Add(value);
                            }

                            catch
                            {
                                output.Add(null);
                            }
                        }
                    }
                }
                else
                {
                    var iterator = input;

                    if (input.GetType() == typeof(SavedItemReference))
                    {
                        iterator = doc.ResolveReference(input as SavedItemReference);
                    }

                    if (MainTools.IsList(properties))
                    {
                        foreach (var prop in (System.Collections.IEnumerable)properties)
                        {
                            string       method = prop as string;
                            var          types  = iterator.GetType();
                            PropertyInfo props  = types.GetProperty(method);

                            object value = props.GetValue(iterator);

                            output.Add(value);
                        }
                    }
                    else
                    {
                        try
                        {
                            string       method = properties as string;
                            var          types  = iterator.GetType();
                            PropertyInfo prop   = types.GetProperty(method);

                            object value = prop.GetValue(iterator);

                            output.Add(value);
                        }

                        catch
                        {
                            output.Add(null);
                        }
                    }
                }
            }

            return(output as IList <object>);
        }