Change View command

Hi All,

I’ve made custom commands to change the cameraposition but these arent able to interrupt other commands such as setting a dimension for example.

Steps in what I try to achieve:

1 Start dimension command.
2 click on cplane for first point.
3 change view (This doesnt work).
4 click on cplanefor second point.

I dont have a clue about what to modify to achieve this. Below the code for changing the view.

Hopefully you can help me.

BoundingBox bB = new BoundingBox();
                if (RhinoDoc.ActiveDoc.Objects.Count > 0)
                {
                    foreach (RhinoObject ro in RhinoDoc.ActiveDoc.Objects)
                    {
                        bB.Union(ro.Geometry.GetBoundingBox(false));
                    }
                }

                Rhino.Display.RhinoViewport viewport = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport;

                
                viewport.SetCameraDirection((cameraViewDirection), false);
                viewport.ZoomBoundingBox(bB);
                
                viewport.CameraUp = cameraParallelToScreenUpDirection;
                viewport.Name = name;

                ConstructionPlane constructionPlane = new ConstructionPlane();
                constructionPlane.Plane = cPlane;
                viewport.PushConstructionPlane(constructionPlane);

                RhinoDoc.ActiveDoc.Views.RedrawEnabled = true;
                RhinoDoc.ActiveDoc.Views.ActiveView.Redraw();

Normally running a script is not possible inside a running Rhino command without canceling the command in progress… someone correct me if I’m wrong.

I think unfortunately this is still the case for Python scripts, which is quite limiting, like in the case above. It works fine with RhinoScript (running them inside commands).
It’s been discussed before:

And wish is on the pile:
https://mcneel.myjetbrains.com/youtrack/issue/RH-56354

I would hope that now when Python is dominant Rhino scripting language this can be finally implemented…
Not sure who to bug about this but this problem is stopping me from translating bunch of my old RhinoScripts to Python since they would not work within other commands, and especially those that deal with view or display changes would be useless anyway.
@stevebaer ?

Best,

–jarek

1 Like

I didn’t try this yet but perhaps if you compile your Python script into a plugin command, it may be able to interrupt other commands…

OK, it’s been so long since I used RhinoScript, I didn’t know that. Yep, hopefully that can be addressed, would open up a lot of possibilities.

I don’t know if this is on point or not:

The discussion seems to be about calling commands/scripts from other commands/scripts, but the actual example looks like it might just be calling RhinoCommon from a python script.

Step 3, “change view”, is said not to be working. The code example seems to be somewhat incomplete, but I noticed:

RhinoDoc.ActiveDoc.Views.RedrawEnabled = true;
                RhinoDoc.ActiveDoc.Views.ActiveView.Redraw();

Even from within a plugin, if I’m running a loop such as over rhino objects and need the display to update in between inputs from the command line, I also need to execute

Rhino.RhinoApp.Wait()
which lets background tasks and repaints actually happen.

My current use was causing object selection (RhinoObject.Select(true) ) to actually take effect.

My example:

           foreach (RhinoObject ro in doc.Objects)
           {
               doc.Objects.UnselectAll();
               Rhino.Input.Custom.GetString gs2 = new Rhino.Input.Custom.GetString();
               gs2.SetCommandPrompt("Specify partial path");
               gs2.GetLiteralString();
               ro.Select(true);
                              
               doc.Views.ActiveView.Redraw();
               Rhino.RhinoApp.Wait();
               //here's where I do the stuff I needed the refresh to happen for
           }
 

This looks weird because it’s automated test code and I pulled some things out to explore this question.

(note: this can cause some Rhino events to fire in the background such as for object selection, which other plugins may be hooked into. In my case this is the desired behavior.)

Hi @r.weenink,

Your command code is incomplete. Can you post the entire command class?

Thanks,

– Dale

Hi all,
I’m sorry for the incomplete code. I’ve programmed this in c#.

Maybe I’ve chosen the wrong solution direction. The reason I started programming the view changecamera method is that I rather not work with stored views in a template.
Because of a legacy the changed camera positions are neseccary.

The command start with:

namespace PLTModellingPlugin.Commands
{
    public class PLTInsoleCameraTop : Command
    {
        public PLTInsoleCameraTop()
        {
            Instance = this;
        }

        ///<summary>The only instance of the MyCommand command.</summary>
        public static PLTInsoleCameraTop Instance { get; private set; }

        public override string EnglishName => "PLTInsoleCameraTop";

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            
            InsoleCameraControl.SetUpCamera(Vector3d.ZAxis * -1, Vector3d.YAxis, Plane.WorldXY, "PLTInsoleCameraTop");
            return Result.Success;
        }
    }
}
It calls the Setupcamera method:

public static void SetUpCamera(Vector3d cameraViewDirection, Vector3d cameraParallelToScreenUpDirection, Plane cPlane, string name)
        {
            try
            {                
                BoundingBox bB = new BoundingBox();
                if (RhinoDoc.ActiveDoc.Objects.Count > 0)
                {
                    foreach (RhinoObject ro in RhinoDoc.ActiveDoc.Objects)
                    {
                        bB.Union(ro.Geometry.GetBoundingBox(false));
                    }
                }

                Rhino.Display.RhinoViewport viewport = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport;

                
                viewport.SetCameraDirection((cameraViewDirection), false);
                viewport.ZoomBoundingBox(bB);
                
                viewport.CameraUp = cameraParallelToScreenUpDirection;
                viewport.Name = name;

                ConstructionPlane constructionPlane = new ConstructionPlane();
                constructionPlane.Plane = cPlane;
                viewport.PushConstructionPlane(constructionPlane);

                RhinoDoc.ActiveDoc.Views.RedrawEnabled = true;
                RhinoDoc.ActiveDoc.Views.ActiveView.Redraw();
            }
            catch (Exception)
            {
                RhinoApp.WriteLine("Something went wrong while setting up camera!");
            }            
        }

Hi @r.weenink,

In order for a Rhino command to run inside of other commands, it must be tagged with the Transparent command style. You do this by adding the following attribute to your command class.

[CommandStyle(Style.Transparent)]

In the case of your command, that would look like this:

[CommandStyle(Style.Transparent)]
public class PLTInsoleCameraTop : Command
{
  ...
}

To run the command inside of another command, the Dim command for example, just precede the command name with a single-quote character.

'_PLTInsoleCameraTop

I’ve modified your command a little, although I’m not exactly sure what all you are trying to do with it.

PLTInsoleCameraTop.cs (978 Bytes)

Let me know if you have any questions.

– Dale

HI Dale,

Thanks for the solution!

Works perfect.

Regards Reinder