hmm i think all is here…
I stripped most things of the script but had to leave the Panel UI part as the feature is called in the draw panel function: the dirty but simple way…
I think this could be done through a handler but i don’t know yet what event is called at UVEditor image change…
so here’s the script; as-is
import bpy
import numpy as np
from mathutils import Vector
import math
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
EnumProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
PropertyGroup,
)
#==========================================================================================
def SetImageInUVEditor(img):
for a in bpy.context.screen.areas:
if a.type == 'IMAGE_EDITOR':
space = a.spaces[0] # retrieve the 2D view zone
space.image = img
#==========================================================================================
def GetImageInUVEditor()->str:
for a in bpy.context.screen.areas:
if a.type == 'IMAGE_EDITOR':
space = a.spaces[0] # retrieve the 2D view zone
return(space.image.name)
#==========================================================================================
def SetGPLayerInUVEditor(GPLayerName:str):
for a in bpy.context.screen.areas:
if a.type == 'IMAGE_EDITOR':
space = a.spaces[0] # retrieve the 2D view zone
if(GPLayerName != None):
space.grease_pencil = bpy.data.grease_pencils[GPLayerName]
else:
space.grease_pencil = None
#==========================================================================================
# table of correspondances texture <---> annotations
# here's what you should setup the proper names of textures and annotation layers....
textureAnnotationCorresponding =[
["main_DIFF1850.tga","Annot-0"],
["fortif_dirt.tga","Annot-1"],
["cccc",None],
]
prevImgName:str="."
def SetAnnotationsForUVEditorImage(imgName:str):
found:bool = False
global prevImgName
if(imgName != prevImgName):
prevImgName = imgName
print("changing Annotations for "+imgName)
for entry in textureAnnotationCorresponding:
if(entry[0]==imgName):
found=True
SetGPLayerInUVEditor(entry[1])
if(found==False):
SetGPLayerInUVEditor(None)
return
#==========================================================================================
#**************************************************
#
# The class for parameters ( LAUGH MY ASS OFF !! )
#
# python: the art of obfuscating simple things....
#
#**************************************************
class MyBakesParameters(PropertyGroup):
foldCarcassMats : BoolProperty(
name="useless stupid thing",
description="Open texture/UV helper",
default = False)
#==========================================================================================
def foldout(SPN,row,boolVar:str,text,icon)->bool:
state = getattr(SPN,boolVar)
row.prop(SPN,
boolVar,
icon='TRIA_DOWN' if state else 'TRIA_RIGHT',
icon_only=True)
row.alert=True
row.label(text=text, icon=icon)
row.alert=False
return(state)
#==========================================================================================
#**************************************************
#
# The class for drawing previous both classes
# ( LOOOOOOOOOOL )
#
# python: the art of obfuscating simple things....
#
#**************************************************
class CarcassBakesPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Joseph script"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
def draw(self, context):
obj = context.active_object
layout = self.layout
SPN = context.window_manager.stupidPythonNeed
# ========================================
# Tex/UV helper
# ========================================
box = layout.box()
row = box.row()
currentImageName = GetImageInUVEditor()
SetAnnotationsForUVEditorImage(currentImageName)
# foldout for Tex/UV helper ( here's what should look blender's python API like )
if foldout(SPN,row,'foldCarcassMats', 'Carcass tex/UV helper','TEXTURE'):
row = box.row()
row.label(text="Here you can put the UI you want...")
bl_info = {
"name": "JosephScript",
"blender": (2, 80, 0),
"category": "Object",
}
def register():
bpy.utils.register_class(MyBakesParameters)
bpy.utils.register_class(CarcassBakesPanel)
bpy.types.WindowManager.stupidPythonNeed = PointerProperty(type=MyBakesParameters)
def unregister():
bpy.utils.unregister_class(CarcassBakesPanel)
bpy.utils.unregister_class(MyBakesParameters)
del bpy.types.WindowManager.stupidPythonNeed
if __name__ == "__main__":
register()
It creates a small menu in the Outliner → mesh tab.
You have nothing to do with this menu.
For correspondance image <—> annotation, you have to hardcode it in the script.
And that’s it
Tell me if you got further questions @joseph
Happy blending !