SampleNewFloatingViewport problem, C++

Hi,

I would really appreciate your help on this.

(https://github.com/mcneel/Rhino5Samples_CPP/blob/22c79aab84540439c0b78f1c2a146fdce75f467d/SampleCommands/cmdSampleNewFloatingViewport.cpp)

I got the SampleNewFloatingViewport implemented in my comand, in my C++ plugin. When I launch the comand, sometimes the ending result isn’t correct, and I end up with a Viewport newly created, but that wasn’t renamed properly.

The only thing that I changed was saving the currentContext.m_doc in a CRhinoDoc* pointer, called currentDoc, and removing the view->FloatRhinoView(true), because I don’t need it:

CRhinoView* RhinoViewsManager::createNewView(ON_wString viewName)
{
    ON_SimpleArray<ON_UUID> viewport_ids;
    ON_SimpleArray<CRhinoView*> view_list;
    CRhinoView* view = 0;
    int i = 0;

    // Build a list of (current) viewport ids
    currentDoc->GetViewList( view_list, true, false );
    for( i = 0; i < view_list.Count(); i++ )
    {
        CRhinoView* view = view_list[i];
        if( view )
            viewport_ids.Append( view->ActiveViewportID() );
    }
    view_list.Empty();

    // Create a new view
    currentDoc->NewView( ON_3dmView() );

    // Find the viewport (id) that was just created
    currentDoc->GetViewList( view_list, true, false );
    for(int i = 0; i < view_list.Count(); i++ )
    {
        view = view_list[i];
        if( view )
        {
            int rc = viewport_ids.Search( view->ActiveViewportID() );
            if( rc < 0 )
                break;
            else
                view = 0;
        }
    }

    // Make the necessary updates.
    if( view )
    {
        ON_3dmView v = view->ActiveViewport().View();
        v.m_name = (viewName);
        view->ActiveViewport().SetView( v );
        view->Redraw();
    }

    return view;
}

As I said, sometimes the program doesn’t update the view name, probably because it doesn’t enter in the “if(view)” block. Is that possible?

Plus, another question, is it permissible to save the currentContext.m_doc pointer as I did, or it is a thing that absolutely must not be done? (because it changes too much?)

Thank you for your help

If you are just trying to create a new, non-floating viewport, you can always just script the NewViewport command. Here is how you can run a command from a plug-in command:

Ok, thank you for the help!