+ Reply to Thread
Results 1 to 5 of 5

Thread: Scripting Text Object

  1. #1

    Scripting Text Object

    Hi there,

    Is there a way to script a text object without resorting to command scripting? I need to use a single-line machine font, and can't seem to specify that with rs.addtext - hence the textObject.

    This seems to work:

    Python Code:
      import rhinoscriptsyntax as rs
       
      point = rs.GetPoint("Pick point")
      rs.Command ("-_TextObject Height=10 Hello Enter", point)

    However, if I change the text ('Hello') to a number (such as 301), it fails:

    Python Code:
      import rhinoscriptsyntax as rs
       
      point = rs.GetPoint("Pick point")
      rs.Command ("-_TextObject Height=10 301 Enter", point)

    I have also tried this, which doesn't work:
    Python Code:
      import rhinoscriptsyntax as rs
       
      point = rs.GetPoint("Pick point")
      textToAdd = str(301)
       
      rs.Command("-_TextObject " + textToAdd + " Enter", point)

    I am sure there is a better way to write this, but unsure of the syntax?

    Thanks for the help,
    Rob

  2. #2
    hey Rob,

    try this

    Python Code:
      import rhinoscriptsyntax as rs
      font_height=10.0; font='Arial'; font_style=0
       
      point = rs.GetPoint("Pick point")
      if point:rs.AddText("my text", point, font_height, font,font_style)
         
       
      #if you want add text on many points
       
      arrPt = rs.GetObjects("Get points", rs.filter.point)
       
      for point in arrPt:
          if point:rs.AddText("my text", rs.PointCoordinates(point), font_height, font,font_style)
    Last edited by Steve Baer; 01-12-2011 at 04:17 PM.

  3. #3
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,464
    Blog Entries
    19
    Hi Rob,
    The first parameter for rs.Command is the entire command string. Your script is passing the point as the 'echo' argument which just resolves to True and tells Rhino to print to the command history window. The following just get TextObject working for you.
    Python Code:
      import rhinoscriptsyntax as rs
       
      point = rs.GetPoint("Pick point")
      cmd = "-_TextObject Height=10 301 "
      cmd += str(point[0]) + "," + str(point[1]) + "," + str(point[2])
      cmd += " Enter"
      rs.Command (cmd)

    Thanks,
    -Steve

  4. #4
    OK - that's how it works. Thanks.
    And thank you Dimitry, but I needed the textObject to use a single-stroke font.

  5. #5
    hello steve
    i need to label a bunch of curves with a single line font, i'm iterating and changing the label for each curve, i haven't been able to apply your solution to my original code (which is part of a much larger script) this is (part of) my original code:

    Code:
    import rhinoscriptsyntax as rs
    
    crvs=rs.GetObjects ("select crvs",4)
    
    for i in crvs:
        centroid = rs.CurveAreaCentroid (i)
        tagTEMP = int(centroid[0][2])
        currentLevelTAG = str(tagTEMP)
        rs.AddText (currentLevelTAG, centroid[0],height=7.0,font="MecSoft_Font-1")

    it outputs fine except for the type of font.

    i tried your solution by doing this:

    Code:
    import rhinoscriptsyntax as rs
    
    crvs=rs.GetObjects ("select crvs",4)
    
    for i in crvs:
        centroid = rs.CurveAreaCentroid (i)
        tagTEMP = int(centroid[0][2])
        currentLevelTAG = str(tagTEMP)
        point = centroid[0]
        cmd = "-_TextObject Height=7 currentLevelTAG "
        cmd += str(point[0]) + "," + str(point[1]) + "," + str(point[2])
        cmd += " Enter"
        rs.Command (cmd)
    the text is added thousands of units away from the centroid of the curves + can't get it to replace the label (i don't use command scripting very often).

    thanks

    diego

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts