Rhino tutorial Calling Python custom scripts with Buttons and Aliases
It is more likely that many of you will already know that Rhinon’s flexibility in customizing its UI is one of its greatest strengths. In fact, through the methods that I will illustrate in the video at the bottom of this page, you will be able to quickly recall, through a button or through an alias (this is my favourite method) a Python script that you have coded specifically to perform any repetitive action that you would otherwise have to perform manually.
In the first case, the first script will allow you to mirror an object through a Median Axis defined by the user – (“Mirror_Between.py”); in the second example instead, I will run a script that will allow you to mirror the object-based on its axis of symmetry (X, Y, Z) – (“Mirror_Symmetrical.py”).
This simple script lets to perform a mirror operation by providing a median axis as input, obtained by selecting two extreme points. The script also applies to a multiple selection of objects.
This simple script lets to perform a mirror operation by selecting one object-symmetry axes (X, Y, Z). The script also applies to a multiple selection of objects.
🧙🏼⌨️ Magic trigger string-code
! _-RunPythonScript (your code) or the "filename"
! _-RunPythonScript ( import rhinoscriptsyntax as rs objs = rs.GetObjects("Select objects to mirror") if objs==None: print("\nMirror Between (custom cmd) failed to run!\n") else: # Give the two between axes points p1 = rs.GetPoint("Start point of the Mirror between axes") p2 = rs.GetPoint("End point of the Mirror between axes") # Mid point mid = rs.PointDivide(rs.PointAdd(p1, p2), 2) rs.UnselectAllObjects() # unselect all objs rs.SelectObjects(objs) # select only objs mirror to MirrorBetween=rs.Command("_Mirror " + str(mid)) )
Rhino Options > Aliases > (fill in the content as described in the video demo)
For aliases in the command macro area, brackets must not be inserted. Very important, in this case, is to insert in quotes exactly the name of the Python file (.py) with your custom code/script.