Download DesignScript summary:
Transcript
o
Properties: user defined types (or classes) can have properties which are accessed via the . operator [the dot operator]
Properties may have a defined type.
import("ProtoGeometry.dll");
a = Point.ByCoordinates(5,5,0);
b = a.X; // b = 5 .. access the X coordinate property of the Point variable 'a'
Note: most properties of the geometry objects in ProtoGeometry are ‘read only’ and cannot be assigned to.
A constructor [such as Point.ByCoordinates(5,5,0);] is effectively setting a set of related (and sufficient) properties
‘in one go’. DesignScript intentionally restricts the change of a single property [such as the X coordinate of a point] in isolation,
outside the known context provided by such method.
a.X = 10; // not allowed, instead a method should be used to define a.X in the context of other properties
There are some properties that are ‘writeable’ and can be assigned to, specifically in the DesignScript ProtoGeometry library:
import("ProtoGeometry.dll");
a = Line.ByStartPointEndPoint
a.Color
= Color.Red;
a.Visible = true;
(Point.ByCartesianCoordinates(WCS, 5, 5, 0),
Point.ByCartesianCoordinates(WCS, 10, 5,0));
// assign a color to a geometric variable
// control a variable’s visibility
The users should check the properties of the class he is using to determine which properties are read only or writable.
o
Guaranteed Properties: Each class in the geometry library has a set of guaranteed properties that are always defined no matter
which constructor is used to create an instance of the class. Therefore these guaranteed properties can always be referenced.
There may also be other properties, which are not guaranteed and which are unique to specific constructors being currently
used. These properties may not be available to be referenced if the constructor for this instance is changed.
o
Collections: can be defined with the {} notation and evaluated by the Count() and Rank() functions
a
b
c
d
e
f
o
{1, 2, 3, 4};
// a 1D collection defined using the {} notation, with a list of values
Rank(a);
// b = 1
Count(a);
// c = 4
{ { 1, 2 }, { 3, 4 } }; // d is a 2D collection
Rank(d);
// d = 2
Count(d);
// f = 2
Range Expression: range expression can be used to generate numeric collections, in the form start..end..inc
a
b
c
d
o
=
=
=
=
=
=
=
=
=
=
1..5;
1..9..2;
1..9..~3;
1..9..#3;
//
//
//
//
a
b
c
d
=
=
=
=
{1,2,3,4,5} of no increment is specified use the default increment of '1'
{1,3,5,7,9} using the defined increment '2'
{1.0, 3.666667, 6.333333, 9.0} using the 'approximate' increment '~3'
{1, 5, 9}
using the 'number of cases' '#3'
Indexing: the members of a collection can be accessed using indices and the [] notation
a
b
c
d
=
=
=
=
1..9;
a[0];
a[-1] ;
a[1..5..2];
// a =
// b =
// c =
// d =
//
e = a[{ 2, 3, 0 }]; //
//
f = Count(a);
// f =
{1,2,3,...7, 8, 9}.. using the default increment of '1'
1 … in DesignScript as with other languages, indexing starts from zero
9 … negative indexing counts back from the end of the collection
{2, 4, 6} … a collection of int’s can be used to select a sub collection,
via a range expression
d = {3,4,1} … a collection of int’s can be used to select a sub collection,
via some arbitrary collection
9 … using the Count() function
Note: the following code will fail…
g = a[Count(a)];
// because indexing starts at zero, the last member of a collection is a[Count(a)-1]..
This provides the motivation for negative indexing where:
a[Count(a)-1] is equivalent to a[-1] (the count of a is applied automatically)
o
Rectangular Collection: is a collection where all sub collections are the same dimension and length
a = { { 1, 2 }, { 3, 4 } };
b = Count(a[0]);
c = Count(a[1]);
// a rectangular 2D collection
// b = 2… both the a[0] and a[1] subcollections and have the same length
// c = 2