How to run a python script with options?

For example:
In a macro I can run: “line b”, and i will run the line function with the both sides option, in one step.
But if I have a python script and I execute it using an alias like “myline”, can I have “myline 100” where 100 is a variable used inside the script?

Hi @Bogdan_Chipara,

yes, if your python script is asking for a variable eg. a number, this number can be used as a variable. Below example asks for a length, if you enter it or pass it after your command alias, a vertical line is created at the origin with the entered or passed length:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    '''prompt for a number and create vertical line at origin'''
    
    # prompt for a line length
    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    length = rs.GetReal("LineLength", 10.0, minimum=tolerance)
    if not length: return
    
    # create a line
    p0 = Rhino.Geometry.Point3d(0, 0, 0)
    p1 = Rhino.Geometry.Point3d(0, 0, length)
    line = Rhino.Geometry.Line(p0, p1)
    
    # add to document
    scriptcontext.doc.Objects.AddLine(line)
    scriptcontext.doc.Views.Redraw()
    
if __name__=="__main__":
    DoSomething()

_
c.

1 Like

Great! I understand, thank you!