| 1 | <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 | <title>Scripting 4.2. Removing objects</title> |
| 3 | <style> |
| 4 | td { padding-left: 5pt; padding-right: 5pt; } |
| 5 | th { padding-left: 5pt; padding-right: 5pt; } |
| 6 | code { white-space: pre-wrap; } |
| 7 | dd { white-space: pre-wrap; } |
| 8 | </style> |
| 9 | </head><body bgcolor="#FFFFFF"> |
| 10 | |
| 11 | <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b> |
| 12 | Scripting 4.2. Removing objects |
| 13 | </b></font></table></table> |
| 14 | <p>In <a href="Scripting_4_1__Selecting_objects.html">§4.1</a> we saw that objects could be removed by selecting them first and then calling the <b>Remove</b> command. A faster way is the <b>removeObject</b> function, which can also remove unselected objects:</p> |
| 15 | <code> sound = Create Sound as pure tone: “sine377”,<br></code> |
| 16 | <code> ... 1, 0, 1, 44100, 377, 0.2, 0.01, 0.01 ; remember the ID of the Sound<br></code> |
| 17 | <code> Play ; the Sound is selected, so it plays<br></code> |
| 18 | <code> spectrum = To Spectrum: “yes” ; remember the ID of the Spectrum<br></code> |
| 19 | <code> Draw: 0, 5000, 20, 80, “yes” ; the Spectrum is selected, so it is drawn<br></code> |
| 20 | <code> # Remove the created Spectrum and Sound:<br></code> |
| 21 | <code> <b><a href="_removeObject_.html">removeObject</a></b>: sound, spectrum ; remove one selected and one unselected object<br></code> |
| 22 | <p>The <b>removeObject</b> function keeps the objects selected that were selected before (except of course the ones it throws away). This allows you to easily throw away objects as soon as you no longer need them:</p> |
| 23 | <code> sound = Create Sound as pure tone: “sine377”,<br></code> |
| 24 | <code> ... 1, 0, 1, 44100, 377, 0.2, 0.01, 0.01 ; remember the ID of the Sound<br></code> |
| 25 | <code> Play ; the Sound is selected, so it plays<br></code> |
| 26 | <code> spectrum = To Spectrum: “yes”<br></code> |
| 27 | <code> <b><a href="_removeObject_.html">removeObject</a></b>: sound ; we no longer need the Sound, so we remove it<br></code> |
| 28 | <code> Draw: 0, 5000, 20, 80, “yes” ; the Spectrum is still selected, so it is drawn<br></code> |
| 29 | <code> <b><a href="_removeObject_.html">removeObject</a></b>: spectrum ; remove the last object created by the script<br></code> |
| 30 | <h2>Selecting and removing all objects from the list (don’t)</h2> |
| 31 | <p>A very strange command, which you should not normally use, is <code><font size=+1>select all</font></code>:</p> |
| 32 | <code> <b>select all</b><br></code> |
| 33 | <code> Remove<br></code> |
| 34 | <p>This selects all objects in the list and then removes them. Please try not to use this, because it will remove even the objects that your script did not create! After all, you don’t want the users of your script to lose the objects they created! So please try to remove in your script only the objects that your script created, even if the script is for your own use (because if it is a nice script, others will want to use it).</p> |
| 35 | <h3>Links to this page</h3> |
| 36 | <ul> |
| 37 | <li><a href="Scripting.html">Scripting</a> |
| 38 | <li><a href="Scripting_4__Object_selection.html">Scripting 4. Object selection</a> |
| 39 | </ul> |
| 40 | <hr> |
| 41 | <address> |
| 42 | <p>© Paul Boersma 1999,2004,2006–2008,2011,2013,2014</p> |
| 43 | </address> |
| 44 | </body> |
| 45 | </html> |