Mitch script to scroll back through created objects.
for V5
right mouse click or spacebar to scroll through, esc to stop.
last object selected stays selected.
I wish to make a button for this, for both V5 and V7, what should the code be for the button as I am only knowing about .rvb and .py ?
Thanks. Steve
the code from Mitch is this:-
import rhinoscriptsyntax as rs
import scriptcontext as sc
def ScrollBackInTime():
objs=rs.NormalObjects()
if objs:
for i in range(len(objs)):
rs.UnselectAllObjects()
rs.SelectObject(objs[i])
msg="Object #{} selected.".format(i+1)
check=rs.GetString(msg+" Press enter to continue, Esc to stop")
if sc.escape_test(False):
break
print "Oldest object reached, exiting function"
ScrollBackInTime()
Hi,
so thats a macro, aha. so the code for the button is:-
!_-RunPythonScript (
import rhinoscriptsyntax as rs
import scriptcontext as sc
def ScrollBackInTime():
objs=rs.NormalObjects()
if objs:
for i in range(len(objs)):
rs.UnselectAllObjects()
rs.SelectObject(objs[i])
msg=“Object #{} selected.”.format(i+1)
check=rs.GetString(msg+" Press enter to continue, Esc to stop")
if sc.escape_test(False):
break
print “Oldest object reached, exiting function”
ScrollBackInTime()
)
without your reply I would not have thought to put a run python script as prefix.
I didnt see that as a .py code, as I dont know how to id different code types, learning though. if people help me.
Its easy for coders but I am a raw beginner in code, and brain is not at ease at all, mild panic as if about to walk a tightrope, code is tough for me.
macros pythons scripts plugins .rvb .py .rhp, .txt edit boxes, d and d and so it goes on. is d and d needed before referencing, hope someone tells me, its slow progress getting answers and I was keen to finish v7 build and back up.
so I have now made a button for the code I have here, and I get an error.
!_-RunPythonScript (
import rhinoscriptsyntax as rs
import scriptcontext as sc
def ScrollBackInTime():
objs=rs.NormalObjects()
if objs:
for i in range(len(objs)):
rs.UnselectAllObjects()
rs.SelectObject(objs[i])
msg=“Object #{} selected.”.format(i+1)
check=rs.GetString(msg+" Press enter to continue, Esc to stop")
if sc.escape_test(False):
break
print “Oldest object reached, exiting function”
ScrollBackInTime()
)
so having added the RunPythonScript to the start, which was what the article said to do,.
Line 5 is erroring, and thats within the code.
I don’t know how or where you copied this from, but if it’s like the above, you have lost all the formatting, notably the indentations. Python relies on indentation to work, if your code looks like the above without indentations it will never work.
Hi,
somehow it got like that, going back to the .txt file in folder I kept it in, we have indented.
Learning all the time.
!_-RunPythonScript (
import rhinoscriptsyntax as rs
import scriptcontext as sc
def ScrollBackInTime():
objs=rs.NormalObjects()
if objs:
for i in range(len(objs)):
rs.UnselectAllObjects()
rs.SelectObject(objs[i])
msg=“Object #{} selected.”.format(i+1)
check=rs.GetString(msg+" Press enter to continue, Esc to stop")
if sc.escape_test(False):
break
print “Oldest object reached, exiting function”
ScrollBackInTime()
)
If you want to post python code here that retains its formatting, do the following:
i.e. 3 'backticks` and then the brand of code
paste in the entire code
3 more backticks at the end
Then it will look like this and can be safely copied/pasted.
import rhinoscriptsyntax as rs
import scriptcontext as sc
def ScrollBackInTime():
objs=rs.NormalObjects()
if objs:
for i in range(len(objs)):
rs.UnselectAllObjects()
rs.SelectObject(objs[i])
msg="Object #{} selected.".format(i+1)
check=rs.GetString(msg+" Press enter to continue, Esc to stop")
if sc.escape_test(False):
break
print "Oldest object reached, exiting function"
ScrollBackInTime()
Beware also, posting stuff on Discourse without this code formatting will turn regular quote marks into “curly” quotes, which will also cause scripts to fail if you copy and paste directly - even if you fix the indentations.
Hi thanks,
I reckon thats what happened then I copied it from the forum and pasted to the button, I remember doing that. Not knowing about indenting.
Normally code is indented, never knew fuly why and how many space bar hits are needed per line, of maybe as its typed it knows what to do.
As I said Python code flow is based on indenting - other languages can use other ways - and most code editors offer standard presets for semi-automatic indenting. Tabs or spaces can be used, in this case the Rhino code editor uses the more or less standard 4 spaces (=1 Tab) as an indent increment.