Closed Max-Vincent closed 6 months ago
try this, from packscript_demos/packscript_override.py
# ////////////////////////////////////////////////
# CAPSULE PACK SCRIPTS DEMO
#
#
# Pack Scripts let you edit an export just before it's saved to a file.
#
# The Blender Python API lets you do anything you'd want to do to create a setup
# just right for your particular workflow in a way I never could with all the interface
# buttons in the world. Capsule will automate everything else for you, all you need to
# do is add the few things special to how you work!
#
# IMPORTANT INFO
#
# - Use the "Test Export" button when developing scripts to check that they function in
# the way you expect. If it's a bigger script you might want to test it using the Text
# Editor first, before using Test Export.
#
# - If some of your exports have the Origin Point set to anything other than
# 'Scene', you'll find that when this script is run the entire scene will have
# moved in 3D space. This is how Capsule ensures that an object's origin point is where
# you want it.
#
# - This script is called twice - once just before an export and once right after.
#
# - A Pack Script is the LAST thing Capsule has to do, everything else including filtering,
# moving objects to the origin point of the scene and anything else has been done.
#
# - Separate Pack Scripts cannot interact with each other, the CAPStatus object that provides
# export information and a way to provide a final export list will be cleared after every
# export operation.
import bpy
context = bpy.context
export_status = context.scene.CAPStatus
if export_status.target_status == 'BEFORE_EXPORT':
# Use this to get the objects that Capsule wants to export
objects = export_status['target_input']
final_objects = []
for obj in objects:
if obj.type == 'ARMATURE':
obj.name = "Armature"
final_objects.append(obj)
# Use this to provide Capsule with the objects you want to export
# THIS MUST CONTAIN SOMETHING
export_status['target_output'] = objects
if export_status.target_status == 'AFTEREXPORT': for obj in objects: if obj.type == 'ARMATURE': if obj.name == "Armature": obj.name = "ARM"
# CAPStatus information will be cleared after is this run ready for
# the next export.
pass
@Max-Vincent The example posted by @Wolfgang-IX is the correct format for Pack Scripts, though it's missing code to undo the changes made to the scene in the 'AFTER_EXPORT' portion of the template.
As of right now you need to both make the changes and undo them in the scene once the export is complete, though this may change in the future. It's really important to remember that Pack Scripts are editing the Blend file as it is, it's not currently possible to sandbox these changes without various compromises made elsewhere in the export process.
@Wolfgang-IX @Takanu thank you both of you, and the script works!
Hello, i was wondering if i have multiple collections to be exported but with different armatures in each collections, how do i ensure that when exporting each collections it rename the armature as "Armature"?
i was guessing that Pack Script will run for each export list before exporting it, but when i use this script it didn't export the objects just a info that said it's successfully exported.