This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-first-component-run.html
executable file
·198 lines (168 loc) · 10.8 KB
/
my-first-component-run.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My First Component Run – Livestock3D</title>
<!-- Meta -->
<meta name="description" content="Livestock3D – ">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Social -->
<meta property="article:author" content="Christian Kongsgaard" />
<meta property="article:section" content="posts" />
<meta property="article:published_time" content="2018-03-22" />
<meta property="og:type" content="article"/>
<meta property="og:title" content="My First Component Run"/>
<meta property="og:description" content="Run Component You have to save and restart Grasshopper before we start testing the our component. We do that to make sure that Rhino has loaded the newest versions of the scripts from %appdata%\McNeel\Rhinoceros\5.0\scripts\livestock3d When you open "1 - My First Component.gh" it should …"/>
<meta property="og:site_name" content="Livestock3D" />
<meta property="og:url" content="https://livestock3d.github.io/my-first-component-run.html"/>
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="My First Component Run">
<meta name="twitter:description" content="Run Component You have to save and restart Grasshopper before we start testing the our component. We do that to make sure that Rhino has loaded the newest versions of the scripts from %appdata%\McNeel\Rhinoceros\5.0\scripts\livestock3d When you open "1 - My First Component.gh" it should …">
<meta name="twitter:url" content="https://livestock3d.github.io/my-first-component-run.html">
<!-- Feed -->
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Open+Sans:regular,bold">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/w3.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/style.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/jqcloud.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/pygments-highlight-github.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/static/custom.css">
<!-- Icon -->
<link rel="shortcut icon" type="image/x-icon" href="https://livestock3d.github.io/favicon.ico">
<!-- JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://livestock3d.github.io/theme/js/jqcloud.min.js"></script>
</head>
<body>
<div class="w3-row w3-card w3-white">
<header id="header">
<a href="https://livestock3d.github.io" id="header-logo" title="Home">CK</a>
<nav id="header-menu">
<ul>
<li><a href="https://livestock3d.github.io/pages/contributing-to-livestock.html">Contributing to Livestock</a></li>
<li><a href="https://livestock3d.github.io/pages/how-is-it-working.html">How is it Working?</a></li>
<li><a href="https://livestock3d.github.io/pages/welcome-to-livestock3d.html">Welcome to Livestock3D</a></li>
<li class="w3-bottombar w3-border-white w3-hover-border-green" style="font-weight: bold;"><a href="https://livestock3d.github.io/category/posts.html">posts</a></li>
</ul>
</nav>
</header>
</div>
<br><br><br>
<article>
<header class="w3-container col-main">
<h1>My First Component Run</h1>
<div class="post-info">
<div class="w3-opacity w3-margin-right w3-margin-bottom" style="flex-grow: 1;">
<span><time datetime="2018-03-22T00:00:00+01:00">to 22 marts 2018</time> in <a href="https://livestock3d.github.io/category/posts.html" title="All articles in category posts">posts</a></span>
</div>
<div>
<span class="w3-tag w3-light-grey w3-text-green w3-hover-green">
<a href="https://livestock3d.github.io/tag/python.html" title="All articles with Python tag">#python</a>
</span>
<span class="w3-tag w3-light-grey w3-text-green w3-hover-green">
<a href="https://livestock3d.github.io/tag/grasshopper.html" title="All articles with Grasshopper tag">#grasshopper</a>
</span>
<span class="w3-tag w3-light-grey w3-text-green w3-hover-green">
<a href="https://livestock3d.github.io/tag/tutorial.html" title="All articles with Tutorial tag">#tutorial</a>
</span>
<span class="w3-tag w3-light-grey w3-text-green w3-hover-green">
<a href="https://livestock3d.github.io/tag/my_first_component.html" title="All articles with My_First_Component tag">#my_first_component</a>
</span>
</div>
</div>
</header>
<br>
<div class="col-main w3-container">
<section id="content">
<h2>Run Component</h2>
<p>You have to save and restart Grasshopper before we start testing the our component. We do that to make sure that Rhino has
loaded the newest versions of the scripts from</p>
<blockquote>
<p>%appdata%\McNeel\Rhinoceros\5.0\scripts\livestock3d</p>
</blockquote>
<p>When you open "1 - My First Component.gh" it should look something like this:
<img alt="alt text" src="https://livestock3d.github.io/images/first_component_5.png"></p>
<p>You should be missing the panel with "Hallo World!", the slider and the boolean toggle. Add those three things as in the image.
You can see that our component is red and has an error message. Connect a panel to "out" to see the message.
The component complains that it can not find PythonExe. PythonExe is the path to python.exe. We specify that path in the
component Python Executor. Let us do that now. python.exe should be located in the Anaconda folder. You can usually find it
in C:\Users\your_username\Anaconda3. Navigate to the "envs" folder and then the livestock_env folder. Here you will find python.exe.
Copy the path to python.exe into the panel left of the Python Executor component hand connect the panel.
The panel should contain something like this:</p>
<blockquote>
<p>C:\Users\Christian\Anaconda3\envs\livestock_env\python.exe</p>
</blockquote>
<p>If Python Executor is yellow, it means that you have put in a non-valid path.
Our component is still red, though. Disable it and enable it again to make that go away.
Everything should be fine now, and it is time to set the boolean toggle to True.
A window should open and close real fast. That means that the CPython function has been ran. In the panel connected to "out"
you should be able to see the results.
<img alt="alt text" src="https://livestock3d.github.io/images/first_component_6.png"></p>
<p>Congratulations! You have now created your very first Grasshopper component, that uses the Livestock Template Method!
Being able to run native CPython code is a great advantage and increases the possibilities of what you can do. Just head over
to <a href="https://pypi.org/">PyPI</a> or <a href="https://github.com/">Github</a> to find a cool library you would like to use! </p>
<p>Before we completely wrap up. Let us take a look on what happened, when the component ran:</p>
<ol>
<li>The Grasshopper component writes the data_file.txt</li>
<li>Then the template file: my_first_template.py</li>
<li>It then spawns a subprocess, calling python.exe to execute my_first_template.py</li>
<li>When executed my_first_template.py calls my_function() from the livestock3d.py file</li>
<li>my_function() reads the data_file.txt and creates the result.txt</li>
<li>The Grasshopper component reads result.txt and prints out the lines</li>
</ol>
<p>We can go to:</p>
<blockquote>
<p>C:\livestock3d\data</p>
</blockquote>
<p>and see that all the files are still there:</p>
<ul>
<li>data_file.txt</li>
<li>my_first_template.py</li>
<li>results.txt</li>
</ul>
<p>If you want to know more take a look at the post <a href="https://livestock3d.github.io/pages/how-is-it-working.html">How is it working?</a>, continue with
a our second <a href="https://livestock3d.github.io/graph-plotter-component.html">tutorial</a> or even better: Make your own component.</p>
</section>
<br><br><br>
<footer>
<div class="adjust-width">
<div id="author-block" class="w3-light-grey w3-border">
<div id="author-info">
<a href="http://ocni-dtu.github.io"><img style="width: 60px; height: 60px;" src="https://github.com/livestock3d/livestock3d.github.io/blob/master/images/profil.jpg" onerror="this.src='theme/images/avatar.png'" alt="Avatar"></a>
<div style="margin-left: 20px; margin-top: 15px;">
<a href="http://ocni-dtu.github.io"><span id="author-name" class="w3-hover-text-dark-grey">Christian Kongsgaard</span></a>
<p id="author-story">I'm a former Master Student of the Technical University of Denmark (DTU).
I'm developed Livestock for my thesis.</p>
</div>
</div>
</div>
</div>
<br><br><br>
<p style="font-size:10pt; font-style: italic;">Did you like this article? Share it with your friends!</p>
<div id="share" class="share">
<a href="http://www.facebook.com/sharer.php?u=https%3A//livestock3d.github.io/my-first-component-run.html&t=Livestock3D%3A%20My%20First%20Component%20Run" target="_blank" class="w3-btn w3-indigo">
<i class="fa fa-facebook"></i> <span>Facebook</span>
</a>
<a href="http://twitter.com/share?url=https%3A//livestock3d.github.io/my-first-component-run.html&text=Livestock3D%3A%20My%20First%20Component%20Run" target="_blank" class="w3-btn w3-blue">
<i class="fa fa-twitter"></i> <span>Twitter</span>
</a>
<a href="https://plus.google.com/share?url=https%3A//livestock3d.github.io/my-first-component-run.html" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" class="w3-btn w3-red">
<i class="fa fa-google-plus"></i> <span>Google</span>
</a>
</div>
<br><br><br>
</footer>
</div>
</article>
<footer id="footer">
<div id="footer-copyright" class="w3-center w3-small w3-text-grey w3-padding-48">
<span>
©
2018 Christian Kongsgaard
</span>
</div>
</footer>
</body>
</html>