Annotate Curve Form 给曲线起始点注释名称

本教程介绍如何使用Python脚本为Rhino中的曲线起点添加可自定义文本注释。通过创建一个对话框,用户可以输入希望显示在曲线起点的文本,并在确认后将文本注释放置于曲线的起点位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

给曲线起始点注释名称。运行后产生对话框,输入名称如chant(默认start),回车后,曲线起点得到注释,如下图。
这里写图片描述
这里写图片描述

# with a textbox that can be used to define the text in a new text dot
from System.Windows.Forms import Form, DialogResult, Label, Button, TextBox
from System.Drawing import Point, Size
import rhinoscript.selection
import rhinoscript.geometry

# Our custom form class
class AnnotateForm(Form):
  # build all of the controls in the constructor
  def __init__(self, curveId):
    offset = 10
    self.Text = "Annotate Curve"
    crvlabel = Label(Text="Curve ID = "+str(curveId), AutoSize=True)
    self.Controls.Add(crvlabel)
    width = crvlabel.Right
    pt = Point(crvlabel.Left,crvlabel.Bottom + offset)
    labelstart = Label(Text="Text at start", AutoSize=True)
    labelstart.Location = pt
    self.Controls.Add(labelstart)
    pt.X = labelstart.Right + offset
    inputstart = TextBox(Text="Start")
    inputstart.Location = pt
    self.Controls.Add(inputstart)
    if( inputstart.Right > width ):
      width = inputstart.Right
    self.m_inputstart = inputstart

    pt.X  = labelstart.Left
    pt.Y  = labelstart.Bottom + offset*3
    buttonApply = Button(Text="Apply", DialogResult=DialogResult.OK)
    buttonApply.Location = pt
    self.Controls.Add(buttonApply)
    pt.X = buttonApply.Right + offset
    buttonCancel = Button(Text="Cancel", DialogResult=DialogResult.Cancel)
    buttonCancel.Location = pt
    self.Controls.Add(buttonCancel)
    if( buttonCancel.Right > width ):
      width = buttonCancel.Right
    self.ClientSize = Size(width, buttonCancel.Bottom)
    self.AcceptButton = buttonApply
    self.CancelButton = buttonCancel

  def TextAtStart(self):
    return self.m_inputstart.Text


# prompt the user to select a curve
curveId = rhinoscript.selection.GetObject("Select a curve",rhinoscript.selection.filter.curve)
if( curveId==None ):
  print "no curve selected"
else:
  location = rhinoscript.curve.CurveStartPoint(curveId)
  if( location!=None ):
    form = AnnotateForm(curveId)
    if( form.ShowDialog() == DialogResult.OK ):
      # this block of script is run if the user pressed the apply button
      text = form.TextAtStart()
      if( len(text) > 0 ):
        #create a new text dot at the start of the curve
        rhinoscript.geometry.AddTextDot(text, location)

Note: This only works on the Windows version of Rhino.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值