Pass string data in protected override void

I don’t know why in the below method the string is null. how should I pass data by solveinstance() ?

 string getstiring;

 protected override void SolveInstance (IGH_DataAccess DA) 
   string img = property.system.image1.jpg;
    DA.GetData (0, ref img); //get data from application and assign the img
    getstiring = img;

 public Bitmap cahid () 
string getdata = getstiring; // it is null


What is that?

Anyway, the code you posted should work, provided you’re getting an actual string out of the data access.

Put a breakpoint on your GetData line to see when that is invoked and what data is retrieved…

private string _text;
protected override void SolveInstance (IGH_DataAccess access)
  string text = null;
  access.GetData(0, ref text);

  if (string.IsNullOrWhitespace(text))
    _text = null;
    _text = text;

david.cs (3.4 KB)
thank you for your response, here is the source code of my attempt to create an image sampler component for grasshopper.
I want to enter data from another component (receive Json data from Runwayml and decode base 64 to bitmap) and show in a component like image sampler.
I’ve spent a whole week on this component and tried many different methods and I used breaking point in all parts of the code but it seems to be impossible to send data from solveinstance() to Class CustomParameterAttributes()

This is very suspicious:

MyComponent1 getdata = new MyComponent1();

Why are you creating a new component just to invoke that method? Surely you want to call that method on the instance of the component associated with your attributes?

You will also definitely want to cache your bitmap. Creating anew from strings during every single redraw is going to drop the refresh rate down to single digits per second.

What I would suggest is you create a property on your attributes class which allows you to get/set a bitmap. You assign this property from within SolveInstance() and get rid of the class level string variable and the SendbBitmap method.

// in the attributes
public Bitmap CanvasImage { get; set; }

// in SolveInstance
var atts = Attributes as CustomParameterAttributes;
if (atts != null)
  atts.CanvasImage = bitImage;
1 Like

Thank for your wise advises and your precious time David. Your suggestions are very helpful.