init with resolution swapper

main
Anish Lakhwara 2022-08-28 17:20:26 +10:00
commit a7767978c2
4 changed files with 160 additions and 0 deletions

48
Text Normal file
View File

@ -0,0 +1,48 @@
bl_info = {
"name": "Swap Resulotion",
"blender": (2, 80, 0),
"category": "Context",
}
import bpy
class SwapResolution(bpy.types.Operator):
"""Resolution Swaping button""" # Use this as a tooltip for menu items and buttons.
bl_idname = "scene.swap_res" # Unique identifier for buttons and menu items to reference.
bl_label = "Swap Resolution" # Display name in the interface.
def swap(self, curr_x, curr_y):
y = curr_x
x = curr_y
bpy.context.scene.render.resolution_y = y
bpy.context.scene.render.resolution_x = x
def execute(self, context): # execute() is called when running the operator.
# The original script
render = context.scene.render
self.swap(render.resolution_x, render.resolution_y)
return {'FINISHED'} # Lets Blender know the operator finished successfully.
class FancyPanel(bpy.types.Panel):
bl_idname = "test_fancy_panel_for_fun"
bl_label = "Fancy Panel"
bl_space_type = 'PROPERTIES'
bl_region_type = "WINDOW"
def draw(self, context):
self.layout.laber(text="Testing")
self.layout.operator("scene.swap_res")
def register():
bpy.utils.register_class(SwapResolution)
bpy.utils.register_class(FancyPanel)
# bpy.types.VIEW3D_MT_object.append(menu_func) # Adds the new operator to an existing menu.
def unregister():
bpy.utils.unregister_class(SwapResolution)
bpy.utils.unregister_class(FancyPanel)
if __name__ == "__main__":
register()

42
flake.lock Normal file
View File

@ -0,0 +1,42 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1661641486,
"narHash": "sha256-+wdlXaGJeO2PrFrOwVIyP+LmGD1iavGbMJ7Qy+S8SzM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "da1b01a144a95b75db46e2c7102eb51200625515",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

20
flake.nix Normal file
View File

@ -0,0 +1,20 @@
{
description = "Blender Addon Development";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in
{
devShell = pkgs.mkShell {
buildInputs = [
pkgs.blender
];
};
});
}

50
resolution-swapper.py Normal file
View File

@ -0,0 +1,50 @@
bl_info = {
"name": "Resolution Swapper",
"author": "Anish Lakhwara",
"version": (1, 0, 0),
"blender": (2, 78, 0),
"description": "Simple button to swap X & Y resolution size",
"category": "Properties",
}
import bpy
class ResSwapButton(bpy.types.Operator):
bl_idname = "resswap.button"
bl_label = "Swap Resolution"
def execute(self, context):
x = context.scene.render.resolution_y
y = context.scene.render.resolution_x
context.scene.render.resolution_y = y
context.scene.render.resolution_x = x
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(ResSwapButton.bl_idname)
class ResSwapPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Resolution Swaper"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "output"
def draw(self, context):
scene = context.scene
self.layout.operator(ResSwapButton.bl_idname)
def register():
bpy.utils.register_class(ResSwapButton)
bpy.types.RENDER_PT_format.append(menu_func)
#bpy.utils.register_class(ResSwapPanel)
def unregister():
bpy.utils.unregister_class(ResSwapButton)
#bpy.utils.unregister_class(ResSwapPanel)
if __name__ == "__main__":
register()