Perhaps it will be helpful to have an “unofficial” list of things/tips, that might help answer some of the “re-occurring” questions that come up on the forum, (in regards to ghpython).
This isn’t intended to be any sort of comprehensive guide, but more of a running list of things that folks might find useful to know when working, (or starting to learn to work), with a ghpython component.
Most of these have come from the generous minds of this forum.
Feel free to post other handy tips/suggestions! (or corrections!)
Be sure to familarize yourself with this secition "What is “ghdoc” and how does it relate to the rhinoscriptsyntax? , in the link above. You can save yourself a bit of “GUID” headache by sticking exclusively with Rhinocommon. With that said…opinions on Rhinocommon vs rhinoscriptsyntax may vary.
You can’t use numpy/scipy. This is an ironpython limitation, not specifically a ghpython limitation
Adding additional component interface options:
It’s probably best to NOT go down the path of trying to add certain types of component interface options, (buttons for example). read more here:
Button and Context Menu discussion
You absolutely can add additional context menu items.
Code Editor tips:
highlight line/s and
tabwill indent multiple lines
highlight line/s and
shift+tabwill unindent highlighted lines
API Documentation, hints, and things to know:
Autocomplete may not always return all the information you may be looking for. Get used to using the RhinoCommon API documentation
the objects that come up in the autocomplete, (intellisense), of an imported module, will have icons that indicate what they are.
= method OR constuctor
Informative introspection methods to use:
print(), type(), help(), dir(), inspect()
import rhinoscriptsyntax as rs import inspect source = inspect.getsource(rs.BoundingBox) print(source)
You can also look directly at what rhinocommon methods are being used in rhinoscriptsyntax: (path to folder is something like this)
C:\Users\YOURUSERNAME\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython Scripting (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript
Edge Case scenarios (these are not terribly common occurrences).
There are few/rare occasions where a rhinocommon method won’t accept a python list. You need to use a structured DotNet Array: (typed array)
(I don’t think this is terribly common…but here is an example).
Example: (component inputs set to G, U, V, PS, F, PE, tol)
RhinoCommon Method - CreatePatch
import System def PatchSrf(self, G, U, V, PS, F, PE, tol): startingSurface = None if tol == None: tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance if PE:# need to create dot net typed array fixEdges = System.Array[bool]([False,False,False,False]) else: fixEdges = System.Array[bool]([True, True, True, True]) Patches = Rhino.Geometry.Brep.CreatePatch(G, startingSurface, U, V, self.Trim, self.Tangency, PS, F, 100, fixEdges, tol) return Patches
If you are in SDK mode, and are returning multiple variables from your runscript, make sure to turn off the output “out” parameter.