/// <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) { // First, we need to retrieve all data from the input parameters. // We'll start by declaring variables and assigning them starting values. //Plane plane = Plane.WorldXY; //double radius0 = 0.0; //double radius1 = 0.0; //int turns = 0; DataTree <Point3d> polylinePoints = new DataTree <Point3d>(); List <string> fields = new List <string>(); DataTree <Object> attributes = new DataTree <Object>(); // Then we need to access the input parameters individually. // When data cannot be extracted from a parameter, we should abort this method. //if (!DA.GetData(0, ref plane)) return; //if (!DA.GetData(1, ref radius0)) return; //if (!DA.GetData(2, ref radius1)) return; //if (!DA.GetData(3, ref turns)) return; if (!DA.GetData(0, ref polylinePoints)) { return; } if (!DA.GetData(1, ref fields)) { return; } if (!DA.GetData(2, ref attributes)) { return; } // We should now validate the data and warn the user if invalid data is supplied. //if (radius0 < 0.0){ // AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Inner radius must be bigger than or equal to zero"); // return;} //if (radius1 <= radius0){ // AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Outer radius must be bigger than the inner radius"); // return;} //if (turns <= 0){ // AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Spiral turn count must be bigger than or equal to one"); // return;} //Create working variables, not outputs or inputs but middle men Dictionary <int, Object> geoDict = new Dictionary <int, Object>(); // We're set to create the spiral now. To keep the size of the SolveInstance() method small, // The actual functionality will be in a different method: //Curve spiral = CreateSpiral(plane, radius0, radius1, turns); //Basic esriJSON headder info Dictionary <string, Object> geoDict = new Dictionary <string, Object>(); geoDict.Add("displayFieldName", " "); Dictionary <string, string> fieldAliasDic = new Dictionary <string, string>(); foreach (string field in Fields) { fieldAliasDic.Add(field, field); } geoDict.Add("fieldAliases", fieldAliasDic); geoDict.Add("geometryType", "esriGeometryPolyline"); Dictionary <string, int> sr = new Dictionary <string, int>() { { "wkid", 102729 }, { "latestWkid", 2272 } }; geoDict.Add("spatialReference", sr); List <Dictionary <string, string> > fieldsList = new List <Dictionary <string, string> >(); foreach (var item in Fields.Select((Value, Index) => new { Value, Index })) { Dictionary <string, string> fieldTypeDict = new Dictionary <string, string>(); fieldTypeDict.Add("name", item.Value.ToString()); var typeItem = Values.Branch(Values.Paths[0])[item.Index]; if (typeItem is int) { fieldTypeDict.Add("type", "esriFieldTypeInteger"); } else if (typeItem is long || typeItem is ulong || typeItem is float || typeItem is double || typeItem is decimal) { fieldTypeDict.Add("type", "esriFieldTypeDouble"); } else { fieldTypeDict.Add("type", "esriFieldTypeString"); } if (item.Value.ToString().Length > 7) { fieldTypeDict.Add("alias", item.Value.ToString().Substring(0, 7)); } else { fieldTypeDict.Add("alias", item.Value.ToString()); } fieldsList.Add(fieldTypeDict); } geoDict.Add("fields", fieldsList); //Produces conver dictionary to json text var json = Newtonsoft.Json.JsonConvert.SerializeObject(geoDict, Newtonsoft.Json.Formatting.Indented); Print(json); // Finally assign the spiral to the output parameter. DA.SetData(0, spiral); }