4
$\begingroup$

I wonder if it's possible to send commands/data from scripts (ex from Text editor) to Blender Python Console? I've enabled a Math Vis Console: it draws provided Vector/Line/Etc data in 3d viewport and it'd being a great help, however it requires data to be typed in Python Console. So for example if I want to display an ob.location I have to

  • print(ob.location) in my script first
  • then copy string from System Console: <Vector (-1.4095, -0.1780, 1.7132)>
  • reformat it as a 'proper' Vector: Vector((-1.4095, -0.1780, 1.7132))
  • paste this along with a variable name (loc) to Python Console: loc = Vector((-1.4095, -0.1780, 1.7132)):

enter image description here

I wonder if there's a faster way of doing that?

$\endgroup$

2 Answers 2

2
$\begingroup$

You can paste data onto bpy, not sure how advisable it is, but its a technique that works:

In a script:

import bpy

bpy.sergey = (1,2,3)

And then on the console:

>>> bpy.sergey
(1, 2, 3)
$\endgroup$
1
  • $\begingroup$ Woah! This works, thank you! $\endgroup$ Commented Aug 12, 2020 at 19:39
1
$\begingroup$

Not sure about the method above, tried it in 3.6.4 and it gave me no results. What works for me is the code below that writes to the current window console directly.

def get_current_console():
    import console_python
    for window in bpy.context.window_manager.windows:
        for area in window.screen.areas:
            if area.type == 'CONSOLE':
                for region in area.regions:
                    if region.type == 'WINDOW':
                        console = console_python.get_console(hash(region))
                        if console:
                            return console[0]
                            
console = get_current_console()                       
console.locals['location'] = bpy.data.objects['Cube'].location
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .