我正在为搅拌机制作一个插件,我有一些包含绘图功能的数据类型。但是,当在两个特定类上调用这些函数时,它会抛出一个
AttributeError
Traceback (most recent call last):
File "[REDACTED]/blender/4.2/scripts/addons/manifoldclothing/gen/GenPanel.py", line 17, in draw
context.active_object.manifoldHuman.maleBody.draw(layout, context)
File "[REDACTED]/blender/4.2/scripts/addons/manifoldclothing/data/FemaleBodyData.py", line 35, in draw
self.neck.draw(box, context)
^^^^^^^^^^^^^^
AttributeError: 'LongLimbData' object has no attribute 'draw'
肢体数据:
import bpy
class LimbData(bpy.types.PropertyGroup):
length: bpy.props.FloatProperty(name="Length")
def draw(self, layout, context):
layout.prop(self, "length")
长肢数据:
import bpy
from .LimbData import *
class LongLimbData(LimbData):
thickness: bpy.props.FloatProperty(name="Thickness")
def draw(self, layout, context):
super().draw(layout, context)
layout.prop(self, "thickness")
女性脊柱数据:
import bpy
from .LongLimbData import *
class FemaleSpineData(LongLimbData):
lowerWidth: bpy.props.FloatProperty(name="Lower Width")
upperWidth: bpy.props.FloatProperty(name="Upper Width")
def draw(self, layout, context):
super().draw(layout, context)
layout.prop(self, "lowerWidth")
layout.prop(self, "upperWidth")
女性身体数据:
import bpy
from .BodyData import *
from .FemaleChestData import *
from .FemaleHipData import *
from .FemaleThighData import *
class FemaleBodyData(BodyData):
hips: bpy.props.PointerProperty(type=FemaleHipData)
spine: bpy.props.PointerProperty(type=FemaleSpineData)
chest: bpy.props.PointerProperty(type=FemaleChestData)
neck: bpy.props.PointerProperty(type=LongLimbData)
head: bpy.props.PointerProperty(type=WideLimbData)
# OTHER FIELDS OMITTED
def draw(self, layout, context):
box = layout.box()
self.hips.draw(box, context)
self.spine.draw(box, context)
self.chest.draw(box, context)
self.neck.draw(box, context)
self.head.draw(box, context)
# OTHER DRAW CALLS OMITTED
但是
FemaleSpineData
(扩展了LongLimbData
)可以很好地调用super().draw(layout, context)
。它显示了 LongLimbData
定义的额外属性。
我现在已经确保缩进 4 个空格至少 5 次。我也尝试安装另一个版本的搅拌机但无济于事。
原来这是搅拌机的问题。当对现有属性组等进行子类化时,Blender 表现不佳。在这种情况下使用子类化的正确方法是使用混合类。
示例:
import bpy
class AbstractLimb:
length: bpy.props.FloatProperty(name="Length", min=0.0)
def Draw(self, layout, context):
layout.prop(self, "length")
class LongLimb(AbstractLimb, bpy.types.PropertyGroup):
radius: bpy.props.FloatProperty(name="Radius", min=0.0)
def Draw(self, layout, context):
super().Draw(layout, context)
layout.prop(self, "radius")
class WideLimb(AbstractLimb, bpy.types.PropertyGroup):
width: bpy.props.FloatProperty(name="Width", min=0.0)
thickness: bpy.props.FloatProperty(name="Thickness", min=0.0)
def Draw(self, layout, context):
super().Draw(layout, context)
layout.prop(self, "width")
layout.prop(self, "thickness")
这没有给我带来任何错误,并且由 UI 正确绘制。