+ Reply to Thread
Results 1 to 3 of 3

Thread: Insert image with pictureFrame command

  1. #1
    New Member aubergine2001's Avatar
    Join Date
    Nov 2010
    Location
    Halifax, Nova Scotia, Canada
    Posts
    19

    Insert image with pictureFrame command

    I am trying to import an image, usually jpeg or png. I normally use PictureFrame in Rhino. I am not sure about picking the 2 points for the image. I have checked on the forums and have found info to help start. I can get to the point of selecting the image file, but then nothing.
    How do I get to select points for placing image?

    Code:
    import rhinoscriptsyntax as rs
    import System.Drawing as SD
    
    filter = "PNG (*.png)|*.png|JPG (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp|All (*.*)|*.*||"
            
    filename = rs.OpenFileName("Select image file", filter)
    
    img = SD.Bitmap(filename)
        
    # scripted rhino command pictureframe with width and height as calculated above
    rs.Command("!_-PictureFrame "+filename+" ")
    
    img.Dispose()

  2. #2
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,464
    Blog Entries
    19
    You just need to pass two additional points to the Command script

    Python Code:
      import rhinoscriptsyntax as rs
      import System.Drawing as SD
       
      filter = "PNG (*.png)|*.png|JPG (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp|All (*.*)|*.*||"
      filename = rs.OpenFileName("Select image file", filter)
       
      img = SD.Bitmap(filename)
         
      # scripted rhino command pictureframe with width and height as calculated above
      script = '_-PictureFrame "{0}" 0,0,0 {1},0,0'.format(filename, img.Width)
      rs.Command(script)
       
      img.Dispose()

  3. #3
    New Member aubergine2001's Avatar
    Join Date
    Nov 2010
    Location
    Halifax, Nova Scotia, Canada
    Posts
    19
    Thanks Steve, that works perfectly.
    I was wondering if there is a way to pick first point & second point for scaling image when inserting image file.
    If not I have figured out how to do orient 2 pts.
    Code:
    obj = rs.GetObject("Select object to orient")
    if obj:
        reference = rs.GetPoints(message1="First reference point", message2="Second reference point")
        if reference>0:
            target = rs.GetPoints(message1="First target point", message2="Second target point")
            if target>0:
                rs.OrientObject( obj, reference, target, flags=2 )
    thanks again,
    Randy

+ Reply to Thread

Tags for this 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