From The Foundry MODO SDK wiki
Jump to: navigation, search

Scripts often need to know which selection mode modo is in. The answer is to use the select.typeFrom command. This command takes a semicolon-delimited list of selection types, comparing the first entry in that list to the others, and if the first entry is the most recently manipulated selection type, then the queried command will return true.

It has been asked why this somewhat involved process is used, and why a script can't simply ask modo for the current selection type. This article attempts to clarify why select.typeFrom exists and how it is used.

On the surface, it appears that modo has a few basic selection types, such as vertices, polygons, edges, items and so on. In actuality, modo has dozens of selection types supported through a generalized selection system, many of which the user doesn't necessarily see in normal use. For example, there are selections in the Form Editor, or Input Editor, the currently selected vertex map, the currently selected viewport, and so on.

In general use, you don't want to know which selection type out of all of the possible selection types is topmost -- you just want to know which of a subset of selection modes is topmost. If your script can operate in vertex, polygon or edge mode, then you really don't care if the topmost selection is a form in the Form Editor. You just want to know which of vertex, polygon or edge is the most current selection type. That's where select.typeFrom comes in.

The syntax of the command is fairly straight forward, but requires some explanation.

select.typeFrom typelist:string ?enable:boolean

The type list argument is a semicolon-delimited list of selection type names. When you query the enable argument, it returns true if the first selection type in the typelist has been manipulated more recently than the other entries in the list.

Let's say you have the selected elements in the following order in modo:

  • an item
  • a vertex
  • an edge
  • a polygon

Since the selection system is first-in-last-out, the selection type stack now looks like the following, with polygon being the topmost (ie: most recently set) selection type.

  • polygon
  • edge
  • vertex
  • item

Next we'll query select.typeFrom with the following arguments.

select.typeFrom edge;polygon;item;vertex ?

The above states that you are want to know if the edge type is the topmost selection type relative to the polygon, item and vertex selection types. Since the polygon type was topmost, the query returns false.

This type list returns a different result.

select.typeFrom edge;item;vertex ?

Here, the typelist argument is set such that the command is checking to see if the edge type is topmost compared to the vertex and item types. Since it is, this query will return true. Even though the polygon type was the most recently manipulated selection type, you are only asking the command to test the edge type against the item and vertex types; compared to those two, edge is indeed topmost.

As such, setting the typelist argument to just one type, like the following, will always return true, since it isn't being compared against anything else, and thus is always topmost compared to nothing at all.

select.typeFrom item ?

The enable argument can be set as well as being queried. This is most often used in the UI, such as when you click the Vertex, Edge and Polygon' buttons at the top of the main window. When set to true, the command selects the first entry in the typelist, and is in fact what happens when you click the button in modo. You can't click the button "off" again, since it doesn't know which selection type should become the new primary. As such, setting the enable argument to false will do nothing. You generally will only query select.typeFrom from scripts, and won't need to directly execute it.

More Information