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!)
Must Read links:
1 - Rhino - Rhino.Python Guides
2 - Rhino - An Overview of the GhPython Editor
3 - Rhino - GhPython Common Questions and AnswersBe 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.
Limitations:
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 discussionYou absolutely can add additional context menu items.
Code Editor tips:
highlight line/s andtab
will indent multiple lines
highlight line/s andshift+tab
will 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
https://developer.rhino3d.com/api/RhinoCommon/html/R_Project_RhinoCommon.htm#!the objects that come up in the autocomplete, (intellisense), of an imported module, will have icons that indicate what they are.
= property
= method OR constuctorInformative introspection methods to use:
print(), type(), help(), dir(), inspect()
example: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).
Scenario 1:
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)
http://www.ironpython.info/index.php?title=Typed_Arrays_in_IronPython
(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 - CreatePatchimport 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
Scenario 2:
RhinoCommon method overloads.
use StrongBox in ghpython.
Discussion 1
Discussion 2
Discussion 3
Random tips:
If you are in SDK mode, and are returning multiple variables from your runscript, make sure to turn off the output “out” parameter.