Scriptcontext这个库的举起的api说明为什么在rhino的开发者页面找不到呢,想要类似rhinocommon的api说明

在rhino编辑中经常能看到scriptcontext的使用,但是鄙人愚笨找不到对应的说明,就很迷惑

scriptcontext模块没有说明,因为它本身也没有多少代码。你可以在安装文件里找到scriptcontext模块的源代码:

# scriptcontext module
import RhinoPython.Host as __host

'''The Active Rhino document (Rhino.RhinoDoc in RhinoCommon) while a script
is executing. This variable is set by Rhino before the exection of every script.
'''
doc = None


'''Identifies how the script is currently executing
1 = running as standard python script
2 = running inside grasshopper component
3... potential other locations where script could be running
'''
id = 1


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

def escape_test( throw_exception=True, reset=False ):
    "Tests to see if the user has pressed the escape key"
    rc = __host.EscapePressed(reset)
    if rc and throw_exception:
        raise Exception('escape key pressed')
    return rc
    

def errorhandler():
    '''
    The default error handler called by functions in the rhinoscript package.
    If you want to have your own predefined function called instead of errorhandler,
    replace the scriptcontext.errorhandler value
    '''
    return None


__executing_command = None
def localize(s):
    import Rhino
    if __executing_command is None:
        return Rhino.UI.LocalizeStringPair(s,s)
    assembly = __executing_command.PlugIn.Assembly
    l = Rhino.UI.Localization.LocalizeString(s, assembly, -1)
    return Rhino.UI.LocalizeStringPair(s,l)

开发者为了方便大家使用,做了一个简单的封装。scriptcontext.doc应该是最常用的功能,这个是对Rhino.RhinoDoc.ActiveDoc内常用方法的封装,你也可以使用Rhino.RhinoDoc.ActiveDoc。

scriptcontext.sticky这个是开发定义了一个字典,我一般都是用开发者定义的这个,你也可以自己定义。

scriptcontext.escape_test做了一个按esc键退出程序的功能,偶尔可能会用到。

别的几个功能,我基本上没咋用到过。

2 个赞

感谢月神,嘿嘿,受教啦