-
Notifications
You must be signed in to change notification settings - Fork 37
02 First GH_CPython plugin
Mahmoud AbdelRahman edited this page Aug 17, 2017
·
2 revisions
Now you are ready to create your first plugin.
- create a new GH_CPython component by dragging and dropping it into the canvas, then right click and change its name to
FirstPlugin
- 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.
- 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 namedx
, 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.
- Now, lets add some variables to the component, for example, I'll add a panel to the
_input
input, a numerical slider to thex
input, and a panel to theoutput_
output , change the values as you like.
- 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"
- 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. . Simply, drag and drop it into the center of your plugin. If it is 24x24 pixel image, it will be changed as follows:
- 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.
-
- 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]
"""
- 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>
- for inputs,
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>
"""
- Finally, to save your Firstplugin, click on the component, then go to
File > Create user object
a new window will appear as shown change theCategory
name toFP
and theSub-Category
topluginNo01
or any other names then click onOk
Congratulations!!!, you will notice a new tab called FP
has appeared on the Component Tabs
: