A guide on how to navigate scriptcontext would be very helpful

anything that uses scriptcontext stands out in that it doesn’t align well with the API docs. I mean you can find what’s what but not very easily. A guide would help. Maybe I can even write one once I have a little more experience.

Hmm, i see a lot of references but not a true guide.

This post seems the most helpful.

Thanks Japhy. I’ve read both these at one point I’ll probably skim them again.

We’re lucky to have a built-in code editor. But as we’d guess, the built-in help also struggles with scriptcontext (it forever says “expanding”).

Anything after “scriptcontext” (or “sc”) in this case ends up not matching the API opposed to other code which very closely matches the api structure. The Object Table for example looks nothing like you’d expect from reading the API docs:

image

https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.tables.objecttable

At this point I’m more or less over this hurdle (I think). But when you first get into using Rhino Common this is another huge thing to overcome.

I’ve been saying that I think it’s a huge loss that more attention isn’t paid to documenting everything better and making it easier for new programmers to create Rhino plugins. Sometimes I almost wonder if they’re working on a new API in secret and that’s why they really don’t bother with all these relatively small and easy things that would help

1 Like

Currently, the best answer to your questions is probably in the source code for the scriptcontext module: rhinoscriptsyntax/Scripts/scriptcontext.py at rhino-8.x · mcneel/rhinoscriptsyntax · GitHub. Most of the variables it defines are documented. We’ve been meaning to write external documentation for a while, eventually it’ll be there:

RH-30040 scriptcontext documentation
DOC-412 Developer docs: Need a “scriptcontext” guide and/or API reference page

In the source code, you will see that there isn’t much in scriptcontext. Here is everything you can access from outside of it:

'''The Active Rhino document (Rhino.RhinoDoc in RhinoCommon) while a script
is executing.'''
doc = None

'''Identifies how the script is currently executing'''
id = 1

'''A dictionary of values that can be reused between execution of scripts'''
sticky = dict()

'''Tests to see if the user has pressed the escape key'''
def escape_test( throw_exception=True, reset=False ):
    pass
    
'''The default error handler called by functions in the rhinoscript package'''
def errorhandler():
    pass

'''Localize a string'''
def localize(s):
    pass

This should all play nicely with RhinoCommon things, including sc.doc.Objects being exactly of type Rhino.DocObjects.Tables.ObjectTable.

sc.doc is a RhinoCommon object of type RhinoDoc, and so behaves exactly like the other RhinoCommon RhinoDoc objects. In particular it has a member called Objects, which is a RhinoCommon ObjectsTable object, and has all the member variables and functions of one, including the AddLine methods.

And I just reported this little bug (which is probably related to the fact that there is no external documentation available for scriptcontext):

RH-91219 ScriptEditor: “scriptcontext” in help panel does not expand

Thanks for reporting these issues!

1 Like

Very helpful! Thank-you.

The autocomplete and the suggestion list ends up being useful too. I just need to study that along with the API docs open at the same time.