`scriptcontext` not working in VSCode

Hi All,

Is there a way to get scriptcontext working in VSCode? At the moment I get the No module named 'scriptcontext' error.

Cheers

Hi @Gerrard_Hickson, have you seen my answer here ?

_
c.

Hi @Gerrard_Hickson, i cannot say anything about CreateHeadless as i tested only with a
regular rhino document. Does your script run from one of the build in python editors or using
RunPythonScript ?

Maybe you should first try to solve the problem with scriptcontext ? Both script editors import > module search paths before running scripts. It could be that this is the reason you’re not able > to access the modules in VS which are imported using:

import scriptcontext

You might try this:

1.Open _EditPythonScript (the old IronPython script editor)
2.Go to Tools > Options > Files > Module Search Paths
3.Note the paths listed in the dialog

In my case, the scriptcontext module is located here:

C:\Users\Clement\AppData\Roaming\McNeel\Rhinoceros\8.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib

Can you try to append that path on top of your script using:

import sys
sys.path.append(the_path)

and access scriptcontext without getting an error ?

Thanks for the reply in the other thread.

at step 3 - there are no paths listed on my system.

There is a scriptcontext.py located in my equivalent of the path you suggested. I’ve added that with Import sys as you suggest, but it ends up in a new error in file rhinocompat.py - No module named 'RhinoCodePlatform'

You cannot directly use Rhino libraries outside of Rhino. You’ll have to use Rhino Inside Python (and have a valid Rhino license). You will not be able to create a standalone script that uses Rhino geometry kernel. This is why Dale asks about Rhino Inside Python in his reply AddPageView has no effect - #13 by dale

At most you can use the Python module rhino3dm to create files with Python in a standalone script. This module allows you to read and write 3dm files. But you don’t have access to the geometry kernel, nor any of the plug-in functionality (like pdf import/export).

Here Python examples of standalone scripts using rhino3dm that you can do from VSCode: rhino-developer-samples/rhino3dm/py at 8 · mcneel/rhino-developer-samples · GitHub . You will find that you can create a document, add geometry, but not do for instance boolean operation through rhino3dm, or use functionality that is provided by plug-ins (see the Tools > Options > Plug-ins list in Rhino).

Hi Nathan,

Thanks for the explanation. I understood some of the geometry limitations, but I didn’t realise this method prevented access to plug-ins as well. That’s a problem.

In my case, the script needs to generate a Rhino file with content (I have most of this under control), then export DXF and PDF files of the output.

Presumably, I can’t launch another Rhino script externally - I imagine this would rely on a plug-in of some kind.

In that case, I need an internal script to handle the file export functionality, in which case I may as well move everything internally. Are there limitations on using the internal scripting options? e.g. can I access external python libraries, call other python functions from internal scripts?

Thanks and Regards

As far as I know you should be able to run other external scripts through Rhino Inside Python, assuming they don’t use any GUI. This you can do by scripting the RunPythonScript command through RhinoApp.RunScript Method (String, Boolean) .

In regular Rhino 8 you are able to import external modules (search the forum for how to import for instance numpy in Rhino 8 using the # r: numpy directive), and you can create your own modules to organize your code.

1 Like