Working with picture frames in rhinocommon

Is there a way to work with picture frames with rhinocommon? I would like to be able to ask the user to create one from a jpg file and then store this in a variable and then be able to manipulate its position and orientation.

I don’t see a rhinocommon command for inputing a picture frame, so I’m guessing I will have to script this from the command line. But what about the variable that holds the picture frame? I tried just an objRef, but that seems to only hold the surface information, not the picture too.

Any thoughts?

Thanks,
Sam

Use RhinoDoc.Objects.AddPictureFrame.

Hi Dale,

When I use that I get the error:
reference to a non-shared member requires an object reference

I must not be using it properly…

I didn’t see it in the rhinocommon namespace guide, maybe there is a more up to date one? The one I am using is here:
http://4.rhino3d.com/5/rhinocommon/

Thanks,
Sam

I’m sure the online doc set is out-of date. I’ll see if I can get some one to update it.

Here is a simple example you can reference.

https://github.com/dalefugier/SampleCsCommands/blob/master/SampleCsPictureFrame.cs

Hi Dale,

I’m still getting an error for the AddPictureFrame function:
‘AddPictureFrame’ is not a member of ‘Rhino.DocObjects.Tables.ObjectTable’

I do have the latest version of Rhino…

Thanks,
Sam

You are using RhinoDoc.ActiveDoc.Objects.AddPictureFrame or dod.Objects.AddPictureFrame right?

neither of the following work for me:

RhinoDoc.ActiveDoc.Objects.AddPictureFrame()
doc.Objects.AddPictureFrame()

Thanks,
Sam

Are you able to post your code or a part of it?

The code is below. I just seems like my rhinocommon doesn’t have the function AddPictureFrame. I’m noticing that while I have the latest service release, there is a new ‘candidate’ version. Would that help?

Thanks,
Sam

Imports Systems
Imports System.Windows.Forms
Imports Rhino
Imports Rhino.Commands
Imports Rhino.Geometry

<System.Runtime.InteropServices.Guid("1cca23b9-bfef-4897-b2bf-483c254ea3ea")> _
<Rhino.Commands.CommandStyle(Commands.Style.ScriptRunner)> _
Public Class Testing
    Inherits Rhino.Commands.Command

    Private Shared m_thecommand As Testing
    Public Shared ReadOnly Property TheCommand() As Testing
        Get
            Return m_thecommand
        End Get
    End Property

    Public Sub New()
        m_thecommand = Me
    End Sub

    Public Overrides ReadOnly Property EnglishName() As String
        Get
            Return "Testing"
        End Get
    End Property


    Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As Rhino.Commands.RunMode) As Rhino.Commands.Result
        Dim dialog As New OpenFileDialog()
        dialog.Filter = "Image Files|*.bmp;*.gif;*.jpg;*.jpeg;*.pcx;*.png;*.tif;*.tiff"
        Dim rc As DialogResult = dialog.ShowDialog()
        If rc <> DialogResult.OK Then
            Return Result.Cancel
        End If

        Dim filename As String = dialog.FileName

        Dim corners As Point3d()
        Dim res As Result = Rhino.Input.RhinoGet.GetRectangle(corners)
        If res <> Result.Success Then
            Return res
        End If

        Dim p0 As Point3d = corners(0)
        Dim p1 As Point3d = corners(1)
        Dim p3 As Point3d = corners(3)
        Dim plane As Plane = New Rhino.Geometry.Plane(p0, p1, p3)

        Dim width As Double = p0.DistanceTo(p1)
        Dim height As Double = p0.DistanceTo(p3)

        doc.Objects.AddPictureFrame(plane, filename, False, width, height, True, False)
        doc.Views.Redraw()

        Return Result.Success


    End Function
End Class

Hmm. Its working here.

I got this:

Imports System
Imports System.Windows.Forms
Imports Rhino
Imports Rhino.Commands
Imports Rhino.Geometry

Namespace MyProject1

    <System.Runtime.InteropServices.Guid("7a163de1-4bcf-4b06-8b03-5b3654b329e8")> _
    Public Class TestC
        Inherits Command

        Shared _instance As TestC

        Public Sub New()
            ' Rhino only creates one instance of each command class defined in a
            ' plug-in, so it is safe to store a refence in a static field.
            _instance = Me
        End Sub

        '''<summary>The only instance of this command.</summary>
        Public Shared ReadOnly Property Instance() As TestC
            Get
                Return _instance
            End Get
        End Property

        '''<returns>The command name as it appears on the Rhino command line.</returns>
        Public Overrides ReadOnly Property EnglishName() As String
            Get
                Return "Testing"
            End Get
        End Property

        Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As Rhino.Commands.RunMode) As Rhino.Commands.Result
            Dim dialog As New OpenFileDialog()
            dialog.Filter = "Image Files|*.bmp;*.gif;*.jpg;*.jpeg;*.pcx;*.png;*.tif;*.tiff"
            Dim rc As DialogResult = dialog.ShowDialog()
            If rc <> DialogResult.OK Then
                Return Result.Cancel
            End If

            Dim filename As String = dialog.FileName

            Dim corners As Point3d() = Nothing
            Dim res As Result = Rhino.Input.RhinoGet.GetRectangle(corners)
            If res <> Result.Success Then
                Return res
            End If

            Dim p0 As Point3d = corners(0)
            Dim p1 As Point3d = corners(1)
            Dim p3 As Point3d = corners(3)
            Dim plane As Plane = New Rhino.Geometry.Plane(p0, p1, p3)

            Dim width As Double = p0.DistanceTo(p1)
            Dim height As Double = p0.DistanceTo(p3)

            doc.Objects.AddPictureFrame(plane, filename, False, width, height, True, False)
            doc.Views.Redraw()

            Return Result.Success


        End Function

    End Class
End Namespace

Attached is a screenshot of the problem.

Thanks,
Sam

Looks like the function was added on August 7th, which means you will need the SR10 release candidate to test. Sorry for the confusion…

Hi Dale,

I got the new candidate version and it works now.
I need to translate and rotate the picture frame after it has been added to the document, but the function returns a GUID rather than geometry. What is the best way to do this?

Thanks,
Sam

Why after? Its much more efficient to do it before adding to the document.

Here is a sample command that rotates objects. This one is fancy because it show the object rotating dynamically.

https://github.com/dalefugier/SampleCsCommands/blob/master/SampleCsRotate.cs

Perhaps this will help…

The user needs to click on some points on the image to determine how it should be oriented, so I can only orient it after it has been added to the document. Any really quick simple way to do this?

Thanks,
Sam

Whoops, that was a dump question, all I had to do was use a transform on the guid…

One thing I just noticed was that transforms don’t work on point geometries, kind of reminds me of how you can’t do cage edit on points, while many times I have wished I could. Just a thought…

All my questions are answered for this thread, thank you kindly.
Sam