/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess"> /// The DA object is used to retrieve from inputs and store in outputs. /// </param> protected override void SolveInstance(IGH_DataAccess dataAccess) { GH_ObjectWrapper objectWrapper = null; if (!dataAccess.GetData(0, ref objectWrapper) || objectWrapper == null) { dataAccess.SetData(0, null); AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Null object provided"); return; } object @object = objectWrapper.Value; if (@object is IGH_Goo) { try { @object = (@object as dynamic).Value; } catch (Exception exception) { @object = null; } } if (@object == null) { dataAccess.SetData(0, null); AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Null object provided"); return; } dataAccess.SetDataList(0, Core.Query.Names(@object)); }
/// <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) { #region variables GH_ObjectWrapper wrapNode = new GH_ObjectWrapper(); List <Node> nodes = new List <Node>(); List <int> nodeIds = new List <int>(); List <Node> outNodes = new List <Node>(); #endregion #region input if (!DA.GetData(0, ref wrapNode)) { return; } wrapNode.CastTo <List <Node> >(out nodes); if (!DA.GetDataList(1, nodeIds)) { return; } #endregion #region solve // foreach (Node n in nodes) for (int i = 0; i < nodeIds.Count; i++) { outNodes.Add(Node.FindNodeById(nodes, nodeIds[i])); } #endregion #region output DA.SetData(0, outNodes); #endregion }
public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GH_String) { string tempfile = ""; if (GH_Convert.ToString(gh_typ, out tempfile, GH_Conversion.Both)) { if (!tempfile.EndsWith(".gwb")) { tempfile = tempfile + ".gwb"; } GsaModel.FileName = tempfile; } } else if (gh_typ.Value is GsaAPI.Model) { GsaAPI.Model model = new Model(); gh_typ.CastTo(ref model); GsaModel.Model = model; } } }
protected override void SolveInstance(IGH_DataAccess da) { // get input from gh component inputs List <string> ids = new List <string>(); List <string> vals = new List <string>(); // don't compute if values and ids are not provided if (!da.GetDataList(0, ids)) { return; } if (!da.GetDataList(1, vals)) { return; } //List<DomSetValueModelGoo> setValueModels = // ids.Select((t, i) => new DomSetValueModelGoo() {id = t, value = vals[i]}).ToList(); // create a dictionary of ids and values to set // TODO: there's definitely a more elegant way than this stupid loop... Dictionary <string, string> setValueModels = new Dictionary <string, string>(); for (int i = 0; i < ids.Count; i++) { setValueModels.Add(ids[i], vals[i]); } IGH_Goo dictionaryGoo = new GH_ObjectWrapper(setValueModels); da.SetData(0, dictionaryGoo); }
/// <inheritdoc /> protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper goo = null; if (!DA.GetData(0, ref goo)) { return; } IFeature feat = null; switch (goo.Value) { case Mesh m: feat = new MeshFeature(m); break; case Curve c: feat = new CurveFeature(c); break; case Point3d p: feat = new PointFeature(p); break; default: throw new ArgumentException(); } DA.SetData(0, new GH_ObjectWrapper(feat)); }
/// <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 a variable for the input String Topologic.Topology topology = null; // Use the DA object to retrieve the data inside the first input parameter. // If the retieval fails (for example if there is no data) we need to abort. if (!DA.GetData(0, ref topology)) { return; } // If the retrieved data is Nothing, we need to abort. // We're also going to abort on a zero-length String. if (topology == null) { return; } //if (data.Length == 0) { return; } // Convert the String to a character array. //char[] chars = data.ToCharArray(); Dictionary <String, Object> dictionary = topology.Dictionary; IGH_Goo dictionaryGoo = new GH_ObjectWrapper(dictionary); DA.SetData(0, dictionaryGoo); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess"> /// The DA object is used to retrieve from inputs and store in outputs. /// </param> protected override void SolveInstance(IGH_DataAccess dataAccess) { List <GH_ObjectWrapper> objectWrapperList = new List <GH_ObjectWrapper>(); if (!dataAccess.GetDataList(0, objectWrapperList) || objectWrapperList == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } GH_ObjectWrapper objectWrapper = null; if (!dataAccess.GetData(1, ref objectWrapper) || objectWrapper.Value == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } GH_Number gHNumber = objectWrapper.Value as GH_Number; if (gHNumber == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } CellComplex cellComplex = CellComplex.ByFaces(objectWrapperList.ConvertAll(x => x.Value as global::Topologic.Face), gHNumber.Value); dataAccess.SetData(0, cellComplex); }
/// <inheritdoc /> public override bool CastTo <T>(ref T target) { if (typeof(T).IsAssignableFrom(typeof(HeMesh3d))) { object obj = Value; target = (T)obj; return(true); } if (typeof(T).IsAssignableFrom(typeof(Mesh))) { object obj = new GH_Mesh(base.Value.ToMesh()); target = (T)obj; return(true); } if (typeof(T).IsAssignableFrom(typeof(GH_Mesh))) { object obj = new GH_Mesh(Value.ToMesh()); target = (T)obj; return(true); } if (typeof(T).IsAssignableFrom(typeof(GH_ObjectWrapper))) { object obj = new GH_ObjectWrapper(Value); target = (T)obj; return(true); } return(false); }
/** * Goo.CastTo<> supports cross-type castings i.e. Integers could be cast to Strings. We need strong typing. * GH_integer -> integer * GH_boolean -> boolean * * returns the System primitive wrapped by the GH_Goo object * returns a Boolean out of GH_Boolean * returns an Integer out of GH_Integer * */ public static Object ConvertToSystemType(GH_Goo <Object> goo) { if (goo.GetType() == GH_TypeLib.t_gh_bool)//GH_BooleanPrototype.GetType())//check if it is a boolean { Boolean result = false; goo.CastTo <Boolean>(ref result); return(result); } else if (goo.GetType() == GH_TypeLib.t_gh_int) { int result = -1; goo.CastTo <int>(ref result); return(result); } else if (goo.GetType() == GH_TypeLib.t_gh_string) { String result = null; goo.CastTo <String>(ref result); return(result); } else if (goo.GetType() == GH_TypeLib.t_gh_objwrapper) { GH_ObjectWrapper result = null; goo.CastTo <GH_ObjectWrapper>(ref result); return(result.Value); } throw new NotSupportedException("Could not get the System object for Goo of type" + goo.GetType()); }
protected override void SolveInstance(IGH_DataAccess da) { // get input from gh component inputs GH_ObjectWrapper settersGoo = null; GH_ObjectWrapper webWindowGoo = null; Dictionary <string, string> settersDictionary = new Dictionary <string, string>(); // get setters if (!da.GetData(0, ref webWindowGoo)) { return; } if (da.GetData(1, ref settersGoo)) { settersDictionary = settersGoo.Value as Dictionary <string, string>; } else { return; } WebWindow webWindow = (WebWindow)webWindowGoo.Value; webWindow.HandleSetters(settersDictionary); }
/// <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) { #region variables string materialName = "N/A"; int materailId = 0; Material_properties properties; #endregion GH_ObjectWrapper wrapprop = new GH_ObjectWrapper(); #region input DA.GetData(0, ref materialName); if (!DA.GetData(1, ref materailId)) { return; } if (!DA.GetData(2, ref wrapprop)) { return; } wrapprop.CastTo <Material_properties>(out properties); #endregion #region solve Material outMaterial = new Material(materialName, materailId, properties); #endregion #region output DA.SetData(0, outMaterial); #endregion }
protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper input = null; if (!DA.GetData("SpeckleObject", ref input)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Invalid object."); return; } if (input.Value == null) { return; } object inputObject = input.Value; if (inputObject.GetType() != ObjectType) { ObjectType = inputObject.GetType(); UpdateInputs(); } var modifiedObject = CreateCopy(inputObject); DA.SetData("Result", UpdateObjectProperties(modifiedObject)); }
private Dictionary <string, object> CreateOutputDictionary(Base @base) { // Create empty data tree placeholders for output. var outputDict = new Dictionary <string, object>(); // Assign all values to it's corresponding dictionary entry and branch path. var obj = @base; if (obj == null) { return(new Dictionary <string, object>()); } foreach (var prop in obj.GetMembers()) { // Convert and add to corresponding output structure var value = prop.Value; //if (!outputDict.ContainsKey(prop.Key)) continue; switch (value) { case null: outputDict[prop.Key] = null; break; case System.Collections.IList list: var result = new List <IGH_Goo>(); foreach (var x in list) { var wrapper = Utilities.TryConvertItemToNative(x, Converter); result.Add(wrapper); } outputDict[prop.Key] = result; break; // TODO: Not clear how we handle "tree" inner props. They can only be set by sender components, // so perhaps this is not an issue. Below a simple stopgap so we can actually see what data is // inside a sender-created object. case Dictionary <string, List <Base> > dict: foreach (var kvp in dict) { IGH_Goo wrapper = new GH_ObjectWrapper(); foreach (var b in kvp.Value) { wrapper = Utilities.TryConvertItemToNative(b, Converter); } outputDict[prop.Key] = wrapper; } break; default: outputDict[prop.Key] = Utilities.TryConvertItemToNative(obj[prop.Key], Converter); break; } } return(outputDict); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess"> /// The DA object is used to retrieve from inputs and store in outputs. /// </param> protected override void SolveInstance(IGH_DataAccess dataAccess) { int index = -1; index = Params.IndexOfInputParam("type_"); if (index == -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } GH_ObjectWrapper objectWrapper = null; index = Params.IndexOfInputParam("_revitLinkInstance_"); if (index != -1) { dataAccess.GetData(index, ref objectWrapper); } Document document = null; if (objectWrapper != null && objectWrapper.TryGetElement(out RevitLinkInstance revitLinkInstance) && revitLinkInstance != null) { document = revitLinkInstance.GetLinkDocument(); } if (document == null) { document = RhinoInside.Revit.Revit.ActiveDBDocument; } objectWrapper = null; index = Params.IndexOfInputParam("type_"); if (!dataAccess.GetData(index, ref objectWrapper) || objectWrapper == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } if (!objectWrapper.TryGetElement(out ElementType elementType, document) || elementType == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } int count = elementType.InstancesCount(); index = Params.IndexOfOutputParam("isPlaced"); if (index != -1) { dataAccess.SetData(index, count > 0); } index = Params.IndexOfOutputParam("count"); if (index != -1) { dataAccess.SetData(index, count); } }
/// <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 a variable for the input String GH_ObjectWrapper dictionaryGoo = null; String key = null; Object value = null; // Use the DA object to retrieve the data inside the first input parameter. // If the retieval fails (for example if there is no data) we need to abort. if (!DA.GetData(0, ref dictionaryGoo)) { return; } if (!DA.GetData(1, ref key)) { return; } if (!DA.GetData(2, ref value)) { return; } Dictionary <String, Object> dictionary = dictionaryGoo.Value as Dictionary <String, Object>; if (dictionary != null) { dictionary = GhToNetConverter.ConvertDictionary(dictionary); } else { Dictionary <Object, Object> ooDictionary = dictionaryGoo.Value as Dictionary <Object, Object>; dictionary = GhToNetConverter.ConvertDictionary(ooDictionary); } // If the retrieved data is Nothing, we need to abort. // We're also going to abort on a zero-length String. if (key == null) { return; } if (value == null) { return; } //if (data.Length == 0) { return; } // Convert the String to a character array. //char[] chars = data.ToCharArray(); Dictionary <String, Object> newDictionary = Topologic.Dictionary.SetValueAtKey(dictionary, key, value); IGH_Goo newDictionaryGoo = new GH_ObjectWrapper(newDictionary); DA.SetData(0, newDictionaryGoo); }
/** * 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); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Mesh ghmesh = new GH_Mesh(); if (DA.GetData(0, ref ghmesh)) { if (ghmesh == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh input is null"); } Mesh mesh = new Mesh(); if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both)) { GsaElement2d elem = new GsaElement2d(mesh); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { for (int i = 0; i < elem.Elements.Count; i++) { elem.Elements[i].Property = idd; } prop2d = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } else { prop2d = null; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem)); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection sect = new GsaSection(); GsaSection gsaSection = new GsaSection(); if (DA.GetData(0, ref sect)) { gsaSection = sect.Clone(); } if (gsaSection != null) { // #### input #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { gsaSection.ID = id; } } // 2 profile string profile = ""; if (DA.GetData(2, ref profile)) { gsaSection.Section.Profile = profile; } // 3 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); gsaSection.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { gsaSection.Section.MaterialAnalysisProperty = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } }
/// <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) { List <Dictionary <string, object> > pf_in = new List <Dictionary <string, object> >(); string key_in = ""; List <object> v_out = new List <object>(); GH_ObjectWrapper key_str = new GH_ObjectWrapper(); if (!DA.GetDataList(0, pf_in)) { return; } if (!DA.GetData(1, ref key_in)) { return; } //for (int i = 0; i < pf_in.Count; i++) //{ // var d = pf_in[i]; // foreach (object key in d.Keys) // { // var a = key; // var h1 = a.GetHashCode(); // var h2 = key_in.GetHashCode(); // string s1 = a.ToString(); // string s2 = key_in.ToString(); // bool test =key.Equals(key_in); // bool test2 = a.Equals(key); // bool test3 = s1.Equals(s2); // bool test4 = Object.Equals(key, key_in); // } //v_out.Add(pf_in[i][k[0]]); for (int i = 0; i < pf_in.Count; i++) { if (pf_in[i].ContainsKey(key_in)) { v_out.Add(pf_in[i][key_in]); } } DA.SetDataList(0, v_out); }
public static bool TryGetElement <T>(this GH_ObjectWrapper objectWrapper, out T element, Document document = null) where T : Element { element = null; if (objectWrapper == null) { return(false); } dynamic obj = objectWrapper.Value; if (obj is RhinoInside.Revit.GH.Types.ProjectDocument) { return(false); } if (obj is SAMObject) { if (document == null) { document = RhinoInside.Revit.Revit.ActiveDBDocument; } SAMObject sAMObject = obj as SAMObject; string uniqueId = Core.Revit.Query.UniqueId(sAMObject); if (!string.IsNullOrWhiteSpace(uniqueId)) { element = document.GetElement(uniqueId) as T; } if (element == null) { ElementId elementId = Core.Revit.Query.ElementId(sAMObject); if (elementId != null && elementId != ElementId.InvalidElementId) { element = document.GetElement(elementId) as T; } } } else if (obj is int) { ElementId elementId = new ElementId((int)obj); element = (obj.Document as Document).GetElement(elementId) as T; } else { ElementId elementId = obj.Id as ElementId; element = (obj.Document as Document).GetElement(elementId) as T; } return(element != null); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection gsaSection = new GsaSection(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref gsaSection); } else { string profile = ""; gh_typ.CastTo(ref profile); gsaSection = new GsaSection(profile); } } if (gsaSection != null) { double conversionfactor = 1; if (Util.Unit.LengthSection != "m") { switch (Util.Unit.LengthSection) { case "mm": conversionfactor = 1000; break; case "cm": conversionfactor = 100; break; case "in": conversionfactor = 1000 / 25.4; break; case "ft": conversionfactor = 1000 / (12 * 25.4); break; } } DA.SetData(0, gsaSection.Section.Area * Math.Pow(conversionfactor, 2)); DA.SetData(1, gsaSection.Section.Iyy * Math.Pow(conversionfactor, 4)); DA.SetData(2, gsaSection.Section.Izz * Math.Pow(conversionfactor, 4)); DA.SetData(3, gsaSection.Section.Iyz * Math.Pow(conversionfactor, 4)); DA.SetData(4, gsaSection.Section.J * Math.Pow(conversionfactor, 4)); DA.SetData(5, gsaSection.Section.Ky); DA.SetData(6, gsaSection.Section.Kz); DA.SetData(7, gsaSection.Section.SurfaceAreaPerLength * Math.Pow(conversionfactor, 2)); DA.SetData(8, gsaSection.Section.VolumePerLength * Math.Pow(conversionfactor, 3)); } }
/// <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 a variable for the input String Topologic.Topology topology = null; GH_ObjectWrapper dictionaryGoo = null; // Use the DA object to retrieve the data inside the first input parameter. // If the retieval fails (for example if there is no data) we need to abort. if (!DA.GetData(0, ref topology)) { return; } if (!DA.GetData(1, ref dictionaryGoo)) { return; } Dictionary <String, Object> dictionary = dictionaryGoo.Value as Dictionary <String, Object>; if (dictionary != null) { dictionary = GhToNetConverter.ConvertDictionary(dictionary); } else { Dictionary <Object, Object> ooDictionary = dictionaryGoo.Value as Dictionary <Object, Object>; dictionary = GhToNetConverter.ConvertDictionary(ooDictionary); } // If the retrieved data is Nothing, we need to abort. // We're also going to abort on a zero-length String. if (topology == null) { return; } if (dictionary == null) { return; } //if (data.Length == 0) { return; } // Convert the String to a character array. //char[] chars = data.ToCharArray(); Topologic.Topology topologyWithDictionary = topology.SetDictionary(dictionary); // Use the DA object to assign a new String to the first output parameter. DA.SetData(0, topologyWithDictionary); }
/// <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 a variable for the input String GH_ObjectWrapper dictionaryGoo = null; String key = null; // Use the DA object to retrieve the data inside the first input parameter. // If the retieval fails (for example if there is no data) we need to abort. if (!DA.GetData(0, ref dictionaryGoo)) { return; } if (!DA.GetData(1, ref key)) { return; } Dictionary <String, Object> dictionary = dictionaryGoo.Value as Dictionary <String, Object>; if (dictionary == null) { Dictionary <Object, Object> ooDictionary = dictionaryGoo.Value as Dictionary <Object, Object>; dictionary = new Dictionary <String, Object>(); foreach (var ooKeyValuePair in ooDictionary) { String oKey = ooKeyValuePair.Key as String; if (oKey == null) { throw new Exception("The dictionary contains a non-String key."); } dictionary.Add(oKey, ooKeyValuePair.Value); } } // If the retrieved data is Nothing, we need to abort. // We're also going to abort on a zero-length String. if (key == null) { return; } //if (data.Length == 0) { return; } // Convert the String to a character array. //char[] chars = data.ToCharArray(); Object value = Topologic.Dictionary.ValueAtKey(dictionary, key); DA.SetData(0, value); }
/// <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) { DA.GetDataTree(0, out GH_Structure <IGH_Goo> objtree); if (objtree.IsEmpty) { listenees.Clear(); btnpress.Clear(); listening = false; AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, " No Synapse connected"); return; } GH_Structure <GH_ObjectWrapper> outputs = new GH_Structure <GH_ObjectWrapper>(); for (int bi = 0; bi < objtree.Branches.Count; bi++) { List <IGH_Goo> objs = objtree.Branches[bi]; GH_Path pth = objtree.Paths[bi]; for (int ii = 0; ii < objs.Count; ii++) { GH_ObjectWrapper obj = objs[ii] as GH_ObjectWrapper; if (obj.Value is Control ctrl) { if (ctrl.ID == Guid.Empty.ToString() || ctrl.ID == string.Empty) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format(" a {0} isn't initialized properly with a valid ID\n this is a code error; contact dev", ctrl.GetType())); listening = true; } else if (!listenees.Contains(ctrl.ID)) { Relisten(ctrl); listening = true; } else if (!listening) { listening = true; } else { outputs.Append(GetCtrlValue(ctrl), pth); } } else { listening = false; // not an Eto control } } } DA.SetDataTree(0, outputs); }
/// <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) { // Fields GH_ObjectWrapper abstractSocket = new GH_ObjectWrapper(); bool run = false; bool getSocket = DA.GetData(0, ref abstractSocket); //Check input if (_clientSocket == null) { if (!getSocket) { return; } abstractSocket.CastTo(ref _clientSocket); } else if (_clientSocket != null && !getSocket) { try { _clientSocket = null; return; } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Waiting For Connection..."); return; } } if (!DA.GetData(1, ref run)) { return; } //If trigger is pressed, read data and output. if (run) { string response = Util.ReadVariable(ref _clientSocket, "$BASE", this); string response2 = Util.ReadVariable(ref _clientSocket, "$TOOL", this); frameBase.DeserializeFrame(response); frameTool.DeserializeFrame(response2); } DA.SetDataList(0, frameBase.GetValuesList()); DA.SetData(1, new GH_Plane(frameBase.GetPlane())); DA.SetDataList(2, frameTool.GetValuesList()); DA.SetData(3, new GH_Plane(frameTool.GetPlane())); }
/// <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) { GH_ObjectWrapper wrapper = new GH_ObjectWrapper(); DA.GetData(0, ref wrapper); List <string> roomNames = new List <string>(); foreach (RoomInstance room in (wrapper.Value as HouseInstance).RoomInstances) { roomNames.Add(room.RoomName); } DA.SetDataList(0, roomNames); }
protected override void SolveInstance(IGH_DataAccess DA) { Model model = new Model(); GsaModel gsaModel = new GsaModel(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ == null) { return; } if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref gsaModel); gsaSaveModel = gsaModel.Model; Message = ""; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model"); return; } if (!usersetFileName) { if (gsaModel.FileName != "") { fileName = gsaModel.FileName; } } string tempfile = ""; if (DA.GetData(2, ref tempfile)) { fileName = tempfile; } bool save = false; if (DA.GetData(1, ref save)) { if (save) { Message = gsaSaveModel.SaveAs(fileName).ToString(); } } DA.SetData(0, new GsaModelGoo(gsaModel)); } }
public static IGH_Goo TryConvertItemToNative(object value, ISpeckleConverter converter) { if (value == null) { return(null); } if (value is IGH_Goo) { value = value.GetType().GetProperty("Value")?.GetValue(value); } if (value is Base @base && converter.CanConvertToNative(@base)) { var converted = converter.ConvertToNative(@base); var geomgoo = GH_Convert.ToGoo(converted); if (geomgoo != null) { return(geomgoo); } var goo = new GH_ObjectWrapper { Value = converted }; return(goo); } if (value is Base @base2) { var goo = new GH_SpeckleBase { Value = @base2 }; return(goo); } if (value.GetType().IsSimpleType()) { return(GH_Convert.ToGoo(value)); } if (value is Enum) { var i = (Enum)value; return(new GH_ObjectWrapper { Value = i }); } return(null); }
/// <inheritdoc /> protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper fieldGoo = null; if (!DA.GetData(0, ref fieldGoo)) { return; } var points = new List <Point3d>(); if (!DA.GetDataList(1, points)) { return; } double stepSize = 0.0; DA.GetData(2, ref stepSize); int stepCount = 0; DA.GetData(3, ref stepCount); PolylineCurve[] paths = null; switch (fieldGoo.Value) { case IField3d <Vec3d> f: { paths = SolveInstanceImpl(f, points, stepSize, stepCount); break; } case IField2d <Vec2d> f: { paths = SolveInstanceImpl(f, points, stepSize, stepCount); break; } default: { throw new ArgumentException("The given vector field is not recognized."); } } DA.SetDataList(0, paths); }
/// <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 objectRef = null; DA.GetData(0, ref objectRef); if (objectRef == null) { return; } object valueExtract = objectRef.GetType().GetProperty("Value").GetValue(objectRef, null); GeometryBase recipient = getGeometryBase(valueExtract); if (recipient == null) { DA.SetData(0, null); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input object not supported."); return; } object dictObject = null; DA.GetData(1, ref dictObject); GH_ObjectWrapper temp = dictObject as GH_ObjectWrapper; if (temp == null) { DA.SetData(0, recipient); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Dictionary not provided. Object not modified."); return; } ArchivableDictionary dict = ((GH_ObjectWrapper)dictObject).Value as ArchivableDictionary; if (dict == null) { DA.SetData(0, recipient); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Dictionary not valid. Object not modified."); return; } recipient.UserDictionary.ReplaceContentsWith(dict); DA.SetData(0, new GH_ObjectWrapper(recipient)); }
/// <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) { bool test_bool = false; List<GH_ObjectWrapper> vals = new List<GH_ObjectWrapper>(); List<GH_ObjectWrapper> output = new List<GH_ObjectWrapper>(); GH_ObjectWrapper f = new GH_ObjectWrapper(); StringList m_py_output = new StringList(); // python output stream is piped to m_py_output Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String> consoleOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String>(); GH_ObjectWrapper key_str = new GH_ObjectWrapper(); //if (!DA.GetData(0, ref key_str)) return; if (!DA.GetDataList(0, vals)) return; if (!DA.GetData(1, ref f)) return; var ret = key_str; Type t =ret.GetType(); ScriptEngine pyEngine = Python.CreateEngine(); //var outputStream = m_py_output.Write; var outputStream = new System.IO.MemoryStream(); var outputStreamWriter = new System.IO.StreamReader(outputStream); //pyEngine.Runtime.IO.SetOutput(outputStream, outputStreamWriter); //pyEngine.Runtime.IO.SetOutput(m_py_output.Write); //pyEngine. = m_py_output.Write; PythonScript _py = PythonScript.Create(); //_py.Output = m_py_output.Write; Rhino.RhinoApp.WriteLine("Testing, testong"); //var textWriter = new System.IO.TextWriter; //pyEngine.Runtime.IO.RedirectToConsole(); //Console.SetOut(TextWriter.Synchronized(textWriter)); //System.IO.Stream out_string = pyEngine.Runtime.IO.OutputStream; //pyEngine.Runtime.IO.RedirectToConsole(); //pyEngine.Runtime.IO.SetOutput //System.IO.TextWriter test = Console.Out; //Console.SetOut(test); //pyEngine. = this.m_py_output.Write; //_py = PythonScript.Create(); //pyEngine.Operations.Output = this.m_py_output.Write; for (int i = 0; i < vals.Count; i++) { //ret = vals[i]; Type the_type = vals[i].Value.GetType(); dynamic result = pyEngine.Operations.Invoke(f.Value, vals[i].Value); object return_object = (object)result; GH_ObjectWrapper temp = new GH_ObjectWrapper(return_object); var temp2 = temp.Value; output.Add(new GH_ObjectWrapper(return_object)); } //string out_str = return_object.GetType().ToString(); SpatialGraph gph = new SpatialGraph(); DA.SetData(0, test_bool); DA.SetDataList(1, output); //DA.SetData(2, return_object); //DA.SetData(3, out_str); }
protected override void SolveInstance(IGH_DataAccess DA) { ITargetLength TargetLength = null; bool reset = false; int Flip = 0; List<Curve> FC = new List<Curve>(); List<Point3d> FV = new List<Point3d>(); double FixT = 0.01; double PullStrength = 0.8; double SmoothStrength = 0.8; double LengthTol = 0.15; bool Minim = false; int Iters = 1; GH_ObjectWrapper Surf = new GH_ObjectWrapper(); DA.GetData<GH_ObjectWrapper>(0, ref Surf); GH_ObjectWrapper Obj = null; DA.GetData<GH_ObjectWrapper>(1, ref Obj); TargetLength = Obj.Value as ITargetLength; DA.GetDataList<Curve>(2, FC); DA.GetDataList<Point3d>(3, FV); DA.GetData<int>(4, ref Flip); DA.GetData<double>(5, ref PullStrength); DA.GetData<int>(6, ref Iters); DA.GetData<bool>(7, ref reset); if (PullStrength == 0) { Minim = true; } if (Surf.Value is GH_Mesh) { DA.GetData<Mesh>(0, ref M); M.Faces.ConvertQuadsToTriangles(); } else { double L = 1.0; MeshingParameters MeshParams = new MeshingParameters(); MeshParams.MaximumEdgeLength = 3 * L; MeshParams.MinimumEdgeLength = L; MeshParams.JaggedSeams = false; MeshParams.SimplePlanes = false; Brep SB = null; DA.GetData<Brep>(0, ref SB); Mesh[] BrepMeshes = Mesh.CreateFromBrep(SB, MeshParams); M = new Mesh(); foreach (var mesh in BrepMeshes) M.Append(mesh); } if (reset || initialized == false) { #region reset M.Faces.ConvertQuadsToTriangles(); P = M.ToPlanktonMesh(); initialized = true; AnchorV.Clear(); FeatureV.Clear(); FeatureE.Clear(); //Mark any vertices or edges lying on features for (int i = 0; i < P.Vertices.Count; i++) { Point3d Pt = P.Vertices[i].ToPoint3d(); AnchorV.Add(-1); for (int j = 0; j < FV.Count; j++) { if (Pt.DistanceTo(FV[j]) < FixT) { AnchorV[AnchorV.Count - 1] = j; } } FeatureV.Add(-1); for (int j = 0; j < FC.Count; j++) { double param = new double(); FC[j].ClosestPoint(Pt, out param); if (Pt.DistanceTo(FC[j].PointAt(param)) < FixT) { FeatureV[FeatureV.Count - 1] = j; } } } int EdgeCount = P.Halfedges.Count / 2; for (int i = 0; i < EdgeCount; i++) { FeatureE.Add(-1); int vStart = P.Halfedges[2 * i].StartVertex; int vEnd = P.Halfedges[2 * i + 1].StartVertex; Point3d PStart = P.Vertices[vStart].ToPoint3d(); Point3d PEnd = P.Vertices[vEnd].ToPoint3d(); for (int j = 0; j < FC.Count; j++) { double paramS = new double(); double paramE = new double(); Curve thisFC = FC[j]; thisFC.ClosestPoint(PStart, out paramS); thisFC.ClosestPoint(PEnd, out paramE); if ((PStart.DistanceTo(thisFC.PointAt(paramS)) < FixT) && (PEnd.DistanceTo(thisFC.PointAt(paramE)) < FixT)) { FeatureE[FeatureE.Count - 1] = j; } } } #endregion } else { for (int iter = 0; iter < Iters; iter++) { int EdgeCount = P.Halfedges.Count / 2; double[] EdgeLength = P.Halfedges.GetLengths(); List<bool> Visited = new List<bool>(); Vector3d[] Normals = new Vector3d[P.Vertices.Count]; for (int i = 0; i < P.Vertices.Count; i++) { Visited.Add(false); Normals[i] = Normal(P, i); } double t = LengthTol; //a tolerance for when to split/collapse edges double smooth = SmoothStrength; //smoothing strength double pull = PullStrength; //pull to target mesh strength // Split the edges that are too long for (int i = 0; i < EdgeCount; i++) { if (P.Halfedges[2 * i].IsUnused == false) { int vStart = P.Halfedges[2 * i].StartVertex; int vEnd = P.Halfedges[2 * i + 1].StartVertex; if ((Visited[vStart] == false) && (Visited[vEnd] == false)) { double L2 = TargetLength.Calculate(P, 2 * i); if (EdgeLength[2 * i] > (1 + t) * (4f / 3f) * L2) { int SplitHEdge = P.Halfedges.TriangleSplitEdge(2 * i); if (SplitHEdge != -1) { int SplitCenter = P.Halfedges[SplitHEdge].StartVertex; P.Vertices.SetVertex(SplitCenter, MidPt(P, i)); //update the feature information FeatureE.Add(FeatureE[i]); FeatureV.Add(FeatureE[i]); AnchorV.Add(-1); //2 additional new edges have also been created (or 1 if split was on a boundary) //mark these as non-features int CEdgeCount = P.Halfedges.Count / 2; while (FeatureE.Count < CEdgeCount) { FeatureE.Add(-1); } Visited.Add(true); int[] Neighbours = P.Vertices.GetVertexNeighbours(SplitCenter); foreach (int n in Neighbours) { Visited[n] = true; } } } } } } //Collapse the edges that are too short for (int i = 0; i < EdgeCount; i++) { if (P.Halfedges[2 * i].IsUnused == false) { int vStart = P.Halfedges[2 * i].StartVertex; int vEnd = P.Halfedges[2 * i + 1].StartVertex; if ((Visited[vStart] == false) && (Visited[vEnd] == false)) { if (!(AnchorV[vStart] != -1 && AnchorV[vEnd] != -1)) // if both ends are anchored, don't collapse { int Collapse_option = 0; //0 for none, 1 for collapse to midpt, 2 for towards start, 3 for towards end //if neither are anchorV if (AnchorV[vStart] == -1 && AnchorV[vEnd] == -1) { // if both on same feature (or neither on a feature) if (FeatureV[vStart] == FeatureV[vEnd]) { Collapse_option = 1; } // if start is on a feature and end isn't if ((FeatureV[vStart] != -1) && (FeatureV[vEnd] == -1)) { Collapse_option = 2; } // if end is on a feature and start isn't if ((FeatureV[vStart] == -1) && (FeatureV[vEnd] != -1)) { Collapse_option = 3; } } else // so one end must be an anchor { // if start is an anchor if (AnchorV[vStart] != -1) { // if both are on same feature, or if the end is not a feature if ((FeatureE[i] != -1) || (FeatureV[vEnd] == -1)) { Collapse_option = 2; } } // if end is an anchor if (AnchorV[vEnd] != -1) { // if both are on same feature, or if the start is not a feature if ((FeatureE[i] != -1) || (FeatureV[vStart] == -1)) { Collapse_option = 3; } } } Point3d Mid = MidPt(P, i); double L2 = TargetLength.Calculate(P, 2 * i); if ((Collapse_option != 0) && (EdgeLength[2 * i] < (1 - t) * 4f / 5f * L2)) { int Collapsed = -1; int CollapseRtn = -1; if (Collapse_option == 1) { Collapsed = P.Halfedges[2 * i].StartVertex; P.Vertices.SetVertex(Collapsed, MidPt(P, i)); CollapseRtn = P.Halfedges.CollapseEdge(2 * i); } if (Collapse_option == 2) { Collapsed = P.Halfedges[2 * i].StartVertex; CollapseRtn = P.Halfedges.CollapseEdge(2 * i); } if (Collapse_option == 3) { Collapsed = P.Halfedges[2 * i + 1].StartVertex; CollapseRtn = P.Halfedges.CollapseEdge(2 * i + 1); } if (CollapseRtn != -1) { int[] Neighbours = P.Vertices.GetVertexNeighbours(Collapsed); foreach (int n in Neighbours) { Visited[n] = true; } } } } } } } EdgeCount = P.Halfedges.Count / 2; if ((Flip == 0) && (PullStrength > 0)) { //Flip edges to reduce valence error for (int i = 0; i < EdgeCount; i++) { if (!P.Halfedges[2 * i].IsUnused && (P.Halfedges[2 * i].AdjacentFace != -1) && (P.Halfedges[2 * i + 1].AdjacentFace != -1) && (FeatureE[i] == -1) // don't flip feature edges ) { int Vert1 = P.Halfedges[2 * i].StartVertex; int Vert2 = P.Halfedges[2 * i + 1].StartVertex; int Vert3 = P.Halfedges[P.Halfedges[P.Halfedges[2 * i].NextHalfedge].NextHalfedge].StartVertex; int Vert4 = P.Halfedges[P.Halfedges[P.Halfedges[2 * i + 1].NextHalfedge].NextHalfedge].StartVertex; int Valence1 = P.Vertices.GetValence(Vert1); int Valence2 = P.Vertices.GetValence(Vert2); int Valence3 = P.Vertices.GetValence(Vert3); int Valence4 = P.Vertices.GetValence(Vert4); if (P.Vertices.NakedEdgeCount(Vert1) > 0) { Valence1 += 2; } if (P.Vertices.NakedEdgeCount(Vert2) > 0) { Valence2 += 2; } if (P.Vertices.NakedEdgeCount(Vert3) > 0) { Valence3 += 2; } if (P.Vertices.NakedEdgeCount(Vert4) > 0) { Valence4 += 2; } int CurrentError = Math.Abs(Valence1 - 6) + Math.Abs(Valence2 - 6) + Math.Abs(Valence3 - 6) + Math.Abs(Valence4 - 6); int FlippedError = Math.Abs(Valence1 - 7) + Math.Abs(Valence2 - 7) + Math.Abs(Valence3 - 5) + Math.Abs(Valence4 - 5); if (CurrentError > FlippedError) { P.Halfedges.FlipEdge(2 * i); } } } } else { //Flip edges based on angle for (int i = 0; i < EdgeCount; i++) { if (!P.Halfedges[2 * i].IsUnused && (P.Halfedges[2 * i].AdjacentFace != -1) && (P.Halfedges[2 * i + 1].AdjacentFace != -1) && (FeatureE[i] == -1) // don't flip feature edges ) { int Vert1 = P.Halfedges[2 * i].StartVertex; int Vert2 = P.Halfedges[2 * i + 1].StartVertex; int Vert3 = P.Halfedges[P.Halfedges[P.Halfedges[2 * i].NextHalfedge].NextHalfedge].StartVertex; int Vert4 = P.Halfedges[P.Halfedges[P.Halfedges[2 * i + 1].NextHalfedge].NextHalfedge].StartVertex; Point3d P1 = P.Vertices[Vert1].ToPoint3d(); Point3d P2 = P.Vertices[Vert2].ToPoint3d(); Point3d P3 = P.Vertices[Vert3].ToPoint3d(); Point3d P4 = P.Vertices[Vert4].ToPoint3d(); double A1 = Vector3d.VectorAngle(new Vector3d(P3 - P1), new Vector3d(P4 - P1)) + Vector3d.VectorAngle(new Vector3d(P4 - P2), new Vector3d(P3 - P2)); double A2 = Vector3d.VectorAngle(new Vector3d(P1 - P4), new Vector3d(P2 - P4)) + Vector3d.VectorAngle(new Vector3d(P2 - P3), new Vector3d(P1 - P3)); if (A2 > A1) { P.Halfedges.FlipEdge(2 * i); } } } } if (Minim) { Vector3d[] SmoothC = LaplacianSmooth(P, 1, smooth); for (int i = 0; i < P.Vertices.Count; i++) { if (AnchorV[i] == -1) // don't smooth feature vertices { P.Vertices.MoveVertex(i, 0.5 * SmoothC[i]); } } } Vector3d[] Smooth = LaplacianSmooth(P, 0, smooth); for (int i = 0; i < P.Vertices.Count; i++) { if (AnchorV[i] == -1) // don't smooth feature vertices { // make it tangential only Vector3d VNormal = Normal(P, i); double ProjLength = Smooth[i] * VNormal; Smooth[i] = Smooth[i] - (VNormal * ProjLength); P.Vertices.MoveVertex(i, Smooth[i]); if (P.Vertices.NakedEdgeCount(i) != 0)//special smoothing for feature edges { int[] Neighbours = P.Vertices.GetVertexNeighbours(i); int ncount = 0; Point3d Avg = new Point3d(); for (int j = 0; j < Neighbours.Length; j++) { if (P.Vertices.NakedEdgeCount(Neighbours[j]) != 0) { ncount++; Avg = Avg + P.Vertices[Neighbours[j]].ToPoint3d(); } } Avg = Avg * (1.0 / ncount); Vector3d move = Avg - P.Vertices[i].ToPoint3d(); move = move * smooth; P.Vertices.MoveVertex(i, move); } if (FeatureV[i] != -1)//special smoothing for feature edges { int[] Neighbours = P.Vertices.GetVertexNeighbours(i); int ncount = 0; Point3d Avg = new Point3d(); for (int j = 0; j < Neighbours.Length; j++) { if ((FeatureV[Neighbours[j]] == FeatureV[i]) || (AnchorV[Neighbours[j]] != -1)) { ncount++; Avg = Avg + P.Vertices[Neighbours[j]].ToPoint3d(); } } Avg = Avg * (1.0 / ncount); Vector3d move = Avg - P.Vertices[i].ToPoint3d(); move = move * smooth; P.Vertices.MoveVertex(i, move); } //projecting points onto the target along their normals if (pull > 0) { Point3d Point = P.Vertices[i].ToPoint3d(); Vector3d normal = Normal(P, i); Ray3d Ray1 = new Ray3d(Point, normal); Ray3d Ray2 = new Ray3d(Point, -normal); double RayPt1 = Rhino.Geometry.Intersect.Intersection.MeshRay(M, Ray1); double RayPt2 = Rhino.Geometry.Intersect.Intersection.MeshRay(M, Ray2); Point3d ProjectedPt; if ((RayPt1 < RayPt2) && (RayPt1 > 0) && (RayPt1 < 1.0)) { ProjectedPt = Point * (1 - pull) + pull * Ray1.PointAt(RayPt1); } else if ((RayPt2 < RayPt1) && (RayPt2 > 0) && (RayPt2 < 1.0)) { ProjectedPt = Point * (1 - pull) + pull * Ray2.PointAt(RayPt2); } else { ProjectedPt = Point * (1 - pull) + pull * M.ClosestPoint(Point); } P.Vertices.SetVertex(i, ProjectedPt); } if (FeatureV[i] != -1) //pull feature vertices onto feature curves { Point3d Point = P.Vertices[i].ToPoint3d(); Curve CF = FC[FeatureV[i]]; double param1 = 0.0; Point3d onFeature = new Point3d(); CF.ClosestPoint(Point, out param1); onFeature = CF.PointAt(param1); P.Vertices.SetVertex(i, onFeature); } } else { P.Vertices.SetVertex(i, FV[AnchorV[i]]); //pull anchor vertices onto their points } } //end new AnchorV = CompactByVertex(P, AnchorV); //compact the fixed points along with the vertices FeatureV = CompactByVertex(P, FeatureV); FeatureE = CompactByEdge(P, FeatureE); P.Compact(); //this cleans the mesh data structure of unused elements } } DA.SetData(0, P); }
/// <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) { List<Dictionary<string, object>> pf_in = new List<Dictionary<string, object>>(); string key_in = ""; List<object> v_out = new List<object>(); GH_ObjectWrapper key_str = new GH_ObjectWrapper(); if (!DA.GetDataList(0, pf_in)) return; if (!DA.GetData(1, ref key_in)) return; //for (int i = 0; i < pf_in.Count; i++) //{ // var d = pf_in[i]; // foreach (object key in d.Keys) // { // var a = key; // var h1 = a.GetHashCode(); // var h2 = key_in.GetHashCode(); // string s1 = a.ToString(); // string s2 = key_in.ToString(); // bool test =key.Equals(key_in); // bool test2 = a.Equals(key); // bool test3 = s1.Equals(s2); // bool test4 = Object.Equals(key, key_in); // } //v_out.Add(pf_in[i][k[0]]); for (int i = 0; i < pf_in.Count; i++) { if (pf_in[i].ContainsKey(key_in)) { v_out.Add(pf_in[i][key_in]); } } DA.SetDataList(0, v_out); }
protected override void SolveInstance(IGH_DataAccess DA) { AWorld refwrld = new AWorld(); List<object> v_list = new List<object>(); GH_ObjectWrapper gh_dict = new GH_ObjectWrapper(); IDictionary<string, string> dict = new Dictionary<string,string>(); string k = ""; //GH_Dict test = GH_Dict.create("a", 1.0); //if (!DA.GetData(0, ref refwrld) || !refwrld.IsValid) return; //AWorld wrld = new AWorld(refwrld); SpatialGraph gph = new SpatialGraph(); if (!DA.GetData(0, ref gph)) return; int nGen = 0; string pyString = ""; if (!DA.GetData(1, ref pyString)) return; if (!DA.GetDataList(2, v_list)) return; if (!DA.GetData(3, ref nGen)) return; if (!DA.GetData(4, ref gh_dict)) return; if (!DA.GetData(5, ref k)) return; //dict = (IDictionary<string, string>)gh_dict.Value; //object d = gh_dict.Value; var t = Type.GetType("IronPython.Runtime.PythonDictionary,IronPython"); IDictionary i_dict = Activator.CreateInstance(t) as IDictionary; //IronPython.Runtime.PythonDictionary d = gh_dict.Value; //string v = d.get(k); string v = "oops"; // Sets the initial Generation by using the input v_list // if it runs out of values, it starts over (wraps) //object[] val_list = new object[gph.nodes.Count]; //int v_i = 0; //for (int i = 0; i < gph.nodes.Count; i++) //{ // if (v_i == v_list.Count) v_i = 0; // val_list[i] = v_list[v_i]; // v_i++; //} //AWorld wrld = new AWorld(gph, val_list); //_py = PythonScript.Create(); //_py.Output = this.m_py_output.Write; //_compiled_py = _py.Compile(pyString); //// console out Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String> consoleOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String>(); //// Main evaluation cycle //// Should move code into the Antsworld Class //for (int g = 0; g < nGen; g++) //{ // // console out // this.m_py_output.Reset(); // double[] new_vals = new double[wrld.NodeCount]; // for (int i = 0; i < wrld.NodeCount; i++) // { // int[] neighboring_indices = wrld.gph.NeighboringIndexesOf(i); // // build list of neighboring values // List<double> neighboring_vals = new List<double>(); // for (int k = 0; k < neighboring_indices.Length; k++) neighboring_vals.Add(wrld.LatestGen[neighboring_indices[k]]); // double d = EvaluateCell(i, wrld.LatestGen[i], neighboring_vals); // //double d = g + i + 0.0; // new_vals[i] = d; // } // wrld.AddGen(new_vals); // // console out // Grasshopper.Kernel.Data.GH_Path key_path = new Grasshopper.Kernel.Data.GH_Path(g); // List<Grasshopper.Kernel.Types.GH_String> gh_strs = new List<Grasshopper.Kernel.Types.GH_String>(); // foreach (String str in this.m_py_output.Result) gh_strs.Add(new Grasshopper.Kernel.Types.GH_String(str)); // consoleOut.AppendRange(gh_strs, key_path); //} DA.SetDataTree(0, consoleOut); //DA.SetData(1, wrld); DA.SetData(2, v); }