What coding up front for a button using txt script and not .rvb or .py?

Hi,
V7

Hi, whilst I can see where to place the -_Runscript ( code for .rvb and _-RunPythonScript for .py codes, I have this code which was as a .txt file and don’t know where such goes.
The wording:-
import rhinoscriptsyntax as rs
import scriptcontext as sc
…I don’t know if that’s coding or not.

It is from:-
Mitch script to scroll back through created objects.
for V5
(is it ok V7, how do I establish such ?)

right mouse click or spacebar to scroll through, esc to stop.
last object selected stays selected.

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()

What would button coding be for this ?

Cheers Steve

Two ways:

-_RunPythonScript (
#code goes here
)

Better way I find is to save your scripts in one location and add a reference to it:

-_RunPythonScript "c:\script_directory\your_pythonscript.py"

Hi, I am feeling like a shuttlecock.

For all of these reasons, I recommend manual installation of scripts as outlined on this wiki page:
https://wiki.mcneel.com/rhino/macroscriptsetup
an entire thread saying dont save on a drive, if it gets moved etc, .

So I have elected to follow such advice and add scripts into buttons.

Your first suggestion is add codes to buttons, just drop entire code in,

but your example plucked out the rhino stuff in red.
and put in extra coding, so just plonking code in would be different to that.

so this is saying do make a button, then dont make a button, and if do, then just paste code in, but what of this Cal Main() and SubMain()

someone said there are some additions needed to make a code run in a button, these were shown, and now they are not needed.

I am totally perplexed now.

script added and deleted Notcher

If I am hopeless on knowing what code bits to add in and what to delete, perhaps I should just reference then instead, bound to work then !
…and I thought I was doing good by following advice to not do so.
:cry:
@Helvetosaur

Is that .txt file a .py ?

as prefixing code with a .py starter suggests it is.

Steve

The link you post shows two ways: add the script totally in the button, or reference it, it can’t be made any clearer than that. If you have trouble reading code, then I think it is best not to mess with it, and use

-_RunScript "c:\script_directory\yourscript.rvb"

or

The link you post shows two ways: add the script totally in the button, or reference it, it can’t be made any clearer than that.

yes and I opted for the button route, as it was highly suggested as best practice.

Ok, as I am new to code, I will reference it. but cannot , see below. the VERY WORRIED bit.

If I drag drop an .rvb to V7, where does it then live ?
If I drag drop a .py to rhino, where does it then live ?

I am building a win10 PC, if I have need to reinstall C drive from acronis backup, if codes live on D drive, then they wont get harmed, should I move the folder they live in to D using copy paste ?

and reference them on the D drive address ?

Then when I do another drag and drop will it know to go to D drive ?

VERY WORRIED ON GOING AGAINST THIS :-
and helvetosaur said his codes I have were not intended for d and d,
so I am even more confused.
@Helvetosaur

if not for d and d then what ?

absolutely confused now.

Steve

it’s just an example. You can put them anywhere

-_RunScript "d:\some_other_directory\yourscript.rvb"

then I say: don’t

then I say: don’t

Hi, hang on, being told to drag drop, then now being told not to drag drop,.

aaaaaaagh !

please clarify as this is getting very confusing indeed.
@Helvetosaur
helvetosaurs are not D and D, to reference these .rvb and .py you say drag and drop, then say not to drag and drop.

please this is changing per line,.

I just want to finish the V7 build and back up PC.

Q1. IF I KEEP THEM ON D DRIVE, WHEN I DRAG DROP TO V7 HOW WILL IT KNOW WHERE TO FIND THEM DO I THEN CUT THEM FROM A C DRIVE LOCATION AND PASTE TO D DRIVE ?

Q2.WHAT IS LOCATION OF THE C DRIVE DAND D FILES ?

Q3. WHAT OF HELVETOSAURS NON D AND D ONES, WHAT TO DO WITH THOSE ?

Q4. I DONT WANT TO MESS UP STABILITY OF V7, I AM TRYING TO INSTALL IT, MAKE CHANGES TO PROPERTIIES AS PER V5 LIKES, AND ACRONIS IT AS A STABLE WORKING NOT GLITCHED UP WITH V5 CODES THAT DONT WORK SO WELL,
HOW DO I KNOW THESE .RVB AND .PY CODES ARE OK FOR V7 ?

been on V7 an entire week setting it up now…

Steve

I cannot browse this entire forum and look for what others have said, so let’s keep it simple. Try this:

Take one of your existing .py scripts, and place that in a location of choice, then make a button and put in what I suggested:

-_RunPythonScript "d:\script_directory\your_pythonscript.py"

and then post back if it works.

also: if you have a rvb script that doesn’t work this way (when it is made for drag and drop) it will contain something like what I posted a few days back:

Option Explicit

Rhino.AddStartupScript Rhino.LastLoadedScriptFile()
Rhino.AddAlias "MyAlias", "_NoEcho _-Runscript (FunctionName)"

Call FunctionName()
Sub FunctionName()
  'all the script stuff
End Sub

in that case edit the script and take out the two lines

Rhino.AddStartupScript Rhino.LastLoadedScriptFile()
Rhino.AddAlias "MyAlias", "_NoEcho _-Runscript (FunctionName)"

and keep Option Explicit and everything from Call …

Hi,
I need to know.

Q2.WHAT IS LOCATION OF THE C DRIVE D AND D FILES ?

Q3. WHAT OF HELVETOSAURS NON D AND D ONES, WHAT TO DO WITH THOSE ?

I have been without D drive fr 9 months, so Helvetosaurs advice on when such happens messing things up is true, thats why I am trying to get my head around this coding, and make sure rhino runs even if a drive is acting up.

I have to place the appropriate code at start, either -_RunPythonScript for .py or -_RunScript for .rvb just before Option Explicit and remove some rhino stuff, if not a drag n drop code and add in the
code in green, how difficult could that be.
script added and deleted Notcher

is that example correctly done ?

and if using buttons with code within, thats taking care of Helvetosaurs scripts I have that are not for D and D.
I would like to at least try, be told where my code is wrong, learn something.

Steve

They stay where you D&D’d them from, so if you downloaded them to c:\yourfiles\script.rvb, and you D&D them on Rhino, when you delete it from that location in will no longer work.

Again, try what I suggest and be amazed.

no it isn’t, if you want to paste code in a button, you’ll need to take out the lines I indicated above, pls carefully read my previous post.

Hi,
I think I did and cant see what I missed.

I have the scripts in a folder on a usb removable hard drive, has all the progs needed for my win10 build. as its remoavble thats all that time wasted. if within the button all is good, Helvetosuar is right.
@Helvetosaur

I just need to know exactly what the start of the scripts should look like, as the only other thing to do is the ) at the end.

