Grasshopper c# DivideCurveByLength Method issues

Hi all,

I am new to c# scripting in grasshopper and have issues with the DivideCurveByLength method. I keep getting the following error :

" 1. Error (CS0103): The name ‘tempPoints’ does not exist in the current context (line 142)"

// divide curve by length
    
    for( int i = 0; i < primaryLine.BranchCount; i++){
      for( int j = 0; j < primaryLine.Branches[i].Count; j++){
        
        LineCurve tempLine = primaryLine.Branches[i][j];
        
        Point3d[] tempPoints;
        
        try{
          tempLine.DivideByLength(500, true, out tempPoints);
        }catch (Exception e){
          Print("The curve is 500mm or less");
        }
        
        if(tempPoints != null){
          Print(tempPoints.Length.ToString());
        }
      }

Any advice would be greatly appreciated!!

Hello,

Can you upload gh file?

for( int j = 0; j < primaryLine.Branches[i].Count; j++){

        Curve tempLine = primaryLine.Branches[i][j];

        Point3d[] tempPoints;

        tempLine.DivideByLength(500, true, out tempPoints);
        if(tempPoints != null)
        {
          Print(tempPoints.Length.ToString());
        }
        else
        { 
          Print("The curve is 500mm or less");
        }
      }
    }
1 Like

Thanks Tao!

I did what you wrote initially but didn’t realise that LineCurve and Curve are interchangeable. I suppose the lesson here is that DivideByLength only works on Curve and not LineCurve. :zap: