Exemplo n.º 1
0
        protected override sealed void SolveInstance(IGH_DataAccess DA)
        {
            try
            {
                TrySolveInstance(DA);
            }
            catch (Exceptions.CancelException e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
            }
            catch (Autodesk.Revit.Exceptions.ApplicationException e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
            }
            catch (System.MissingMemberException e)
            {
                if (e.Message.Contains("Autodesk.Revit.DB."))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: Please consider update Revit to the latest revision.{Environment.NewLine}{e.Message.TripleDot(128)}");
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
                }

                DA.AbortComponentSolution();
            }
            catch (System.Exception e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
                DA.AbortComponentSolution();
            }
        }
Exemplo n.º 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve axis = null;
            DA.GetData("Curve", ref axis);

            GridType gridType = null;

            if (!DA.GetData("Type", ref gridType) && Params.Input[1].Sources.Count == 0)
            {
                gridType = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultElementTypeId(ElementTypeGroup.GridType)) as GridType;
            }

            if (gridType == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' There is no default level type loaded.", Params.Input[1].Name));
                DA.AbortComponentSolution();
                return;
            }

            string name = null;

            DA.GetData("Name", ref name);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, gridType));
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (InPreSolve)
            {
                // You must place "RunCount == 1" here,
                // because RunCount is reset when "InPreSolve" becomes "false"
                if (RunCount == 1)
                {
                    source = new CancellationTokenSource();
                }

                GH_SpeckleBase item = null;
                DA.GetData(0, ref item);
                var task = Task.Run(() => DoWork(item, DA), source.Token);
                TaskList.Add(task);
                return;
            }

            if (source.IsCancellationRequested || !GetSolveResults(DA, out var data))
            {
                DA.AbortComponentSolution(); // You must abort the `SolveInstance` iteration
                return;
            }

            DA.SetData(0, data);
        }
Exemplo n.º 4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve axis = null;
            DA.GetData("Axis", ref axis);

            FamilySymbol familySymbol = null;

            if (!DA.GetData("Type", ref familySymbol) && Params.Input[1].Sources.Count == 0)
            {
                familySymbol = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultFamilyTypeId(new ElementId(BuiltInCategory.OST_StructuralFraming))) as FamilySymbol;
            }

            if (familySymbol == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' There is no default structural framing family loaded.", Params.Input[1].Name));
                DA.AbortComponentSolution();
                return;
            }

            if (!familySymbol.IsActive)
            {
                familySymbol.Activate();
            }

            Autodesk.Revit.DB.Level level = null;
            DA.GetData("Level", ref level);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, familySymbol, level));
        }
Exemplo n.º 5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string pipeIdentifier = Params.Output[0].NickName;

            bool isWebUrl = PipeDataModel.Utils.PipeDataUtil.IsValidUrl(pipeIdentifier);

            if (isWebUrl)
            {
                PullFromWebPipe(pipeIdentifier);
            }
            else
            {
                PullFromLocalPipe(pipeIdentifier);
            }

            if (_newData != null)
            {
                //AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "received new data.");
                DA.SetDataList(0, _newData);
                _oldData = _newData.Select(x => x?.Duplicate()).ToList();
                _newData = null;
            }
            else if (_newData == null && _oldData != null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "did not receive any new data.");
                DA.SetDataList(0, _oldData);
            }
            else if (_newData == null && _oldData == null)
            {
                DA.AbortComponentSolution();
            }
        }
Exemplo n.º 6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            LevelType levelType = null;

            if (!DA.GetData("Type", ref levelType) && Params.Input[1].Sources.Count == 0)
            {
                levelType = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultElementTypeId(ElementTypeGroup.LevelType)) as LevelType;
            }

            if (levelType == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' There is no default level type loaded.", Params.Input[1].Name));
                DA.AbortComponentSolution();
                return;
            }

            double elevation = 0.0;

            DA.GetData("Elevation", ref elevation);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, elevation, levelType));
        }
Exemplo n.º 7
0
        void Iterate(IGH_DataAccess DA, Document doc, CommitAction action)
        {
            var element = PreviousStructureEnumerator?.MoveNext() ?? false ?
                          (
                PreviousStructureEnumerator.Current is Types.Element x && doc.Equals(x.Document) ?
                doc.GetElement(x.Id) :
                null
                          ) :
                          null;

            if (element?.Pinned != false)
            {
                var previous = element;

                try
                {
                    action(doc, ref element);
                }
                catch (System.ComponentModel.WarningException e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, e.Message.Replace("\r\n", " "));
                    element = null;
                }
                catch (System.ArgumentNullException)
                {
                    // Grasshopper components use to send a Null when they receive a Null without throwing any error
                    element = null;
                }
                catch (System.ArgumentException e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message.Replace("\r\n", " "));
                    element = null;
                }
                catch (Autodesk.Revit.Exceptions.ArgumentException e)
                {
                    var message = e.Message.Split("\r\n".ToCharArray()).First().Replace("Application.ShortCurveTolerance", "Revit.ShortCurveTolerance");
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);
                    element = null;
                }
                catch (System.Exception e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                    DA.AbortComponentSolution();
                }
                finally
                {
                    if (previous is object && !ReferenceEquals(previous, element) && previous.IsValidObject)
                    {
                        previous.Document.Delete(previous.Id);
                    }

                    if (element?.IsValidObject == true)
                    {
                        element.Pinned = true;
                    }
                }
            }

            DA.SetData(0, element);
        }
