Convert Text to ToString on Mac

something like this

yup, that I understand, but what do you want to do with the non-numeric text?

Separate one from another (exclude non-numeric text). I believe Convert.ToDouble will give an error.

haa ok, no worries that can be easily done

Cheers :slight_smile: I know how to do “if” statements. But I still trying to get familiar with RhinoCommon
Thank you for help

@arten
Just to finalize this I added more robustness to it. It will ignore everything that is just letters, and all other crazy combinations engineers might come up with . See screenshot which is more self explanatory here… lol

PS: All the filtering stuff does not have to do with RhinoCommon at all though, pure string manipulation in C#

FilterMachine_ToForum.gh (8.6 KB)

and alas the code

private void RunScript(string layer, string illigalChars, ref object Points, ref object Heights)
  {

    List<Point3d> pts;
    List<double> heights = new List<double>();

    GetDataFromText(Rhino.RhinoDoc.ActiveDoc, layer, illigalChars, out pts, out heights);

    Points = pts;
    Heights = heights;
    Component.Message = "Filer Machine";
  }

  // <Custom additional code> 
  public  void GetDataFromText(Rhino.RhinoDoc doc, string layerName, string illegalChars
    , out List<Point3d> pts, out List<double> heights)

  {

    List<Point3d> _pts = new List<Point3d>();
    List<double> _heights = new List<double>();

    Rhino.DocObjects.RhinoObject[] rhobjs = doc.Objects.FindByLayer(layerName);

    if(rhobjs.Length == 0) throw new ArgumentException ("Could not find any text objects in given layer!");

    for (int i = 0; i < rhobjs.Length; i++)
    {
      GeometryBase a = rhobjs[i].Geometry;

      TextEntity text = (TextEntity) a;
      string name = text.PlainText;


      // Check if text contains letters
      // Only process text which does not contain letters
      if(name.Any(x => !char.IsLetter(x)))
      {

        // Remove all unwanted characters
        string newString = RemoveUnwantedCharacters(name, illegalChars.ToCharArray());

        if(newString == "")  CovertStringToDouble(name, _heights);

        if(newString != "") CovertStringToDouble(newString, _heights);

        BoundingBox b = a.GetBoundingBox(true);
        _pts.Add(b.Center);


      }



    }

    pts = _pts;
    heights = _heights;

  }


  public double CovertStringToDouble(string s, List<double> heights)
  {
    double result;
    if(s.Contains(","))
    {
      string n = s.Replace(",", ".");


      if(double.TryParse(n, out result)) heights.Add(result);

      else
        throw new ArgumentException ("Casting from string to double failed!");
    }

    else
    {

      if(double.TryParse(s, out result)) heights.Add(result);

      else
        throw new ArgumentException ("Casting from string to double failed!");
    }

    return result;
  }



  public  string RemoveUnwantedCharacters(string input, char[] allowedCharacters)
  {
    var filtered = input.ToCharArray();

    return new String(filtered.Where(c => !char.IsLetter(c) && !char.IsUpper(c) && !allowedCharacters.Contains(c)).ToArray());
  }

Cheers, and happy coding :love_you_gesture:

Thank you @rawitscher-torres
Yep, I having fun with it ))