Example #1
0
        public static bool GetDataOrDefault(IGH_Component component, IGH_DataAccess DA, string name, out DB.Document document)
        {
            document = default;
            var _Document_ = component.Params.IndexOfInputParam(name);

            if (_Document_ < 0)
            {
                document = Revit.ActiveDBDocument;
                if (document?.IsValidObject != true)
                {
                    component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "There is no active Revit document");
                    return(false);
                }

                // In case the user has more than one document open we show which one this component is working on
                if (Revit.ActiveDBApplication.Documents.Size > 1)
                {
                    component.Message = document.Title.TripleDot(16);
                }
            }
            else
            {
                document = default;
                DA.GetData(_Document_, ref document);
                if (document?.IsValidObject != true)
                {
                    component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter Document failed to collect data");
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
 public void ThrowWarnings()
 {
     foreach (var name in warningsToThrow)
     {
         hostRef.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Access not consistent for {name} property. Output data tree may be messy and not consistent");
     }
 }
Example #3
0
        internal static (string Name, ObjectProperty Property) RetrieveProperties(IGH_DataAccess DA, int paramIndex, IGH_Component @this)
        {
            var            param = @this.Params.Input[paramIndex];
            ObjectProperty prop;
            var            name = param.NickName;

            if (param.Access == GH_ParamAccess.item)
            {
                IGH_Goo item = null;
                if (!DA.GetData(paramIndex, ref item))
                {
                    @this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"{name} has no input and has been assigned null data");
                }
                prop = new ObjectProperty(item);
            }
            else if (param.Access == GH_ParamAccess.list)
            {
                var items = new List <IGH_Goo>();
                DA.GetDataList(paramIndex, items);
                prop = new ObjectProperty(items);
            }
            else //tree access
            {
                DA.GetDataTree(paramIndex, out GH_Structure <IGH_Goo> itemTree);
                prop = new ObjectProperty(itemTree);
            }
            return(name, prop);
        }
Example #4
0
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(List <Polyline> polylines, List <int> types, ref object roofs)
    {
        //Medial Axis
        //Laurent Delrieu
        //30 / 12 / 2017
        //[email protected]

        //Fit the number of roof types with the number of roofs (polylines)
        if (types.Count < polylines.Count)
        {
            if (types.Count > 0)
            {
                for (int i = (types.Count - 1); i < polylines.Count; i++)
                {
                    types.Add(types[types.Count - 1]);
                }
                Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "All types are set to last type");
            }
            else
            {
                for (int i = 0; i < polylines.Count; i++)
                {
                    types.Add(0);
                }
                Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "All types are set to round");
            }
        }
        //Datatree to store roofs brep/surfaces
        DataTree <Brep> roofsDT = new   DataTree <Brep>();

        //Parallel for
        System.Threading.Tasks.Parallel.For(0, polylines.Count,
                                            index => {
            bool parallel = true;
            roofsDT.AddRange(SandDune(polylines[index], types[index], false, parallel), new GH_Path(index));
        });

        roofs = roofsDT;
    }