/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } Rectangle3d region = new Rectangle3d(); DA.GetData(1, ref region); bool original = false; DA.GetData(2, ref original); Color color = Color.Black; DA.GetData(3, ref color); Filter filter = new Af.Crop(original, color, region.ToDrawingRect(image.Bitmap.Height)); image.Filters.Add(new Af.Crop(original, color, region.ToDrawingRect(image.Bitmap.Height))); DA.SetData(0, image); DA.SetData(1, filter); }
/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } int source = 0; DA.GetData(1, ref source); int target = 0; DA.GetData(2, ref target); image.SwapChannel((Image.Channels)source, (Image.Channels)target); DA.SetData(0, new Image(image.Bitmap)); }
/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } int mode = 0; DA.GetData(1, ref mode); Filter filter = new Extract((Extract.Modes)mode); image.Filters.Add(new Extract((Extract.Modes)mode)); message = ((Extract.Modes)mode).ToString(); UpdateMessage(); DA.SetData(0, image); DA.SetData(1, filter); }
internal static IEnumerable <IGH_Goo> PromptEdge(string prompt) { IGH_Goo goo = null; try { var selectEdgeResult = theUI.SelectionManager.SelectTaggedObject(prompt, prompt, Selection.SelectionScope.WorkPart, Selection.SelectionAction.AllAndDisableSpecific, false, false, new Selection.MaskTriple[] { MaskTripleEx.Edge }, out var reference, out _); if (selectEdgeResult == Selection.Response.Ok) { var edge = reference as Edge; var extractedCurve = workPart.Features.CreateExtractGeometry(edge); var nxCurve = extractedCurve.GetEntities()[0] as NXOpen.Curve; nxCurve.RemoveParameters(); var curve = nxCurve.ToRhino(); goo = new GH_Curve(curve); } } catch (Exception) { } yield return(goo); }
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); }
/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } Point3d point = new Point3d(100, 100, 0); DA.GetData(1, ref point); Color color = Color.Black; DA.GetData(2, ref color); point.Y = -point.Y; Filter filter = new Af.Move(color, point.ToDrawingPoint()); image.Filters.Add(new Af.Move(color, point.ToDrawingPoint())); DA.SetData(0, image); DA.SetData(1, filter); }
/// <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 head = null; IGH_Goo arg1 = null; IGH_Goo arg2 = null; LinkType linkType = null; if (!DA.GetData(0, ref head)) { return; } // arg comes in as a wrapper class like GH_Integer or GH_Circle. if (!DA.GetData(1, ref arg1)) { return; } if (!DA.GetData(2, ref arg2)) { return; } // Link arg is optional. DA.GetData(3, ref linkType); // If the retrieved data is Nothing, we need to abort. if (head == null || arg1 == null || arg2 == null) { return; } IKernelLink ml = linkType != null ? linkType.Value : Utils.GetLink(); ml.PutFunction("EvaluatePacket", 1); ml.PutNext(ExpressionType.Function); ml.PutArgCount(2); Utils.SendInputParam(head, ml, GH_ParamAccess.item, true); Utils.SendInputParam(arg1, ml, GH_ParamAccess.item, false); Utils.SendInputParam(arg2, ml, GH_ParamAccess.item, false); ml.EndPacket(); try { ml.WaitForAnswer(); } catch (MathLinkException) { ml.ClearError(); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error on the link."); ml.NewPacket(); return; } // This is the (likely) temporary feature that puts the Expr result on the second output. Expr debuggingExpr = ml.PeekExpr(); DA.SetData(1, new ExprType(debuggingExpr)); if (!Utils.ReadAndStoreResult("Any", 0, ml, DA, GH_ParamAccess.item, this)) { return; } DA.SetData(2, new LinkType(ml)); }
/// <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) { // this doesn't work - check hot to cast to GUID and find dot by id // but keep the possibility that input is of type TextDot IGH_Goo dotInput = null; TextDot dot = null; GH_Guid dotGuid; if (!DA.GetData(0, ref dotInput)) { return; } //dotInput.CastTo(out dot); if (!dotInput.CastTo(out dot)) { dotGuid = dotInput as GH_Guid; Guid dg = dotGuid.Value; var dotDoc = RhinoDoc.ActiveDoc.Objects.FindId(dg); dot = dotDoc.Geometry as TextDot; } DA.SetData(0, dot.Point); DA.SetData(1, dot.Text); DA.SetData(2, dot.SecondaryText); DA.SetData(3, dot.FontHeight); DA.SetData(4, dot.FontFace); }
/// <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; } var updates = new List <(string Name, ObjectProperty Property)>(); for (int i = 1; i < Params.Input.Count; i++) { updates.Add(RetrieveProperties(DA, i, this)); } var newObj = obj.AddOrChangeProperties(updates); DA.SetData(0, new GH_ObjectivismObject(newObj)); }
private void ParseInput(IGH_DataAccess DA) { IGH_Goo DataInput = null; var check = DA.GetData(0, ref DataInput); var ghGoo = DataInput; if (ghGoo == null) { return; } var input = ghGoo.GetType().GetProperty("Value")?.GetValue(ghGoo); var inputType = "Invalid"; StreamWrapper newWrapper = null; if (input is StreamWrapper wrapper) { newWrapper = wrapper; inputType = GetStreamTypeMessage(newWrapper); } else if (input is string s) { newWrapper = new StreamWrapper(s); inputType = GetStreamTypeMessage(newWrapper); } InputType = inputType; HandleInputType(newWrapper); }
/// <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) { object obj = new object(); if (!DA.GetData(0, ref obj)) { return; } CalcCore.ICalc myCalc; IGH_Goo myGoo = obj as IGH_Goo; myGoo.CastTo <CalcCore.ICalc>(out myCalc); bool output = false; if (!DA.GetData(1, ref output)) { return; } string filePath = ""; if (!DA.GetData(2, ref filePath)) { return; } if (myCalc != null && output) { Calcs.OutputToODT.WriteToODT(new List <ICalc> { myCalc }, true, true, true, filePath); } }
/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } Color color = Color.Black; DA.GetData(1, ref color); Filter filter = new Af.Shrink(color); image.Filters.Add(new Af.Shrink(color)); DA.SetData(0, image); DA.SetData(1, filter); }
/// <summary> /// /// </summary> /// <param name="DA"></param> private void InitializeSolver(IGH_DataAccess DA, DynamicRemesher.Settings settings) { GH_HeMesh3d source = null; if (!DA.GetData(0, ref source)) { return; } IGH_Goo targetGoo = null; if (!DA.GetData(1, ref targetGoo)) { return; } var featsGoo = new List <GH_ObjectWrapper>(); DA.GetDataList(2, featsGoo); var target = CreateSurfaceFeature(targetGoo); var features = featsGoo.Select(obj => (IFeature)obj.Value).Concat(CreateBoundaryFeatures(source)); _solver = DynamicRemesher.Solver.Create(source.Value, target, features, settings); }
/// <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; Sd.Bitmap bitmap = new Sd.Bitmap(100, 100); if (DA.GetData(0, ref goo)) { if (!goo.CastTo <Sd.Bitmap>(out bitmap)) { Image image = new Image(); if (goo.CastTo <Image>(out image)) { bitmap = image.GetFilteredBitmap(); } else { bitmap = Properties.Resources.ImageViewer_Background; } } } else { bitmap = Properties.Resources.ImageViewer_Background; } img = (Sd.Bitmap)bitmap.Clone(); message = bitmap.PixelFormat.ToString(); UpdateMessage(); }
/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } int mode = 0; DA.GetData(1, ref mode); int width = 100; DA.GetData(2, ref width); int height = 100; DA.GetData(3, ref height); Filter filter = new Af.Resize(width, height, (Af.Resize.Modes)mode); image.Filters.Add(new Af.Resize(width, height, (Af.Resize.Modes)mode)); DA.SetData(0, image); DA.SetData(1, filter); }
protected override void SolveInstance(IGH_DataAccess DA) { int inputCount = 8; var inputs = new IGH_Goo[inputCount]; for (int i = 0; i < inputCount; i++) { if (!DA.GetData(i, ref inputs[i])) { return; } } var target = (inputs[0] as GH_Target).Value as JointTarget; var attributes = new ExtrusionAttributes() { NozzleDiameter = (inputs[1] as GH_Number).Value, LayerHeight = (inputs[2] as GH_Number).Value, SafeZOffset = (inputs[3] as GH_Number).Value, SafeSpeed = target.Speed, ApproachSpeed = (inputs[4] as GH_Speed).Value, ExtrusionSpeed = (inputs[5] as GH_Speed).Value, SafeZone = target.Zone, ApproachZone = (inputs[6] as GH_Zone).Value, ExtrusionZone = (inputs[7] as GH_Zone).Value, Tool = target.Tool, Frame = target.Frame, Home = target.Joints }.Initialize(); DA.SetData(0, new GH_ExtrusionAttributes(attributes)); }
/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } int alpha = 0; DA.GetData(1, ref alpha); int red = 1; DA.GetData(2, ref red); int green = 2; DA.GetData(3, ref green); int blue = 3; DA.GetData(4, ref blue); image.SwapChannels((Image.Channels)alpha, (Image.Channels)red, (Image.Channels)green, (Image.Channels)blue); DA.SetData(0, image); }
/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } bool flipX = false; DA.GetData(1, ref flipX); bool flipY = false; DA.GetData(2, ref flipY); Filter filter = new Af.Mirror(flipY, flipX); image.Filters.Add(new Af.Mirror(flipY, flipX)); DA.SetData(0, image); DA.SetData(1, filter); }
/// <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; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } double angle = 0; DA.GetData(1, ref angle); double depth = 0; DA.GetData(2, ref depth); bool toPolar = true; DA.GetData(3, ref toPolar); Filter filter = new Af.Polar(toPolar, depth, angle, false, false); image.Filters.Add(new Af.Polar(toPolar, depth, angle, false, false)); DA.SetData(0, image); DA.SetData(1, filter); }
/// <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) { // Declare variables IGH_Goo Z = null; int T = 10; int S = 5; // Access the input parameters if (!DA.GetData(0, ref Z)) { return; } Bitmap A = new Bitmap(10, 10); if (Z != null) { Z.CastTo(out A); } mFilter Filter = new mFilter(); switch (ModeIndex) { case 0: Filter = new mThresholdOtsu(); break; case 1: Filter = new mThresholdSIS(); break; case 2: if (!DA.GetData(1, ref T)) { return; } Filter = new mThresholdSimple(T); break; case 3: if (!DA.GetData(1, ref T)) { return; } if (!DA.GetData(2, ref S)) { return; } Filter = new mThresholdIterative(T, S); break; } Bitmap B = new mApply(A, Filter).ModifiedBitmap; wObject W = new wObject(Filter, "Macaw", Filter.Type); DA.SetData(0, B); DA.SetData(1, W); }
public static bool SetGoo(this GH_IWriter writer, string itemName, IGH_Goo item) { var itemWriter = writer.CreateChunk(itemName); var tree = new GH_Structure <IGH_Goo>(); tree.Append(item); return(tree.Write(itemWriter)); }
/// <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) { // Declare variables IGH_Goo X = null; int Xsize = 0; int Ysize = 0; int F = 0; int S = 0; // Access the input parameters if (!DA.GetData(0, ref X)) { return; } if (!DA.GetData(1, ref F)) { return; } if (!DA.GetData(2, ref S)) { return; } if (!DA.GetData(3, ref Xsize)) { return; } if (!DA.GetData(4, ref Ysize)) { return; } if (F != ModeIndex) { ModeIndex = F; UpdateMessage(); } if (S != TypeIndex) { TypeIndex = S; UpdateMessage(); } wObject Z = new wObject(); if (X != null) { X.CastTo(out Z); } mLayer L = new mLayer((mLayer)Z.Element); L.SetSizing(F, S, Xsize, Ysize); wObject W = new wObject(L, "Macaw", L.Type); DA.SetData(0, W); }
/// <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) { // Declare variables IGH_Goo X = null; IGH_Goo Y = null; IGH_Goo Z = null; // Access the input parameters if (!DA.GetData(0, ref X)) { return; } if (!DA.GetData(1, ref Y)) { return; } if (!DA.GetData(2, ref Z)) { return; } Bitmap A = null; Bitmap B = null; wObject W = new wObject(); mTexture T = new mTexture(); if (X != null) { X.CastTo(out A); } if (Y != null) { Y.CastTo(out B); } Bitmap C = new Bitmap(A); if (Z != null) { Z.CastTo(out W); } T = (mTexture)W.Element; if ((A.Width != B.Width) || (A.Height != B.Height)) { mMatchBitmaps BitmapPair = new mMatchBitmaps(A, B, MatchType, MatchSizing); A = new Bitmap(BitmapPair.BottomImage); B = new Bitmap(BitmapPair.TopImage); } C = new mCompositeTextureMorph(A, B, T).ModifiedBitmap; DA.SetData(0, C); }
/// <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; Bitmap bitmap = new Bitmap(100, 100); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetBitmap(ref bitmap)) { return; } Corners corners = new Corners(bitmap); double threshold = 1.0; DA.GetData(2, ref threshold); corners.Threshold = (int)(threshold * 255.0); double valueModifier = 1.0; if (DA.GetData(3, ref valueModifier)) { corners.Value = valueModifier; } int mode = 0; DA.GetData(1, ref mode); List <Point3d> points = new List <Point3d>(); switch ((CornerModes)mode) { default: points = corners.GetSusanCorners(); break; case CornerModes.Fast: points = corners.GetFastCorners(); break; case CornerModes.Harris: points = corners.GetHarrisCorners(); break; case CornerModes.Morvec: points = corners.GetMorvacCorners(); break; } DA.SetDataList(0, points); }
/** * Does the computation */ protected override void SolveRabbitInstance(IGH_DataAccess DA) { //Get the INPUT //GH_ObjectWrapper CAWrapper = null; //DA.GetData<GH_ObjectWrapper>(1, ref CAWrapper);//param index, place holder //CA CA = (CA)CAWrapper.Value; GH_ObjectWrapper CAConfigurationWrapper = null; DA.GetData <GH_ObjectWrapper>(0, ref CAConfigurationWrapper);//param index, place holder ICAConfig CAConfiguration = (ICAConfig)CAConfigurationWrapper.Value; int time = CAConfiguration.GetAssociatedTime();// CA.GetMemory().GetTime(CAConfiguration); IEnumerable <ICell> cells = null; //Filter the cells, if filter is specified IGH_Goo filterStateValue = null; DA.GetData <IGH_Goo>(1, ref filterStateValue); if (filterStateValue == null) //no filter specified { cells = CAConfiguration.GetCells(); //CA.GetGrid().GetObjects(); } else { //filter cells with the specified state CellState filterCS = new GH_CellState(filterStateValue); //CellState filterCS = new CellState(true); cells = filterCells(CAConfiguration, CAConfiguration.GetCells(), filterCS); } //OUTPUT ArrayList cellTimes = new ArrayList(); ArrayList cellIndexes = new ArrayList(); ArrayList cellStates = new ArrayList(); foreach (ICell cell in cells) { cellTimes.Add(time); //cellTimes.Add(CAConfiguration.GetCellState(cell).Equals(filterCS)); //cellTimes.Add(new GH_Boolean(true).Value.Equals(new GH_Boolean(true).Value)); //cellTimes.Add(new GH_Colour(255,0,0,0).Value.Equals(new GH_Colour(255,0,0,0).Value)); //cellIndexes.Add(cell.GetId()); cellIndexes.Add(cell.GetAttachedObject()); //the value of the state is a GH_Goo instance cellStates.Add(CAConfiguration.GetCellState(cell).GetValue());//.GetValue().GetType()); } //set the output parameters DA.SetDataList(0, cellIndexes); DA.SetDataList(1, cellStates); DA.SetDataList(2, cellTimes); }
internal static IEnumerable <IGH_Goo> PromptPoint(UIDocument doc, string prompt) { IGH_Goo goo = null; if (PickPoint(doc, prompt + " : ", out var point)) { goo = new GH_Point(point.ToRhino().Scale(Revit.ModelUnits)); } yield return(goo); }
internal static IEnumerable <IGH_Goo> PromptPoint(string prompt) { IGH_Goo goo = null; if (PickPoint(prompt + " : ", out var point)) { goo = new GH_Point(point.ToRhino()); } yield return(goo); }
internal static IEnumerable <IGH_Goo> PromptPoint(UIDocument doc, string prompt) { IGH_Goo goo = null; if (PickPoint(doc, prompt + " : ", out var point)) { goo = new GH_Point(point.ToPoint3d()); } yield return(goo); }
/// <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 Element = null; string LayerName = "Layer 01"; if (!DA.GetData(0, ref Element)) { return; } if (!DA.GetData(1, ref LayerName)) { return; } wObject W = new wObject(); if (Element != null) { Element.CastTo(out W); } wGraphic G = W.Graphics; G.Layer = LayerName; W.Graphics = G; switch (W.Type) { case "Parrot": pElement E = (pElement)W.Element; pControl C = (pControl)E.ParrotControl; C.Graphics = G; break; case "Pollen": switch (W.SubType) { } break; case "Hoopoe": wShapeCollection Shapes = (wShapeCollection)W.Element; Shapes.Group = LayerName; Shapes.Graphics.Layer = LayerName; W.Element = Shapes; break; } DA.SetData(0, W); DA.SetData(1, G); }
private object GetItemFromParameter(IGH_DataAccess DA, int index, bool addIntoGhDoc) { IGH_Goo destination = null; DA.GetData(index, ref destination); var toReturn = this.TypeCast(destination, index); DocumentSingle(ref toReturn, addIntoGhDoc); return(toReturn); }
public static bool ObjectToJSON(IGH_Goo obj, ref String str, bool IncludeType = true, bool AllowNulls = true) { if (obj == null) { if (!AllowNulls) return false; str = @"{""Type"":""null""}"; return true; } if (obj.GetType() == typeof(GH_Boolean)){ String val = @"""" + ((GH_Boolean)obj).Value.ToString() + @""""; if (IncludeType) str = @"{""Type"":"""+TypeToString(obj)+@""",""Value"":" + val + @"}"; else str = val; return true; } if (obj.GetType() == typeof(GH_Number)){ String val = ((GH_Number)obj).Value.ToString(); if (IncludeType) str = @"{""Type"":""" + TypeToString(obj) + @""",""Value"":" + val + @"}"; else str = val; return true; } if (obj.GetType() == typeof(GH_Integer)) { String val = ((GH_Integer)obj).Value.ToString(); if (IncludeType) str = @"{""Type"":""" + TypeToString(obj) + @""",""Value"":" + val + @"}"; else str = val; return true; } if (obj.GetType() == typeof(GH_String)) { //TODO: escape bad string characters according to http://stackoverflow.com/questions/3020094/how-should-i-escape-strings-in-json String val = @"""" + ((GH_String)obj).Value.ToString().Replace(@"""",@"\""") + @""""; if (IncludeType) str = @"{""Type"":""" + TypeToString(obj) + @""",""Value"":" + val + @"}"; else str = val; return true; } if (obj.GetType() == typeof(GH_Guid)) { String val = @"""" + ((GH_Guid)obj).Value.ToString() + @""""; if (IncludeType) str = @"{""Type"":""" + TypeToString(obj) + @""",""Value"":" + val + @"}"; else str = val; return true; } if (obj.GetType() == typeof(GH_Time)) { String val = @"""" + ((GH_Time)obj).Value.ToString() + @""""; if (IncludeType) str = @"{""Type"":""" + TypeToString(obj) + @""",""Value"":" + val + @"}"; else str = val; return true; } if (obj.GetType() == typeof(GH_Colour)) { if (IncludeType) str = @"{""Type"":""" + TypeToString(obj) + @""","; else str = @"{"; GH_Colour clr = (GH_Colour)obj; str += @"""A"":" + clr.Value.A.ToString() + ","; str += @"""R"":" + clr.Value.R.ToString() + ","; str += @"""G"":" + clr.Value.G.ToString() + ","; str += @"""B"":" + clr.Value.B.ToString(); str += "}"; return true; } if (obj.GetType() == typeof(GH_Interval)) { if (IncludeType) str = @"{""Type"":""" + TypeToString(obj) + @""","; else str = @"{"; GH_Interval ival = (GH_Interval)obj; str += @"""T0"":" + ival.Value.T0.ToString() + ","; str += @"""T1"":" + ival.Value.T1.ToString(); str += "}"; return true; } if (obj.GetType() == typeof(GH_Interval2D)) { if (IncludeType) str = @"{""Type"":""" + TypeToString(obj) + @""","; else str = @"{"; GH_Interval2D ival = (GH_Interval2D)obj; str += @"""U0"":" + ival.Value.U0.ToString() + ","; str += @"""U1"":" + ival.Value.U1.ToString() + ","; str += @"""V0"":" + ival.Value.V0.ToString() + ","; str += @"""V1"":" + ival.Value.V1.ToString(); str += "}"; return true; } return false; }
public static String TypeToString(IGH_Goo obj) { String[] split = obj.GetType().ToString().Split('.'); return split[split.Length - 1]; }