← All ideas
  • Published 25 Apr 2019

Improvements to Info menu for the use in scripting

The info menu is not really meant for creating script but with improvements like adding selecting and deselecting objects,vertex,bones,etc and adding the ability to switch between modes would greatly improve the ability to simply copy the python code into the text editor in order to create complex scripts instead of having to type out all the code, similar to mel-script in maya.

youtube.com/watch

100%

Development Status: Open

Upvote 2 Downvote 0
EitanSomething
25 Apr 2019

11 Comments

Josephbburg

The problem is that you're comparing Blender's Python API to MEL. They're really different. Blender doesn't have a similar "select" command as in MEL, and selection has a different meaning in Blender... it's based on context and makes a distinction between active selection and other selections. Selection in Blender is a property of the object, relative to the current view-layer. Using Python, you can put yourself in a sticky situation where you have a bunch of stuff selected with no active selection . Of course, this won't happen if you know what you're doing! But if you know what you're doing, you won't take this approach in the first place. I'll explain: Blender draws a distinction between operators and direct data access. Operators are relative to the context and take place in the UI, usually by clicking a button or pressing a hotkey. THIS is what you'll see in the info bar. Direct data access (bpy.data), on the other hand, entails editing the object's properties directly. This is possible in any context and is much faster. It usually won't require updating the scene, either. Managing selection states in a script is stupid, anyways, since the whole point of scripting is making the computer do all the monkey work for you. Instead, give it a test condition, do so-and-so to every x that satisfies condition y.

Anyways, you should know that it's actually very easy to learn and use. Blender's Python API is object-oriented and organized in a really smart way. For example, if you want to query the bones in an armature, you use armatureObject.pose.bones or armatureObject.data.edit_bones. Just about anything you want to iterate through is iteratable. For every x-coordinate in every vertex in every mesh in the selection, do such-and-such, becomes:

for ob in bpy.context.selected_objects: for v in ob.data.vertices #do something

I've got an article on my website that goes into a little more detail: nodespaghetti.xyz/riggy-bits-1/ The article discusses the API and its usefullness to riggers, but it should still be worth reading even if you aren't a rigger.

1
EitanSomething Author

* @Josephbburg * I understand how to create scripts with the python API so I don't need it, but it would be very useful for those moving from another program and don't have the time to learn how to code in python.

You could have the ability to show only operator or operators and direct data access.

Josephbburg

* @EitanSomething * I don't like the idea of the info bar showing something other than what is actually happening. And direct data access is NOT happening when you use the UI operators. I agree that perhaps it could be more verbose, but I think what you're asking is more of a Python tooltip kind of thing.

I also don't like the idea of enabling "don't have time to learn." Don't have time to learn just leads to bad habits and never taking the time to fully learn. That's my opinion.

1
jason

Why not just use the Python Console?

EitanSomething Author

* @Jason van Gumster * The idea is to actually do what you want to happen, and copy the code from the info menu to the text editor so you don't need to know python in order to create simple scripts.

jason

* @EitanSomething * For the most part, that's already possible. It's just working with the assumed context of working on the existing selection. The code can already be copied and pasted in either the text editor or the Python console.

EitanSomething Author

* @Jason van Gumster * The info menu doesn't record selection of objects so you would only be able to create single object script by copying and pasting.

jason

* @EitanSomething * Like I said, because Info reports operations that you run, the assumed context is that it's operating on the existing selection. To add what you're ultimately interested in having, I think it's going to require more deep changes than simply exposing selection events.

EitanSomething Author

* @Jason van Gumster * I understand that this would involve a lot of work. This isn't an addition that I am expecting to be added to 2.80

Josephbburg

* @Jason van Gumster * There actually have been some changes to selection in 2.80 API. Before 2.80, it was a boolean state ( object.select ). Now it's a get/set operation ( object.select_get() ). I think the introduction of view layers has made some other subtleties, too.

In Maya, select is a command that has a bunch of different options, and it runs whenever you click on something. It holds an array of selections and the active selection is just whatever's first in the array (or last, or something, I can't actually find good learning material on MEL). You can write select -r objectName -otherFlags or something along those lines to select in the same way you do in UI.

I don't know if you use Maya or not, but if not, that may help clarify where the OP is coming from.

1
jason

* @Josephbburg * I've used Maya before, but never got heavily into MEL, so your clarification is helpful. Thanks.