Exemplo n.º 8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            try
            {
                TrySolveInstance(DA);
            }
            catch (Exceptions.CancelException e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
            }
            catch (Exceptions.FailException e)
            {
                OnPingDocument()?.RequestAbortSolution();

                unhandledException = e;
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
            }
            catch (Autodesk.Revit.Exceptions.ApplicationException e)
            {
                if (AbortOnUnhandledException)
                {
                    unhandledException = e;
                }

                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
            }
            catch (System.MissingMemberException e)
            {
                unhandledException = e;

                if (e.Message.Contains("Autodesk.Revit.DB."))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: Please consider update Revit to the latest revision.{Environment.NewLine}{e.Message.TripleDot(128)}");
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
                }
            }
            catch (System.Exception e)
            {
                if (AbortOnUnhandledException)
                {
                    unhandledException = e;
                }

                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
            }

            if (unhandledException is object)
            {
                DA.AbortComponentSolution();
                Phase = GH_SolutionPhase.Failed;
            }
        }
Exemplo n.º 9
0
        private IGH_Goo DoWork(object item, IGH_DataAccess DA)
        {
            try
            {
                if (source.Token.IsCancellationRequested)
                {
                    DA.AbortComponentSolution();
                    return(null);
                }
                var converted = Extras.Utilities.TryConvertItemToSpeckle(item, Converter, true);

                if (source.Token.IsCancellationRequested)
                {
                    DA.AbortComponentSolution();
                    return(null);
                }

                if (converted == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                      $"Cannot convert item {DA.ParameterTargetPath(0)}[{DA.ParameterTargetIndex(0)}] to Speckle.");
                    return(new GH_SpeckleBase());
                }

                if (converted.GetType().IsSimpleType())
                {
                    return(new GH_ObjectWrapper(converted));
                }

                return(new GH_SpeckleBase {
                    Value = converted as Base
                });
            }
            catch (Exception e)
            {
                // If we reach this, something happened that we weren't expecting...
                Log.CaptureException(e);
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.InnerException?.Message ?? e.Message);
                return(new GH_SpeckleBase());
            }
        }
Exemplo n.º 10
0
        void Iterate(IGH_DataAccess DA, Document doc, Action <Document, Element> action)
        {
            var element = PreviousStructureEnumerator?.MoveNext() ?? false?
                          doc.GetElement(PreviousStructureEnumerator.Current as Types.Element ?? ElementId.InvalidElementId) :
                              null;

            if (element?.Pinned ?? true)
            {
                try
                {
                    action(doc, element);
                }
                catch (System.ComponentModel.WarningException e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, e.Message.Replace("\r\n", " "));
                    element?.Document.Delete(element.Id);
                    element = null;
                }
                catch (ArgumentNullException e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message.Replace("\r\n", " "));
                    element?.Document.Delete(element.Id);
                    element = null;
                }
                catch (ArgumentException e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message.Replace("\r\n", " "));
                    element?.Document.Delete(element.Id);
                    element = null;
                }
                catch (Autodesk.Revit.Exceptions.ArgumentException e)
                {
                    var message = e.Message.Split("\r\n".ToCharArray()).First().Replace("Application.ShortCurveTolerance", "Revit.ShortCurveTolerance");
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);
                    element?.Document.Delete(element.Id);
                    element = null;
                }
                catch (Exception e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                    DA.AbortComponentSolution();
                }
            }
            else
            {
                DA.SetData(0, element);
            }
        }
        private IGH_Goo DoWork(object item, IGH_DataAccess DA)
        {
            try
            {
                if (source.Token.IsCancellationRequested)
                {
                    DA.AbortComponentSolution();
                }

                return(ConnectorGrasshopper.Extras.Utilities.TryConvertItemToNative(item, Converter, true));
            }
            catch (Exception e)
            {
                // If we reach this, something happened that we weren't expecting...
                Log.CaptureException(e);
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.InnerException?.Message ?? e.Message);
                return(new GH_SpeckleBase());
            }
        }
Exemplo n.º 12
0
 protected override sealed void SolveInstance(IGH_DataAccess DA)
 {
     try
     {
         TrySolveInstance(DA);
     }
     catch (ApplicationException e)
     {
         AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
     }
     catch (Autodesk.Revit.Exceptions.ApplicationException e)
     {
         AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
     }
     catch (System.Exception e)
     {
         AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"{e.Source}: {e.Message}");
         DA.AbortComponentSolution();
     }
 }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (InPreSolve)
            {
                if (RunCount == 1)
                {
                    source = new CancellationTokenSource();
                }

                string item = null;
                DA.GetData(0, ref item);
                var task = Task.Run(() => DoWork(item, DA), source.Token);
                TaskList.Add(task);
                return;
            }

            if (source.IsCancellationRequested || !GetSolveResults(DA, out var data))
            {
                DA.AbortComponentSolution();
                return;
            }

            DA.SetData(0, data);
        }