Autodesk Labs have just released DesignScript as a Technology Preview, so I’ve been looking at porting some of Nathan Miller’s Proving Ground RevitPythonScript examples, just to see how DesignScript works. This first post summarises the Point Creation examples:

#### Single Point

This is the simplest example: Create a point at specified coordinates.

import("ProtoGeometry.dll");

// create a point with x, y, and z coordinates

x_pos = 10;

y_pos = 10;

z_pos = 0;

pCoord = Point.ByCoordinates(x_pos, y_pos, z_pos);

This was adapted from the example on page 17 of the DesignScript Language Manual, version 09. It is very simple: Import the ProtoGeometry dll, define the coordinates and call Point.ByCoordinates(x,y,z).

#### Row of Points

Create a row of points at specified xy values:

import("ProtoGeometry.dll");

// create a row of points

x_pos = 0..100..10;

y_pos = 0..100..10;

z_pos = 0;

pCoord = Point.ByCoordinates(x_pos, y_pos, z_pos);

This example is hardly more complex. Just by defining the x and y coordinates as ranges rather than single values, Point.ByCoordinates generates a row of points.

#### Grid of Points

Create a grid of points:

import("ProtoGeometry.dll");

// create a grid of points

x_pos = 0..100..10;

y_pos = 0..100..10;

z_pos = 0;

pCoord = Point.ByCoordinates(x_pos<1>, y_pos<2>, z_pos);

And just by making a tiny change to the code, adding the Replication Guides <1> and <2> to the Point.ByCoordinates call, Point.ByCoordinates generates a grid of points.

#### Sine Wave Points

Create a grid of points, where the z-value of each point is a function of the x and y coordinates.

import("ProtoGeometry.dll");

import("Math.dll");

def RadiansToDegrees(n)

{

return = n * 360/(2 * 3.142);

}

def CosXPlusSinY(x, y)

{

return = Math.Cos(RadiansToDegrees(x)) + Math.Sin(RadiansToDegrees(y));

}

def PointZ(x, y)

{

z = CosXPlusSinY(x, y);

s = Print(z);

return = Point.ByCoordinates(10 * x, 10 * y, 10 * z);

}

// create a grid of points where z = f(xy)

x_pos = 0..30;

y_pos = 0..30;

pCoord = PointZ(x_pos<1>, y_pos<2>);

Now this is suddenly much more complex. The simple range and replication guide tricks work for simple cases, but are harder to apply in more real-world examples.

I wanted to use the replication guides to generate the grid (I could have fallen back on nested loops, of course, but that would be a shame). There doesn’t seem to be a way to include the z function inline, like this:

pcoord = Point.ByCoordinate(x_pos<1>, y_pos<2>,CosXPlusSinY(x_pos,y_pos)) //fail

So I wrapped the z-calculation and the Point.ByCoordinates call in a custom function, PointZ(x,y). In this way, I could use the replication guides in the call to PointZ, and

The other slight complexity is that both Python and Dynamo use radian values for their trig functions, DesignScript expects degrees. Hence the RadiansToDegrees function (with a dodgy value for pi because, well, I haven’t been able to find the correct syntax for DesignScript’s PI() function).

And here’s the source: DesignScript Points examples.

## 2 comments:

Thanks for the great post. Your comment about

pcoord = Point.ByCoordinate(x_pos<1>, y_pos<2>,CosXPlusSinY(x_pos,y_pos)) //fail

is interesting. it's almost like you would want something like:

pcoord = Point.ByCoordinate(tx = x_pos<1>, ty = y_pos<2>,CosXPlusSinY(tx, ty))

Is that the kind of thing you were thinking about?

===

With respect to the PI thing, it looks like it's a bug in a part of our infrastructure. We're looking at it, I'll get back to you ASAP.

Thanks, Luke,

Yes, that was the idea of that Point.ByCoordinate call. The replication guides seem quite an elegant, powerful feature. I wasn't sure whether they could be extended to allow that kind of call without losing the elegance.

Regarding PI, I'm glad it wasn't just me!

Anyhow, thanks again for the comments.

Post a Comment