Preparing to script control Rhino objects in Grasshopper / Python

Introduction

When using GhPython, a plugin that can handle Python with Grasshopper, for example, commands such as GetObject () that can be used with rhinoscripts cannot be used. This is because when using a Rhino script on Rhino, the object on Rhino is handled, while when using a Rhino script on Grasshopper, the virtual object used by Grasshopper is handled. Then what do you do?

Specify the position of Document

In order to be able to handle objects on the rhino, write the following in the python script.

sample.py


import scriptcontex as sc

sc.doc = Rhino.RhinoDoc.ActiveDoc

This way, if you use a rhino script in this script, you will be able to work with objects that are located in rhino space instead of grasshopper virtual objects.

If you want to undo

sample.py


import scriptcontext as sc

sc.doc = ghdoc

Which Document to choose in what situation

sc.doc = Rhino.RhinoDoc.ActiveDoc

Is used in the following situations.

Also,

sc.doc = ghdoc

Is used in the following situations.

For more details

You can get more detailed and correct information by looking here. A must-see for anyone who wants to use Python scripts with Grasshopper.

TIPS | SCRIPT CONTEXT IN GH PYTHON

Recommended Posts

Preparing to script control Rhino objects in Grasshopper / Python
6 ways to string objects in Python
Pin current directory to script directory in Python
Sample script to trap signals in Python
A memorandum to run a python script in a bat file
To flush stdout in Python
Login to website in Python
Speech to speech in python [text to speech]
How to develop in Python
Post to Slack in Python
Script to count and stop up to 5 seconds in Python in Blender
Assigned scaffolding macro in Python script file to F12 key
[Python] How to do PCA in Python
How to pass arguments to a Python script in SPSS Modeler Batch
Convert markdown to PDF in Python
How to collect images in Python
How to use SQLite in Python
Get the script path in Python
Assignments and changes in Python objects
[python] Copy script to generate copy log
Try to calculate Trace in Python
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
I wrote a script to extract a web page link in Python
How to use PubChem in Python
Examine the object's class in python
Articles to read when Blender Python script code doesn't work in 2.80
How to handle Japanese in Python
An alternative to `pause` in Python
Python script written in PyTorch is converted to exe with PyInstaller
I made a script in python to convert .md files to Scrapbox format
[Cloudian # 5] Try to list the objects stored in the bucket with Python (boto3)
[Introduction to Python] How to use class in Python?
Exclusive control with lock file in Python
Install Pyaudio to play wave in python
How to access environment variables in Python
I tried to implement permutation in Python
Method to build Python environment in Xcode 6
How to dynamically define variables in Python
How to do R chartr () in Python
[Itertools.permutations] How to put permutations in Python
PUT gzip directly to S3 in Python
Send email to multiple recipients in Python (Python 3)
Convert psd file to png in Python
I tried to implement PLSA in Python 2
To set default encoding to utf-8 in python
How to work with BigQuery in Python
Log in to Slack using requests in Python
Run the Python interpreter in a script
How to get a stacktrace in python
How to display multiplication table in python
Easy way to use Wikipedia in Python
How to check opencv version in python
I tried to implement ADALINE in Python
[Python] Pandas to fully understand in 10 minutes
Throw Incoming Webhooks to Mattermost in Python
Module to generate word N-gram in Python
To reference environment variables in Python in Blender
I wanted to solve ABC159 in Python
I tried to implement PPO in Python