+ Reply to Thread
Results 1 to 4 of 4

Thread: Access Return Value from Command Line

  1. #1

    Access Return Value from Command Line

    Hi,

    I wanted to write a quick and simple script to get the angle between 2 Surfaces using the rs.command(_Angle)

    I used the TwoObjects options which works fine but it returns a boolean and writes the angle (that I need) only to the command line.
    And I was wondering if I can somehow access that value?
    Or any other suggestions?

    Here is the script and I also attached a file with 2 Surfaces:

    Python Code:
      import rhinoscriptsyntax as rs
       
      while True:
          pt = rs.GetPoint("select point for dot location")
         
          if pt is None:
              #break
         
          #this returns True/False
          angle = rs.Command("_Angle _t")
         
          if angle is False:
              break
         
          #How can I get the angle???
          rs.AddTextDot(angle, pt)
    Attached Files

  2. #2
    Ok here is a little work arround I came up with.
    Works fine for what I needed it.
    But it would be nice to know if there is any other way?

    Thanks!

    Python Code:
      import rhinoscriptsyntax as rs
       
      while True:
          pt = rs.GetPoint("select point for dot location")
         
          if pt is None:
              break
         
          rs.ClearCommandHistory()
         
          #this returns True/False!
          angle = rs.Command("_Angle _t")
         
          if angle is False:
              break
         
          #get current content of command line
          str_cmdLine = rs.CommandHistory()
         
          #slice, convert and round
          angle = round(float(str_cmdLine[-7:-1]), 1)
         
          rs.AddTextDot(angle, pt)

  3. #3
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313
    Hi,

    rs.command does not return the result of the command, it only returns a boolean true/false value if it succeeded or not... if rs.command returns objects, you can access those by running rs.LastCreatedObjects() immediately after the rs.Command. However if it's just a command line value, that won't work. You can parse the command history as you did, but I prefer to use the base rs functions like this:

    python Code:
      import rhinoscriptsyntax as rs
       
      def PlanarSurfaceNormal(srf):
          domU=rs.SurfaceDomain(srf,0)
          domV=rs.SurfaceDomain(srf,1)
          return rs.SurfaceNormal(srf,[domU[0],domV[0]])
       
      srf1=rs.GetObject("Select first surface",rs.filter.surface)
      srf2=rs.GetObject("Select second surface",rs.filter.surface)
       
      if rs.IsSurfacePlanar(srf1) and rs.IsSurfacePlanar(srf2):
          normVec1=PlanarSurfaceNormal(srf1)
          normVec2=PlanarSurfaceNormal(srf2)
          angle=rs.VectorAngle(normVec1,normVec2)
          print "The angle between surfaces is {} degrees".format(angle)
    (I did not do the text dot stuff in the above example, nor did I do any error checking to see if the surfaces were actually picked...)

    IMO, the above is a bit complicated owing to the fact that we do not have a rs.SurfacePlane method for planar surfaces as we do for planar curves, so I had to write my own function.

    --Mitch

  4. #4
    Hi Mitch,

    thanks for your reply and the code!
    Looks much cleaner than my version ;-)

    Best,
    Grischa

+ 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