Grasshopper

algorithmic modeling for Rhino

Hi, I am trying to convert a piece of my code in C# to Python. I get many errors when it reaches the plane fitting line. Can anybody help please? Has anybody tried SharpDevelop for automatic conversion before?

PointCloud PC = new PointCloud();
PC.AddRange(Pts);
Vector3d n = Vector3d.ZAxis;
if (VP == null) {
Rhino.Geometry.BoundingBox BBox = PC.GetBoundingBox(false);
Rhino.Geometry.Box BoundingB = new Rhino.Geometry.Box(BBox);
VP = BoundingB.PointAt(0.5, 0.5, 1);
VP.Z = BoundingB.Z.T1 * 100;

}
List<Vector3d> Normals = new List<Vector3d>();
double Dev = 0;
foreach (Point3d point in Pts) {
List<Point3d> Neighbors = Pts.FindAll(V => V.DistanceTo(point) < D);
Rhino.Geometry.Plane NP = Rhino.Geometry.Plane.WorldXY;
Plane.FitPlaneToPoints(Neighbors, out NP, out Dev);
if (Dev > MD)
//FileSystem.Print("This computation Is Not As accurate As desired, Try lowering the distance tolerance or rasing your Maximum Deviation");
n = NP.Normal;
if (n * (VP - point) > 0) {
Normals.Add(n);
} else {
Normals.Add(-n);
}
}
A = Normals;

Views: 992

Replies to This Discussion

Hi Pirouz,

I do not "speak" C#, but can read a line or two.

Please post your code in blackquote (") next time, as in this way the code would retain the indentation structure as well. It may be that because of this I haven't understood your C# blocks correctly.

Maybe this will help, until Giulio or some other expert arrive:

import System
import Rhino
import clr

PC = Rhino.Geometry.PointCloud()
PC.AddRange(Pts)
n = Vector3d.ZAxis
if VP == None:
    BBox = PC.GetBoundingBox(False)
    BoundingB = Rhino.Geometry.Box(BBox)
    VP = BoundingB.PointAt(0.5, 0.5, 0.5)
    VP.Z = BoundingB.Z.T1 * 100

NP = clr.StrongBox[Rhino.Geometry.Plane]()
Dev = clr.StrongBox[System.Double]()
Normals = []
for point in Pts:
    Neighbors = [pt for pt in Pts if (V>= V.DistanceTo(point)) and (V.DistanceTo(point) < D)]
    Plane.FitPlaneToPoints(Neighbors, NP, Dev)
    if Dev > MD:
        n = NP.Normal
    if n*(VP-point) > 0:
        Normals.append(n)
    else:
        Normals.append(-n)

A = Normals

On SharpDevelop, I tried using it for VB.NET to Python some time ago, and was not satisfied with results (maybe something changed from 3.1 version). Be sure to put your C# code in a class before trying to convert it.

Also, it would be nice if you would edit your initial post (upper right angle -> Options -> Edit discussion) and change the topic category (move it to the VB, C# and Python Coding category). Thanks.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service