SpeckleGrasshopper/UserDataUtils/ExpandUserDataComponent.cs
/// <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>
This is the method that actually does the work.
This is the method that actually does the work .
protected override void SolveInstance( IGH_DataAccess DA )
    {
      List<object> objs = new List<object>();
      objs = Params.Input[ 0 ].VolatileData.AllData( true ).ToList<object>();
      if ( objs.Count == 0 )
      {
        this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, "No dictionaries found." );
        return;
      }
      global = new Dictionary<string, List<object>>();
      var first = true;
      foreach ( var obj in objs )
      {
        GH_ObjectWrapper goo = obj as GH_ObjectWrapper;
        if ( goo == null )
        {
          this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, "Provided object not a dictionary." );
          return;
        }
        ArchivableDictionary dict = goo.Value as ArchivableDictionary;
        if ( dict != null )
        {
          foreach ( var key in dict.Keys )
          {
            if ( ( first ) )
            {
              global.Add( key, new List<object>() );
              global[ key ].Add( dict[ key ] );
            }
            else if ( !global.Keys.Contains( key ) )
            {
              this.AddRuntimeMessage( GH_RuntimeMessageLevel.Error, "Object dictionaries do not match." );
              return;
            }
            else
            {
              global[ key ].Add( dict[ key ] );
            }
          }
        }
        first = false;
      }
      if ( global.Keys.Count == 0 )
      {
        this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, "Empty dictionary." );
        return;
      }
      var changed = false;
      if ( Params.Output.Count != global.Keys.Count )
      {
        changed = true;
      }
      Debug.WriteLine( "changed:" + changed );
      if ( changed )
      {
        Rhino.RhinoApp.MainApplicationWindow.Invoke( setInputsAndExpireComponent );
      }
      else
      {
        try
        {
          int k = 0;
          foreach ( var key in global.Keys )
          {
            Params.Output[ k ].Name = Params.Output[ k ].NickName = key;
            DA.SetDataList( k++, global[ key ].Select( x => new GH_ObjectWrapper( x ) ) );
          }
        }
        catch ( Exception e )
        {
        }
      }
    }
protected override void SolveInstance ( IGH_DataAccess DA ) { List < object > objs = new List < object > ( ) ; objs = Params . Input [ 0 ] . VolatileData . AllData ( true ) . ToList < object > ( ) ; if ( objs . Count == 0 ) { this . AddRuntimeMessage ( GH_RuntimeMessageLevel . Warning , " " ) ; return ; } global = new Dictionary < string , List < object > > ( ) ; var first = true ; foreach ( var obj in objs ) { GH_ObjectWrapper goo = obj as GH_ObjectWrapper ; if ( goo == null ) { this . AddRuntimeMessage ( GH_RuntimeMessageLevel . Warning , " " ) ; return ; } ArchivableDictionary dict = goo . Value as ArchivableDictionary ; if ( dict != null ) { foreach ( var key in dict . Keys ) { if ( ( first ) ) { global . Add ( key , new List < object > ( ) ) ; global [ key ] . Add ( dict [ key ] ) ; } else if ( ! global . Keys . Contains ( key ) ) { this . AddRuntimeMessage ( GH_RuntimeMessageLevel . Error , " " ) ; return ; } else { global [ key ] . Add ( dict [ key ] ) ; } } } first = false ; } if ( global . Keys . Count == 0 ) { this . AddRuntimeMessage ( GH_RuntimeMessageLevel . Warning , " " ) ; return ; } var changed = false ; if ( Params . Output . Count != global . Keys . Count ) { changed = true ; } Debug . WriteLine ( " " + changed ) ; if ( changed ) { Rhino . RhinoApp . MainApplicationWindow . Invoke ( setInputsAndExpireComponent ) ; } else { try { int k = 0 ; foreach ( var key in global . Keys ) { Params . Output [ k ] . Name = Params . Output [ k ] . NickName = key ; DA . SetDataList ( k ++ , global [ key ] . Select ( x => new GH_ObjectWrapper ( x ) ) ) ; } } catch ( Exception e ) { } } }
This is the method that actually does the work.
This is the method that actually does the work .
DA
IGH_DataAccess
The DA object is used to retrieve from inputs and store in outputs.
The DA object is used to retrieve from inputs and store in outputs .