private string DoWork(GH_SpeckleBase item, IGH_DataAccess DA) { if (item?.Value != null) { try { return(Operations.Serialize(item.Value)); } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, e.Message); return(null); } } AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Item at path {{{DA.ParameterTargetPath(0)}}}[{DA.ParameterTargetIndex(0)}] is not a Base object."); return(null); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Surface destination = null; double naN = double.NaN; double num2 = double.NaN; bool flag = true; if ((((DA.GetData <Surface>(0, ref destination) && DA.GetData <double>(1, ref naN)) && DA.GetData <double>(2, ref num2)) && DA.GetData <bool>(3, ref flag)) && ((destination.IsValid && (naN > 0.0)) && (num2 > 0.0))) { if (naN > num2) { if ((naN % num2) > 0.0) { this.AddRuntimeMessage((GH_RuntimeMessageLevel)1, "One distance parameter needs to be a multiplier of the other"); return; } } else if ((num2 > naN) && ((num2 % naN) > 0.0)) { this.AddRuntimeMessage((GH_RuntimeMessageLevel)1, "One distance parameter needs to be a multiplier of the other"); return; } List <Point3d[]> rhGrid = Utility.DivideSurfaceByChordLength(destination, naN, num2, flag, 0.0, 0.0); GH_Structure <GH_Point> grid = new GH_Structure <GH_Point>(); GH_Path path = new GH_Path(DA.ParameterTargetPath(0)); path = path.AppendElement(DA.ParameterTargetIndex(0)); if (!PtListArrayToGhTreePoint(rhGrid, ref grid, path)) { this.AddRuntimeMessage((GH_RuntimeMessageLevel)1, "Failed to convert Rhino list array to GH tree."); } else { DA.SetDataTree(0, grid); } } }
private Base DoWork(string item, IGH_DataAccess DA) { if (string.IsNullOrEmpty(item)) { return(null); } try { return(Operations.Deserialize(item)); } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Cannot deserialize object at path {{{DA.ParameterTargetPath(0)}}}[{DA.ParameterTargetIndex(0)}]: {e.InnerException?.Message ?? e.Message}"); return(null); } }
protected override void SolveInstance(IGH_DataAccess DA) { if (InPreSolve) { GH_SpeckleBase speckleBase = null; DA.GetData(0, ref speckleBase); var @base = speckleBase.Value.ShallowCopy(); var inputData = new Dictionary <string, object>(); if (Params.Input.Count == 1) { inputData = null; return; } var hasErrors = false; var allOptional = Params.Input.FindAll(p => p.Optional).Count == Params.Input.Count; if (Params.Input.Count > 1 && allOptional) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "You cannot set all parameters as optional"); inputData = null; return; } if (DA.Iteration == 0) { Tracker.TrackPageview("objects", "extend", "variableinput"); } inputData = new Dictionary <string, object>(); for (int i = 1; i < Params.Input.Count; i++) { var ighParam = Params.Input[i]; var param = ighParam as GenericAccessParam; var detachable = param.Detachable; var key = detachable ? "@" + param.NickName : param.NickName; var willOverwrite = @base.GetMembers().ContainsKey(key); var targetIndex = DA.ParameterTargetIndex(0); var path = DA.ParameterTargetPath(0); if (willOverwrite) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, $"Key {key} already exists in object at {path}[{targetIndex}], its value will be overwritten"); } switch (param.Access) { case GH_ParamAccess.item: object value = null; DA.GetData(i, ref value); if (!param.Optional && value == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Non-optional parameter {param.NickName} cannot be null"); hasErrors = true; } inputData[key] = value; break; case GH_ParamAccess.list: var values = new List <object>(); DA.GetDataList(i, values); if (!param.Optional) { if (values.Count == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Non-optional parameter {param.NickName} cannot be null or empty."); hasErrors = true; } } inputData[key] = values; break; case GH_ParamAccess.tree: break; default: throw new ArgumentOutOfRangeException(); } } if (hasErrors) { inputData = null; } var task = Task.Run(() => DoWork(@base, inputData)); TaskList.Add(task); return; } // Report all conversion errors as warnings if (Converter != null) { foreach (var error in Converter.Report.ConversionErrors) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, error.Message + ": " + error.InnerException?.Message); } Converter.Report.ConversionErrors.Clear(); } if (!GetSolveResults(DA, out Base result)) { // Normal mode not supported return; } if (result != null) { DA.SetData(0, result); } }
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()); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { IGH_Goo goo = null; if (!DA.GetData(0, ref goo)) { return; } ObjectivismObject obj; if (goo is GH_ObjectivismObject ghObj) { obj = ghObj.Value; } else { return; } PropertyNames.UnionWith(obj.AllProperties); foreach ((int i, var param) in Params.Output.Enumerate()) { string name = param.NickName; var prop = obj.GetProperty(name); PropertyAccess access; if (prop != null) { access = prop.Access; accessChecker.AccessCheck(prop, name); } else { access = accessChecker.BestGuessAccess(name); } if (access == PropertyAccess.Item) { var item = prop != null ? prop.Data.get_FirstItem(false) : null; var path = DA.ParameterTargetPath(i); if (GraftItems) { int[] index = { DA.ParameterTargetIndex(0) }; var newPath = new GH_Path(path.Indices.Concat(index).ToArray()); var tree = new GH_Structure <IGH_Goo>(); tree.Append(item, newPath); DA.SetDataTree(i, tree); } else { var tree = new GH_Structure <IGH_Goo>(); tree.Append(item, path); DA.SetDataTree(i, tree); } } if (access == PropertyAccess.List) { var list = prop != null ? prop.Data.Branches[0] : new List <IGH_Goo>(); var path = DA.ParameterTargetPath(i); int[] index = { DA.ParameterTargetIndex(0) }; var newPath = new GH_Path(path.Indices.Concat(index).ToArray()); var tree = new GH_Structure <IGH_Goo>(); tree.AppendRange(list, newPath); DA.SetDataTree(i, tree); } if (access == PropertyAccess.Tree) { var tree = prop != null ? prop.Data : Util.EmptyTree; var basePath = DA.ParameterTargetPath(i); var outTree = new GH_Structure <IGH_Goo>(); for (int j = 0; j < tree.PathCount; j++) { var branch = tree.Branches[j]; var path = tree.Paths[j]; int[] index = { DA.ParameterTargetIndex(0) }; var newPathIndices = basePath.Indices .Concat(index) .Concat(path.Indices) .ToArray(); var newPath = new GH_Path(newPathIndices); outTree.AppendRange(branch, newPath); } DA.SetDataTree(i, outTree); } } }