Could I be shown what I missed ? that way I can learn.

a whole day spent getting nowhere.

Steve

in case of the Notcher script, I quickly looked that up by searching the forum, the start of it looks like this:

Option Explicit
'Script written by Pascal
' RMA
'Script version Wednesday, May 01, 2013

'Rhino.AddStartUpScript Rhino.LastLoadedScriptFile
'Rhino.AddAlias "Notcher", "_NoEcho _-Runscript (Notcher)"

'Cuts two intersecting panels with notches for assembly. No clearance.


Private oldClear
	
If isEmpty(oldClear) Then
	oldClear = 0.0
	
End If
Call Notcher()
Sub Notcher()
	
'rest of the script continues here

that script is a non D&D because it has the lines I indicated commented out. So if you would paste that into a button, it should work (with

 -_Runscript (
'all the script goes in here
)

And for D&D with the lines uncommented:

Option Explicit
'Script written by Pascal
' RMA
'Script version Wednesday, May 01, 2013

Rhino.AddStartUpScript Rhino.LastLoadedScriptFile
Rhino.AddAlias "Notcher", "_NoEcho _-Runscript (Notcher)"

'Cuts two intersecting panels with notches for assembly. No clearance.


Private oldClear
	
If isEmpty(oldClear) Then
	oldClear = 0.0
	
End If
Call Notcher()
Sub Notcher()
'script continues here

any clearer now?

Hi
I paste here the code from my download of that Notcher at the time, and I never even touched it, it differs from the code you found. I added the prefix and got that correct

-_Runscript (

Option Explicit

'Script written by Pascal

’ RMA

'Script version Wednesday, May 01, 2013

‘Call Main()

‘Sub Main()

'Call Notcher()

Private OldClear

If isEmpty(oldClear) Then

oldClear = 0

End If

Sub Notcher()

Dim P1, P2

My code as taken at the time has no Call Notcher() after End If.
it also has 0 and not 0.0 if such makes a diffference but absence of Call Notcher might !

Meanwhile
Pascal has spotted that it doesnt support the Private Statement and is investigating.

Steve