TylerGubala/blenderpy

Blender Debugging Environment setup issue: Blender paused itself but nothing happened in the Eclipse PyDev server

YuzhouGuo opened this issue · 2 comments

The Bug

I followed the https://wiki.blender.org/wiki/Tools/Debugging/Python_Eclipse post and set up the PyDev package in Eclipse successfully. I pasted the exact same code from the post before my own code and started the PyDev debug server before running the Blender script as well.

The Blender did pause and disabled input (the cursor became a loading icon in this case). However, when I switch to Eclipse manually, nothing really happened. I didn't see my python file opened anywhere, nothing highlighted or anything else.

Thank you, any help will be much appreciated!

Expected behaviour

According to the Blender Debugging post, we should expect something like this:

Run the script in Blender - at this point Blender will hang (stop responding to input).
Switch to Eclipse.
The file you are debugging should be open, with the line it has stopped at highlighted

What I installed and used

  • Python 3.7
  • future-fstrings 1.2.0
  • pip 21.0.1
  • setuptools 40.8.0
  • six 1.6.0
  • PyDev package
  • Launched Blender from Eclipse (installed Blender as external)
  • OS: MacOS 10.15.6

My Python Script from Blender

PYDEV_SOURCE_DIR = "/Users/yuzhouguo/eclipse/java-202103/Eclipse.app/Contents/Eclipse/dropins/plugins/org.python.pydev.core_8.2.0.202102211157/pysrc"

import sys

if PYDEV_SOURCE_DIR not in sys.path:
   sys.path.append(PYDEV_SOURCE_DIR)

import pydevd
pydeved.settrace()

import os
import os.path
import bpy
import bmesh
import datetime
from math import sqrt, radians, pi, cos, sin
from mathutils import Vector, Matrix
from random import random, seed, uniform, randint, randrange
from enum import IntEnum
from colorsys import hls_to_rgb

def get_face_matrix(face, pos=None):
    x_axis = (face.verts[1].co - face.verts[0].co).normalized()
    z_axis = -face.normal
    y_axis = z_axis.cross(x_axis)
    if not pos:
        pos = face.calc_center_bounds()

    mat = Matrix()
    mat[0][0] = x_axis.x
    mat[1][0] = x_axis.y
    mat[2][0] = x_axis.z
    mat[3][0] = 0
    mat[0][1] = y_axis.x
    mat[1][1] = y_axis.y
    mat[2][1] = y_axis.z
    mat[3][1] = 0
    mat[0][2] = z_axis.x
    mat[1][2] = z_axis.y
    mat[2][2] = z_axis.z
    mat[3][2] = 0
    mat[0][3] = pos.x
    mat[1][3] = pos.y
    mat[2][3] = pos.z
    mat[3][3] = 1
    return mat

def scale_face(bm, face, scale_x, scale_y, scale_z):
    face_space = get_face_matrix(face)
    face_space.invert()
    bmesh.ops.scale(bm,
                    vec=Vector((scale_x, scale_y, scale_z)),
                    space=face_space,
                    verts=face.verts)
                    
def extrude_face(bm, face, translate_forwards=0.0, extruded_face_list=None):
    new_faces = bmesh.ops.extrude_discrete_faces(bm, faces=[face])['faces']
    if extruded_face_list != None:
        extruded_face_list += new_faces[:]
    new_face = new_faces[0]
    bmesh.ops.translate(bm,
                        vec=new_face.normal * translate_forwards,
                        verts=new_face.verts)
    return new_face

bm = bmesh.new()
bmesh.ops.create_cube(bm, size=2)
scale_vector = Vector(
        (uniform(0.75, 2.0), uniform(0.75, 2.0), uniform(0.75, 2.0)))
bmesh.ops.scale(bm, vec=scale_vector, verts=bm.verts)

for face in bm.faces[:]:
    if abs(face.normal.x) > 0.5:
        hull_segment_length = uniform(0.3, 1)
        num_hull_segments = randrange(3, 6)
        hull_segment_range = range(num_hull_segments)
        for i in hull_segment_range:
            is_last_hull_segment = i == hull_segment_range[-1]
            val = random()
            if val > 0.1:
                face = extrude_face(bm, face, hull_segment_length)
                if random() > 0.75:
                    face = extrude_face(
                        bm, face, hull_segment_length * 0.25)
                        
                if random() > 0.5:
                    sy = uniform(1.2, 1.5)
                    sz = uniform(1.2, 1.5)
                    if is_last_hull_segment or random() > 0.5:
                        sy = 1 / sy
                        sz = 1 / sz
                    scale_face(bm, face, 1, sy, sz)
        
me = bpy.data.meshes.new('Mesh')
bm.to_mesh(me)
bm.free()

scene = bpy.context.scene
obj = bpy.data.objects.new('Spaceship', me)
scene.collection.objects.link(obj)

bpy.context.view_layer.objects.active = obj
obj.select_set(True)

bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')
ob = bpy.context.object
ob.location = (0, 0, 0)

How did you set up your Eclipse environment?

I downloaded the Eclipse installer. Then I go to https://www.pydev.org/download.html

But the download links at the bottom are broken.

Yeah that's how I installed my Eclipse as well. I downloaded the 2021/03 version of Eclipse and went to "Install new software" and installed PyDev using the link (https://www.pydev.org/download.html). Didn't try it out with other exe. though, the only thing I have connected with PyDev is Blender so not sure if the issue comes from the Pydev or Blender side.