2

Bear with me, I am still new to python in blender, I apologize, I am not very good with words or is capable of explaining the issues I am having or solutions I am looking for. So instead of struggling with words, I'll use illustration at most of time.

I started off with creating Panel that displays two pointerPropteries coming from Array and Curve modifier.

enter image description here

...and the script.

class PROJECTX(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "PANEL"
    bl_idname = "POINTERTEST"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "PJTX"
def draw(self, context):
    layout = self.layout
    scene = context.scene
    col = layout.column()


    col.prop(bpy.context.active_object.modifiers[r"Array"],'curve', text=r"Curve")
    col.prop(bpy.context.active_object.modifiers[r"Curve"], 'object', text=r"Curve Object")

Now, Instead of two PointerProperies inside UI panel, I was hoping I could use single pointer. I was wondering if its possible to add operation that can have single pointer from Panel to assign direct to both modifiers' (array and curve) pointer at once whenever it pick curve in the scene? If so, how could I write a script for it?

enter image description here

I was looking at layout.prop_search() which I picked up from https://blender.stackexchange.com/a/101301/142719 and https://docs.blender.org/api/current/bpy.types.UILayout.html and thought maybe this can be used in Panel and assign directly to pointers in both modifiers whenever it pick curve in scene. Unfortunately I must admit I don't have better insight on .prop_Search() or PointerProperites since there aren't sufficent information on this. I was hoping I could collect some information to get me started. Any suggestions? Thanks in advance

sirrus
  • 169
  • 6

2 Answers2

3

Sync Data:

import bpy
from bpy.app.handlers import persistent

@persistent def upd_fn(dummy): try: print("-- update --") mds = bpy.context.active_object.modifiers mds[r"Curve"].object = mds[r"Array"].curve except: pass

class PROJECTX(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "PANEL" bl_idname = "POINTERTEST" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "PJTX"

def draw(self, context):
    layout = self.layout
    scene = bpy.context.scene
    col = layout.column()
    col.prop(bpy.context.active_object.modifiers[r"Array"],'curve', text=r"Curve")


bpy.app.handlers.depsgraph_update_post.append(upd_fn)

def register(): bpy.utils.register_class(PROJECTX)

def unregister(): bpy.utils.unregister_class(PROJECTX)

if name == "main": register()

X Y
  • 5,234
  • 1
  • 6
  • 20
3

You can add a custom property to bpy.types.Object that holds a pointer to a curve, and use the update method to dynamically update the object's modifiers.

import bpy

def update_my_curve(self, context): array = self.modifiers.get("Array") if array: array.curve = self.my_curve curve = self.modifiers.get("Curve") if curve: curve.object = self.my_curve

class MOD_PT_Curve(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "PANEL" bl_idname = "POINTERTEST" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "PJTX"

def draw(self, context):
    self.layout.prop(context.active_object, "my_curve")


def register(): bpy.utils.register_class(MOD_PT_Curve) bpy.types.Object.my_curve = bpy.props.PointerProperty( type=bpy.types.Object, update=update_my_curve, name="My Curve", poll=lambda self, object: object.type == "CURVE", # Filter only curve objects )

if name == "main": register()

Gorgious
  • 30,723
  • 2
  • 44
  • 101
  • 1
    Very insightful and interesting! That's something I've always want to look into for a long time. Thank you for taking time to share with me. – sirrus Mar 25 '22 at 15:48