def get_center(self, context): location = (0, 0, 0) matrix = None try: # we must now pass the origin node/tree in 2.80 ( this code does not interpret that yet ) node_group = bpy.data.node_groups[self.idtree] node = node_group.nodes[self.idname] print('node:', node) inputs = node.inputs if node.bl_idname in {'SvViewerDrawMk4'}: matrix_socket = inputs['Matrix'] vertex_socket = inputs['Vertices'] # from this point the function is generic. vertex_links = vertex_socket.is_linked matrix_links = matrix_socket.is_linked if matrix_links: matrix = get_matrix(matrix_socket) if vertex_links: vertex_in_data = vertex_socket.sv_get() verts = vertex_in_data[0] location = geom_utils.mean( [verts[idx] for idx in range(0, len(verts), 3)]) if matrix: if not vertex_links: location = Matrix(matrix).to_translation()[:] else: location = (Matrix(matrix) @ Vector(location))[:] else: self.report({'INFO'}, 'viewer has no get_center function') except Exception as err: self.report({'INFO'}, 'no active node found') sys.stderr.write('ERROR: %s\n' % str(err)) print(sys.exc_info()[-1].tb_frame.f_code) print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno)) return location
def get_center(self, context): location = (0, 0, 0) matrix = None try: node = None if hasattr(context, 'node'): node = context.node if not node: node = context.active_node inputs = node.inputs if node.bl_idname in {'ViewerNode2'}: matrix_socket = inputs['matrix'] vertex_socket = inputs['vertices'] # from this point the function is generic. vertex_links = vertex_socket.is_linked matrix_links = matrix_socket.is_linked if matrix_links: matrix = get_matrix(matrix_socket) if vertex_links: vertex_in_data = vertex_socket.sv_get() verts = vertex_in_data[0] location = geom_utils.mean( [verts[idx] for idx in range(0, len(verts), 3)]) if matrix: if not vertex_links: location = Matrix(matrix).to_translation()[:] else: location = (Matrix(matrix) @ Vector(location))[:] else: self.report({'INFO'}, 'viewer has no get_center function') except: self.report({'INFO'}, 'no active node found') return location
def get_center(self, context): location = (0, 0, 0) matrix = None try: node = None if hasattr(context, 'node'): node = context.node if not node: node = context.active_node inputs = node.inputs if node.bl_idname in {'ViewerNode2'}: matrix_socket = inputs['matrix'] vertex_socket = inputs['vertices'] # from this point the function is generic. vertex_links = vertex_socket.is_linked matrix_links = matrix_socket.is_linked if matrix_links: matrix = get_matrix(matrix_socket) if vertex_links: vertex_in_data = vertex_socket.sv_get() verts = vertex_in_data[0] location = geom_utils.mean([verts[idx] for idx in range(0, len(verts), 3)]) if matrix: if not vertex_links: location = Matrix(matrix).to_translation()[:] else: location = (Matrix(matrix) * Vector(location))[:] else: self.report({'INFO'}, 'viewer has no get_center function') except: self.report({'INFO'}, 'no active node found') return location