Hello I'm trying to make a 3d mouse for rhino

I’m trying to make a 3d mouse for rhino3d using arduino. Till now i made a plugin that connects with arduino mega. The Serial COM ports and baudrate and other thing is hard coded in the plugin cs file only for this time, the plugin take the serial data from arduino and rotates the active view in the x axis for now i have used a while loop for reading the serial data and have a if conditon for escape key to break the loop, but my problem is that i have to manually type the command name in the command prompt to start the command and then press escape key to end the command. Example : after starting rhino you need to type the command lets say “My3DMouse” in the command prompt and then the view gets rotated and won’t stop until you press escape. But this is not how 3D Connexion’s Space Mouse works , It works directly without typing commands on command prompt.

protected override Result RunCommand(RhinoDoc doc, RunMode mode) {

        m_escape_key_pressed = false;

        RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;

        var currentView = doc.Views.ActiveView;

        Point3d point = new Point3d(0, 0, 0);
        Vector3d vectorx = new Vector3d(1, 0, 0);
        Vector3d vectory = new Vector3d(0, 1, 0);

        double angle = 90;

        double radians = ConvertRadiansToDegree(angle);            

            while (true) {

                //double read = double.Parse(serialPort.ReadLine());


                if (m_escape_key_pressed)


                currentView.ActiveViewport.Rotate(0.10/100, vectorx, point);

                //currentView.ActiveViewport.Rotate(read*2, vectory, point);





        RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;

        return Result.Success;


currently this is the runcommand method for the plugin how could i make it run when lets say the serial data is <= 10 , Example arduino reads a analog sensor in loop and prints an output for now i’m reading that output with serialPort.ReadLine , Arduino prints sensor data from -1024 to 1024 with 0 in neutral or center position. So is it possible to make something that continuously listen to the serialPort and check whether the data is < = 10 or so if yes then run the command , Or any other solution and if not don’t run it also with no typing the command on the command prompt. just like a regular mouse dont need to type RotateView in order to rotate the view we just right click and move the mouse to rotate the view, or like 3DConnexion Space mouse dont need to type the command in order to rotate/translate view, just move the mouse and it works.

The short answer is you need to do event handling.

Yeah but how to make rhino continuously listen for events without manually typing the command. I’m new to rhino dev and still haven’t figured out how this all works. :sweat_smile:

Well, you need to learn that stuff. It’s kind of a big topic, I’m not sure how suitable it is for your first try at programming. There are examples around.

Thats why i need some guidance , I’m not new to programming, I mostly do web and mobile app programming you can check my github : https://github.com/YaseenMallick25 so I can’t figure it out how rhino deals with the command and events and how its all executed.

I guess you will need to write utility plugin whitch loads with Rhino and activate events tracking OnLoad of plugin. This plugin may need some references to now what input is coming and when from your custom device.

I don’t understand this quite well , I added this line in the Plugin.cs file

    public override PlugInLoadTime LoadTime => PlugInLoadTime.AtStartup;

which causes rhino to load this plugin at startup after that it opens COM Port and start reading data and rotate view respectively, and i have an event in the command.cs file

to break out of the loop if escape key is pressed. But this has problems 1st. The command only runs once i.e when the rhino starts and ends when the escape key is pressed. 2nd when the command is running no other command can be executed i.e when the command is running and responding to input data and rotating view i coudn’t use any command lets say Line command for making a line i have to press escape first. I guess i’m totally in the wrong path for making this to work , How about starting low Example : run a command lets say when you press some key "without manually typing the command in the command prompt or hotkey ", I tried to bind this command to hotkey and try to use that and it does not feel good :sweat_smile:

I may be out of concept of what you are trying to do, but I put below link to developer samples which you may find usefull. Take your time

All i just want to make is a cheap diyable 3d mouse for rhino , But Thanks for your kind help.