|
| 1 | +# ##### BEGIN GPL LICENSE BLOCK ##### |
| 2 | +# |
| 3 | +# <Import Voodoo Camera Tracker Scripts for Version 2.5 the easy way> |
| 4 | +# Copyright (C) <2020> <Blender Defender> |
| 5 | +# |
| 6 | +# This program is free software; you can redistribute it and/or |
| 7 | +# modify it under the terms of the GNU General Public License |
| 8 | +# as published by the Free Software Foundation; either version 3 |
| 9 | +# of the License, or (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program; if not, write to the Free Software Foundation, |
| 18 | +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | +# |
| 20 | +# ##### END GPL LICENSE BLOCK ##### |
| 21 | + |
| 22 | +bl_info = { |
| 23 | + "name": "Import Voodoo Camera Tracks", |
| 24 | + "author": "Blender Defender", |
| 25 | + "version": (1, 0, 0), |
| 26 | + "blender": (2, 82, 0), |
| 27 | + "location": "View3D > Object > Import > Open Voodo Camera Track", |
| 28 | + "description": "Import Voodoo Camera Tracker Scripts (for Blender 2.5) to Blender 2.8x the easy way!", |
| 29 | + "warning": "", |
| 30 | + "wiki_url": "https://github.com/BlenderDefender/io_voodoo_tracks", |
| 31 | + "tracker_url": "https://github.com/BlenderDefender/io_voodoo_tracks/issues", |
| 32 | + "category": "Import-Export"} |
| 33 | + |
| 34 | +import bpy |
| 35 | +import os |
| 36 | + |
| 37 | +from bpy.props import StringProperty, BoolProperty |
| 38 | +from bpy_extras.io_utils import ImportHelper |
| 39 | +from bpy.types import Operator |
| 40 | + |
| 41 | +# updater ops import, all setup in this file |
| 42 | +from . import addon_updater_ops |
| 43 | + |
| 44 | +#----------------------------------------------------------------- |
| 45 | +# Main Operator, opening, editing and executing the Voodoo Script |
| 46 | +#----------------------------------------------------------------- |
| 47 | + |
| 48 | +class OT_IO_ImportVoodooTrack(Operator, ImportHelper): |
| 49 | + """Import Voodoo Camera Tracker Script (for Blender 2.5, will be automaticly converted)""" |
| 50 | + bl_idname = "open.voodoo_track" |
| 51 | + bl_label = "Open Voodo Camera Track (.py)" |
| 52 | + |
| 53 | + def execute(self, context): |
| 54 | + """Convert the selected file from 2.5 to 2.8""" |
| 55 | + |
| 56 | +#------switch to Text-Editor----------- |
| 57 | + bpy.context.area.ui_type = 'TEXT_EDITOR' |
| 58 | + |
| 59 | +#------call the File Browser----------- |
| 60 | + bpy.ops.text.open(filepath=self.filepath) |
| 61 | + |
| 62 | +#------edit the Script----------------- |
| 63 | + bpy.ops.text.jump(line=16) |
| 64 | + bpy.ops.text.select_line() |
| 65 | + |
| 66 | + bpy.context.space_data.find_text = "scene" |
| 67 | + bpy.context.space_data.replace_text = "bpy.context.collection" |
| 68 | + |
| 69 | + bpy.ops.text.find() |
| 70 | + bpy.ops.text.replace() |
| 71 | + bpy.ops.text.replace() |
| 72 | + bpy.ops.text.replace() |
| 73 | + |
| 74 | + bpy.ops.text.jump(line=19) |
| 75 | + bpy.ops.text.select_line() |
| 76 | + bpy.ops.text.delete() |
| 77 | + |
| 78 | + bpy.ops.text.jump(line=27) |
| 79 | + bpy.ops.text.select_line() |
| 80 | + bpy.ops.text.delete() |
| 81 | + |
| 82 | + bpy.ops.text.jump(line=30) |
| 83 | + bpy.ops.text.select_line() |
| 84 | + bpy.ops.text.delete() |
| 85 | + |
| 86 | +#-------run the Script----------------- |
| 87 | + bpy.ops.text.run_script() |
| 88 | + |
| 89 | +#------return to 3D View--------------- |
| 90 | + bpy.context.area.ui_type = 'VIEW_3D' |
| 91 | + |
| 92 | + return {'FINISHED'} |
| 93 | + |
| 94 | +#----------------------------------------------------------------- |
| 95 | +# Import Menu |
| 96 | +#----------------------------------------------------------------- |
| 97 | + |
| 98 | +class Voodoo_Tracking_Menu(bpy.types.Menu): |
| 99 | + bl_idname = 'menu.import_voodoo' |
| 100 | + bl_label = 'Import' |
| 101 | + |
| 102 | + def draw(self, context): |
| 103 | + layout = self.layout |
| 104 | + layout.operator(OT_IO_ImportVoodooTrack.bl_idname, icon = 'CON_CAMERASOLVER') |
| 105 | +#----------------------------------------------------------------- |
| 106 | + |
| 107 | +def menu_func(self, context): |
| 108 | + self.layout.menu(Voodoo_Tracking_Menu.bl_idname) |
| 109 | + |
| 110 | + |
| 111 | +class DemoPreferences(bpy.types.AddonPreferences): |
| 112 | + bl_idname = __package__ |
| 113 | + |
| 114 | + # addon updater preferences |
| 115 | + |
| 116 | + auto_check_update = bpy.props.BoolProperty( |
| 117 | + name="Auto-check for Update", |
| 118 | + description="If enabled, auto-check for updates using an interval", |
| 119 | + default=False, |
| 120 | + ) |
| 121 | + updater_intrval_months = bpy.props.IntProperty( |
| 122 | + name='Months', |
| 123 | + description="Number of months between checking for updates", |
| 124 | + default=0, |
| 125 | + min=0 |
| 126 | + ) |
| 127 | + updater_intrval_days = bpy.props.IntProperty( |
| 128 | + name='Days', |
| 129 | + description="Number of days between checking for updates", |
| 130 | + default=7, |
| 131 | + min=0, |
| 132 | + max=31 |
| 133 | + ) |
| 134 | + updater_intrval_hours = bpy.props.IntProperty( |
| 135 | + name='Hours', |
| 136 | + description="Number of hours between checking for updates", |
| 137 | + default=0, |
| 138 | + min=0, |
| 139 | + max=23 |
| 140 | + ) |
| 141 | + updater_intrval_minutes = bpy.props.IntProperty( |
| 142 | + name='Minutes', |
| 143 | + description="Number of minutes between checking for updates", |
| 144 | + default=0, |
| 145 | + min=0, |
| 146 | + max=59 |
| 147 | + ) |
| 148 | + |
| 149 | + def draw(self, context): |
| 150 | + layout = self.layout |
| 151 | + # col = layout.column() # works best if a column, or even just self.layout |
| 152 | + mainrow = layout.row() |
| 153 | + col = mainrow.column() |
| 154 | + |
| 155 | + # updater draw function |
| 156 | + # could also pass in col as third arg |
| 157 | + addon_updater_ops.update_settings_ui(self, context) |
| 158 | + |
| 159 | + # Alternate draw function, which is more condensed and can be |
| 160 | + # placed within an existing draw function. Only contains: |
| 161 | + # 1) check for update/update now buttons |
| 162 | + # 2) toggle for auto-check (interval will be equal to what is set above) |
| 163 | + # addon_updater_ops.update_settings_ui_condensed(self, context, col) |
| 164 | + |
| 165 | + # Adding another column to help show the above condensed ui as one column |
| 166 | + # col = mainrow.column() |
| 167 | + # col.scale_y = 2 |
| 168 | + # col.operator("wm.url_open","Open webpage ").url=addon_updater_ops.updater.website |
| 169 | + |
| 170 | + |
| 171 | +classes = ( |
| 172 | + DemoPreferences, |
| 173 | + OT_IO_ImportVoodooTrack, |
| 174 | + Voodoo_Tracking_Menu, |
| 175 | + |
| 176 | +) |
| 177 | + |
| 178 | + |
| 179 | +def register(): |
| 180 | + # addon updater code and configurations |
| 181 | + # in case of broken version, try to register the updater first |
| 182 | + # so that users can revert back to a working version |
| 183 | + addon_updater_ops.register(bl_info) |
| 184 | + |
| 185 | + bpy.types.VIEW3D_MT_object.append(menu_func) |
| 186 | + |
| 187 | + # register the example panel, to show updater buttons |
| 188 | + for cls in classes: |
| 189 | + addon_updater_ops.make_annotations(cls) # to avoid blender 2.8 warnings |
| 190 | + bpy.utils.register_class(cls) |
| 191 | + |
| 192 | + |
| 193 | +def unregister(): |
| 194 | + # addon updater unregister |
| 195 | + addon_updater_ops.unregister() |
| 196 | + |
| 197 | + bpy.types.VIEW3D_MT_object.remove(menu_func) |
| 198 | + |
| 199 | + # register the example panel, to show updater buttons |
| 200 | + for cls in reversed(classes): |
| 201 | + bpy.utils.unregister_class(cls) |
0 commit comments