Hi, I’m working on a mesh exporter to save blender’s vertex attribute (couldn’t find anything existing for that oddely).
I have an issue using CollectionProperty: in the export panel, I expected to see the actual list and be able to edit it, but I only see the number of items (see screenshoot).
class AttributeMapping(PropertyGroup):
attribute = StringProperty(name="Attribute", description="vertex attribute")
semantic = StringProperty(name="Semantic", description="shader semantic (ex: TEXCOORD0)")
class ExportFlexibleMesh(Operator, ExportHelper):
attribute_mapping: CollectionProperty(
name="Attribute mapping",
type=AttributeMapping,
description="map vertex attribute to shader semantic"
)
I can’t find any helpful doc, can I have a clue? Is there a constructor parameter I missed ? Is there a “draw” function to override? or something else?
Yep, you need a draw() function for your properties to work correctly. It’s pretty simple for an n panel but I’m not sure about your use case… see if you can find some other addon with a similar setup and borrow from their code
By default Blender doesn’t know how to display a CollectionProperty, since the data inside is arbitrary. You have to define your own layout. For example add this to your operator class :
def draw(self, context):
self.layout.prop(self, "topology")
# This will make the fields readonly
for i, attr in enumerate(self.attribute_mapping):
box = self.layout.box()
box.label(text="Attribute n°" + str(i))
box.label(text="Name : " + attr.attribute)
box.label(text="Semantic : " + attr.semantic)
# This will make the fields editable
for i, attr in enumerate(self.attribute_mapping):
box = self.layout.box()
box.label(text="Attribute n°" + str(i))
box.prop(attr, "attribute")
box.prop(attr, "semantic")
Thanks a lot for the full code Gorgious .
I moved on for now by just hardcoding the list for my current needs but I’ll come back to it, beiing able to export any data is mandatory for my VFX workflow.