示例#1
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index = -1;

            bool run = false;

            index = Params.IndexOfInputParam("_run");
            if (index == -1 || !dataAccess.GetData(index, ref run) || !run)
            {
                return;
            }

            ConvertSettings convertSettings = null;

            index = Params.IndexOfInputParam("_convertSettings_");
            if (index != -1)
            {
                dataAccess.GetData(index, ref convertSettings);
            }

            convertSettings = this.UpdateSolutionEndEventHandler(convertSettings);

            AdjacencyCluster adjacencyCluster = null;

            index = Params.IndexOfInputParam("_adjacencyCluster");
            if (index == -1 || !dataAccess.GetData(index, ref adjacencyCluster))
            {
                return;
            }

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            StartTransaction(document);

            convertSettings.AddParameter("AdjacencyCluster", adjacencyCluster);

            List <Element> elements = Analytical.Revit.Convert.ToRevit(adjacencyCluster, document, convertSettings);

            index = Params.IndexOfOutputParam("elements");
            if (index != -1)
            {
                dataAccess.SetDataList(index, elements);
            }
        }
示例#2
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index            = -1;
            int index_Elements   = -1;
            int index_Successful = -1;

            index_Successful = Params.IndexOfOutputParam("successful");
            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, false);
            }

            index_Elements = Params.IndexOfOutputParam("elements");
            if (index_Elements != -1)
            {
                dataAccess.SetData(index_Elements, null);
            }

            bool run = false;

            index = Params.IndexOfInputParam("_run");
            if (index == -1 || !dataAccess.GetData(index, ref run) || !run)
            {
                return;
            }

            ConvertSettings convertSettings = null;

            index = Params.IndexOfInputParam("_convertSettings_");
            if (index != -1)
            {
                dataAccess.GetData(index, ref convertSettings);
            }

            convertSettings = this.UpdateSolutionEndEventHandler(convertSettings);

            SAMObject sAMObject = null;

            index = Params.IndexOfInputParam("_analytical");
            if (index == -1 || !dataAccess.GetData(index, ref sAMObject))
            {
                return;
            }

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            StartTransaction(document);

            if (!(sAMObject is Panel) && !(sAMObject is Aperture) && !(sAMObject is Space) && !(sAMObject is AdjacencyCluster) && !(sAMObject is AnalyticalModel))
            {
                return;
            }

            AdjacencyCluster adjacencyCluster = null;

            if (sAMObject is AdjacencyCluster)
            {
                adjacencyCluster = (AdjacencyCluster)sAMObject;
                convertSettings.AddParameter("AdjacencyCluster", adjacencyCluster);
            }
            else if (sAMObject is AnalyticalModel)
            {
                adjacencyCluster = ((AnalyticalModel)sAMObject).AdjacencyCluster;
                convertSettings.AddParameter("AnalyticalModel", (AnalyticalModel)sAMObject);
            }


            if (adjacencyCluster != null)
            {
                adjacencyCluster.GetPanels()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
                adjacencyCluster.GetSpaces()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
            }
            else
            {
                Core.Revit.Modify.RemoveExisting(convertSettings, document, sAMObject);
            }


            object @object = Analytical.Revit.Convert.ToRevit(sAMObject as dynamic, document, convertSettings);

            IEnumerable <Element> elements = null;

            if (@object is IEnumerable)
            {
                elements = ((IEnumerable)@object).Cast <Element>();
            }
            else
            {
                elements = new List <Element>()
                {
                    @object as Element
                }
            };

            //if(elements != null)
            //{
            //    foreach(Element element in elements)
            //    {
            //        ElementId elementId = element.Id;
            //        if (elementId == null)
            //            continue;

            //        elementIds.Add(elementId);
            //    }
            //}

            if (index_Elements != -1)
            {
                dataAccess.SetDataList(index_Elements, elements);
            }

            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, elements != null && elements.Count() > 0);
            }
        }

        //protected override void OnAfterStart(Document document, string strTransactionName)
        //{
        //    base.OnAfterStart(document, strTransactionName);

        //    elementIds = new HashSet<ElementId>();
        //}

        //protected override void OnBeforeCommit(Document document, string strTransactionName)
        //{
        //    base.OnBeforeCommit(document, strTransactionName);

        //    if(elementIds != null && elementIds.Count != 0)
        //    {
        //        List<Wall> walls = new FilteredElementCollector(document, elementIds).OfClass(typeof(Wall)).Cast<Wall>().ToList();
        //        if(walls != null && walls.Count != 0)
        //        {
        //            Dictionary<Wall, int> dictionary = new Dictionary<Wall, int>();
        //            walls.ForEach(x => dictionary[x] = x.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).AsInteger());

        //            using (SubTransaction subTransaction = new SubTransaction(document))
        //            {
        //                subTransaction.Start();

        //                foreach (Wall wall in dictionary.Keys)
        //                    wall.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0);

        //                document.Regenerate();

        //                subTransaction.Commit();

        //                subTransaction.Start();

        //                foreach (KeyValuePair<Wall, int> keyValuePair in dictionary)
        //                    keyValuePair.Key.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(keyValuePair.Value);

        //                subTransaction.Commit();
        //            }
        //        }
        //    }
        //}
    }