SpeckleGrasshopper/ObjectCreation/ConvertSpeckleObject.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)
    {
      if (SelectedType is null)
      {
        this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No type chosen.");
        return;
      }
      object inputObject = null;
      if (!DA.GetData(0, ref inputObject))
        return;
      try
      {
        inputObject = inputObject.GetType().GetProperty("Value").GetValue(inputObject);
      }
      catch { }
      if (inputObject == null) return;
      if (!(inputObject.GetType().IsSubclassOf(typeof(SpeckleObject))))
        inputObject = Converter.Serialise(inputObject);
      SpeckleObject convertedObject = (SpeckleObject)Activator.CreateInstance(SelectedType);
      string inputObjectTypeString = (string)inputObject.GetType().GetProperty("Type").GetValue(inputObject);
      if (!((inputObjectTypeString.Contains(convertedObject.Type))) && !(convertedObject.Type.Contains(inputObjectTypeString)))
      {
        this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "SpeckleObject not convertible to type.");
        return;
      }
      var deepCopyObject = CreateCopy(inputObject);
      foreach (PropertyInfo p in convertedObject.GetType().GetProperties().Where(p => p.CanWrite))
      {
        PropertyInfo inputProperty = deepCopyObject.GetType().GetProperty(p.Name);
        if (inputProperty != null)
          p.SetValue(convertedObject, inputProperty.GetValue(deepCopyObject));
      }
      convertedObject.GenerateHash();
      var appId = convertedObject.GetType().GetProperty("ApplicationId").GetValue(convertedObject);
      if (appId == null)
      {
        var myGeneratedAppId = "gh/" + convertedObject.GetType().GetProperty("Hash").GetValue(convertedObject);
        convertedObject.GetType().GetProperty("ApplicationId").SetValue(convertedObject, myGeneratedAppId);
      }
      DA.SetData(0, convertedObject);
    }
protected override void SolveInstance ( IGH_DataAccess DA ) { if ( SelectedType is null ) { this . AddRuntimeMessage ( GH_RuntimeMessageLevel . Warning , " " ) ; return ; } object inputObject = null ; if ( ! DA . GetData ( 0 , ref inputObject ) ) return ; try { inputObject = inputObject . GetType ( ) . GetProperty ( " " ) . GetValue ( inputObject ) ; } catch { } if ( inputObject == null ) return ; if ( ! ( inputObject . GetType ( ) . IsSubclassOf ( typeof ( SpeckleObject ) ) ) ) inputObject = Converter . Serialise ( inputObject ) ; SpeckleObject convertedObject = ( SpeckleObject ) Activator . CreateInstance ( SelectedType ) ; string inputObjectTypeString = ( string ) inputObject . GetType ( ) . GetProperty ( " " ) . GetValue ( inputObject ) ; if ( ! ( ( inputObjectTypeString . Contains ( convertedObject . Type ) ) ) && ! ( convertedObject . Type . Contains ( inputObjectTypeString ) ) ) { this . AddRuntimeMessage ( GH_RuntimeMessageLevel . Error , " " ) ; return ; } var deepCopyObject = CreateCopy ( inputObject ) ; foreach ( PropertyInfo p in convertedObject . GetType ( ) . GetProperties ( ) . Where ( p => p . CanWrite ) ) { PropertyInfo inputProperty = deepCopyObject . GetType ( ) . GetProperty ( p . Name ) ; if ( inputProperty != null ) p . SetValue ( convertedObject , inputProperty . GetValue ( deepCopyObject ) ) ; } convertedObject . GenerateHash ( ) ; var appId = convertedObject . GetType ( ) . GetProperty ( " " ) . GetValue ( convertedObject ) ; if ( appId == null ) { var myGeneratedAppId = " " + convertedObject . GetType ( ) . GetProperty ( " " ) . GetValue ( convertedObject ) ; convertedObject . GetType ( ) . GetProperty ( " " ) . SetValue ( convertedObject , myGeneratedAppId ) ; } DA . SetData ( 0 , convertedObject ) ; }
This is the method that actually does the work.
This is the method that actually does the work .
// Check to see if one is a subclass of another // applicationId generation/setting
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 .