Simulating the TAB key in a Python script


#1

Is there a way in Python or RhinoCommon to simulate the user pressing the TAB key to lock an alignment? I’m placing a leader and I want it to always point at the center of a hole, sort of the way the dimDiameter command works.

Thanks,

Dan


#2

Hi Dan,

Not that I know of, but you can always get the line formed by where the user clicks and the hole center, and constrain the cursor to the line with GetPointOnLine… Oops, not implemented in Python yet… You’ll need to use RhinoCommon Rhino.Input.Custom.GetPoint and add a line constraint - Constrain(line)… Hmm, a bit painful that…

–Mitch


#3

This is a half-baked attempt… Obviously I don’t know enough about how to set up Rhino.Input.Custom.Get… so as to get more than one leader segment… Really need to learn…

Anyway, FWIW…

–Mitch

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def circ_fltr(rhino_object, geometry, component_index):
    return rs.IsCircle(geometry)

def FakeLeader():
    circ=rs.GetObject("Select circle",4,preselect=True,custom_filter=circ_fltr)
    if not circ: return
    first_pt=rs.GetPointOnCurve(circ,"Pick point on circle")
    if not first_pt: return
    dir_vec=first_pt-rs.CircleCenterPoint(circ)
    const_line=Rhino.Geometry.Line(first_pt,first_pt+dir_vec)

    gp=Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Pick next point on leader")
    gp.DrawLineFromPoint(first_pt,True)
    gp.Constrain(const_line)
    gp.Get()
    next_pt=gp.Point()
    if gp.CommandResult() != Rhino.Commands.Result.Success: return
    leader_line=rs.AddLine(first_pt,next_pt)
    rs.CurveArrows(leader_line,1)
    
FakeLeader()

#4

Thanks Mitch. I’ll take a look at what you have come up with.