Skip to content

02 First GH_CPython plugin

Mahmoud AbdelRahman edited this page Aug 17, 2017 · 2 revisions

2- Create your first GH_CPython plugin

Now you are ready to create your first plugin.

  1. create a new GH_CPython component by dragging and dropping it into the canvas, then right click and change its name to FirstPlugin changename
  2. To start coding, double click on the component name or icon a new python editor widow will appear, this window has already some text, don't worry about the text, you can remove it if you wish, however, this text includes the description of the component as well as the description of inputs and outputs, we will clarify it in the following section.

image

  1. Now, lets add new input before we write our code. To do this, continue zooming in until this marks appear (+),(-), to add new input, click on the addition cross mark. a new input will be added and automatically named x, you can change its name by right clicking on it and changing its name from the text box that appears on the top of the menu, but, I'll keep it as is.

image

  1. Now, lets add some variables to the component, for example, I'll add a panel to the _input input, a numerical slider to the x input, and a panel to the output_ output , change the values as you like.

image

  1. This is great!, now, lets start coding, I'll write these three lines of code:
output_ = "My name is " + _input
output_ += "\n"
output_ += "I'm " + str(x) + " years old"

image

  1. Now, lets change the icon of this component, for example, I'll use the following icon, notice that it should be a 24x24 pixel image. firstplugin . Simply, drag and drop it into the center of your plugin. If it is 24x24 pixel image, it will be changed as follows:

image

  1. Everything is almost done, however, you can add some extra features such as the description of the plugin, and the description of the inputs and outputs, this is very important to make your plugin readable and easily used. But first, What is the description of the component ?
    • if you hovered your mouse over the component, a yellow panel will appear that indicate the name of the plugin and its function... the default text is Description of the plugin Here \n Write here any thing...

    • Also, if you hover your mouse cursor over any of the inputs or outputs, a similar window will appear indicating the description of the input or output.

image

  1. To change the default description of the component, we will add these lines of code at the beginning of the python editor ** Then click on test or close button so that changes take effect**:
# First Plugin
"""
[desc]
First Plugin:
This is my first GH_CPython plugin 
[/desc]
"""

image

  1. To add description to the inputs or outputs, we will put each input description inside the following tag:
    • for inputs, <inp> inputname : description </inp>
    • For outputs, <out> outputName: description </out>

So, the above code will be updated to the following:

# First Plugin
"""
[desc]
First Plugin:
This is my first GH_CPython plugin 
[/desc]

<inp>
_input: This is the input descripton 
    It is a string that contain the userName
</inp>

<inp>
x: This is an integer indicating the age of the
user default value is 30.
</inp>

<out>
output_ : This is a string showing username
and age in two senteses.
</out>
"""

image

  1. Finally, to save your Firstplugin, click on the component, then go to File > Create user object a new window will appear as shown change the Category name to FP and the Sub-Category to pluginNo01 or any other names then click on Ok

image

Congratulations!!!, you will notice a new tab called FP has appeared on the Component Tabs: image

Clone this wiki locally