Copyright © 2013 VITRUALITY & Andrea Graziano
AADRL 2013/2014 – Rhino+Grasshopper with C# 延伸閱讀 – Session 1: 指令碼寫作初探
AADRL 2013/2014 – Extending Rhino+Grasshopper with C# – Session 1: Introduction to scripting
Grasshopper 本身是個非常強大的工具,能夠產出許多令人驚豔的作品。然而,礙於它的運作方式,有幾種傳統架構的演算法無法套用於這種以元件互連為基底(component-based)的系統。雖然它包含大量的元件,但仍有一些領域,其所缺少的功能必需透過自行撰寫新的元件,來擴展它的功能。此外(如果你有寫作腳本的經驗)經常有會這類的念頭,發現某些需要的元件,可能只是簡單幾行代碼的改寫,就能更貼近你需要的功能。
Grasshopper in its natural state is a very powerful tool capable of many impressive feats. However, due to the way in which it operates there are some kinds of algorithms than are not possible to fully reproduce using its component-based system that would be trivial to implement in a traditional programming language. Although it contains a vast array of components there are still some areas in which it is lacking in functionality and it can therefore be necessary to extend it by writing new components yourself. Also, there are often things which, while possible, require long strings of components to achieve what might be more simply implemented as just a few lines of code.
C# (讀音:C Sharp)
在此,我們將以 C# 的使用作為我們的指令碼語言。之所以選擇這個語言,是因為它的語法相似於其他的 C 語言 (C,C++,Objective-C),以及那些基於它開發的語言(JAVA、JavaScript、Processing、D、PHP 等),也因為它可用於一些Rhino 的程式編寫 ,例如編寫自訂的 Grasshopper 元件,甚至包含整個 Rhino 外掛程式(Plugins),這是目前 Python 所不能的。然而,上述提到的這些例子,這些與 Grasshopper/Rhino 搭配的也僅只是某些程式的特色,不論你是否你正在使用 C#、Visual Basic 或 Python 結果應該沒有不同(意指程式都應該寫得出來)— 只有程式的語法不同,所以請選你所愛,愛你所選的程式來撰寫。
C#
In the examples given here we will be using C# as our scripting language. This has been chosen because its syntax should be familiar to people who have used any other of the ‘C’ family of programming languages (C, C++, Objective-C) or those based on it (Java, JavaScript, Processing, D, PHP etc.) and also because it can be used for some of the more powerful forms of programming within Rhino, such as writing custom Grasshopper components and even whole other Rhino plugins, which Python currently cannot. However, none of the parts of these examples which interact with Grasshopper/Rhino are language specific and should be the same whether you are using C#, Visual Basic or Python – only the language syntax will be different, so you should be able to apply the following to whichever language you prefer to use.
