rs.Command() within custom python command not working

I’m working on writing some custom python commands for use within Rhino 6 (version 6.2.18065.11031, 3/6/2018) and am running into an issue using the rs.Command().

For example,

import rhinoscriptsyntax as rs
__commandname__ = "Test"`

def RunCommand( is_interactive ):
    rs.Command("_Delete ")
    return 0

This does not delete the selected objects when “Test” is ran from the rhino command line.

If I run the code from the editor using RunCommand(True), it will work correctly.

import rhinoscriptsyntax as rs

__commandname__ = "Test"

def RunCommand( is_interactive ):
    rs.Command("Delete ")
    return 0
RunCommand(True)

Is there a solution to this?

Thanks,
Joe

Hi @joe5,

Can you provide a small sample script file that works inside of the EditPythonScript editor but does not work with the RunPythonScript command? Or is what you’ve posted sufficient?

– Dale

Hi Dale,

To offer a little more explanation, when I create and install the command to rhino using python, the command is failing to execute any rs.Command() line. If I run the code directly as a script, it will work just fine. The code below is sufficient to test it.

import rhinoscriptsyntax as rs

__commandname__ = "test1"

def RunCommand( is_interactive ):
  rs.SelectObject("bb3b227e-5d5a-461d-9196-bbbbc00142a4")
  rs.Command("_Delete")
  return 0

Just using an object ID I have in a test file for the select object. Calling “test1” from the command line will select the object, but it will not delete it. If i were to run the 2 lines

import rhinoscriptsyntax as rs
rs.SelectObject("bb3b227e-5d5a-461d-9196-bbbbc00142a4")
rs.Command("_Delete")

as a script file from the editor, it works fine.


Here is an image of after running test1 as a command. The square is the object ID used in the command, where it successfully gets selected. The delete command is called, as seen in the command history, but it is not executed successfully.

Hope this clears things up.

Joe

Hi @joe5,

Can you review these?

http://developer.rhino3d.com/guides/rhinopython/creating-rhino-commands-using-python/

How to create a new Rhino command using Python

– Dale

Did you figure out a way? I’m running into the same issue.
I guess a work-around question is, how do I script something like rs.Command('_Line') without using the rs.Command()

Either using rs.AddLine() - if you already have 2 points to determine the line, or rs.GetLine() if you need user interactive… See Help for optional arguments on the second.

–Mitch

That did it!
But still wonder if rs.Command() should be made available through custom python command. It’d be much easier to script on-the-flight user interactions for me.