Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/object.py
| Show First 20 Lines • Show All 864 Lines • ▼ Show 20 Lines | def execute(self, context): | ||||
| scene = context.scene | scene = context.scene | ||||
| collection = context.collection | collection = context.collection | ||||
| collection.dupli_offset = scene.cursor_location | collection.dupli_offset = scene.cursor_location | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class LoadImageAsEmpty(Operator): | class LoadImageAsEmpty: | ||||
| """Select an image file and create a new image empty with it""" | |||||
| bl_idname = "object.load_image_as_empty" | |||||
| bl_label = "Load Image as Empty" | |||||
| bl_options = {'REGISTER', 'UNDO'} | bl_options = {'REGISTER', 'UNDO'} | ||||
| filepath: StringProperty( | filepath: StringProperty( | ||||
| subtype='FILE_PATH' | subtype='FILE_PATH' | ||||
| ) | ) | ||||
| filter_image: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'}) | filter_image: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'}) | ||||
| filter_folder: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'}) | filter_folder: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'}) | ||||
| view_align: BoolProperty( | view_align: BoolProperty( | ||||
| name="Align to view", | name="Align to view", | ||||
| default=True | default=True | ||||
| ) | ) | ||||
| def invoke(self, context, event): | def invoke(self, context, event): | ||||
| context.window_manager.fileselect_add(self) | context.window_manager.fileselect_add(self) | ||||
| return {'RUNNING_MODAL'} | return {'RUNNING_MODAL'} | ||||
| def execute(self, context): | def execute(self, context): | ||||
| scene = context.scene | scene = context.scene | ||||
| space = context.space_data | space = context.space_data | ||||
| cursor = (space if space and space.type == 'VIEW_3D' else scene).cursor_location | cursor = (space if space and space.type == 'VIEW_3D' else scene).cursor_location | ||||
| try: | try: | ||||
| image = bpy.data.images.load(self.filepath, check_existing=True) | image = bpy.data.images.load(self.filepath, check_existing=True) | ||||
| except RuntimeError as ex: | except RuntimeError as ex: | ||||
| self.report({"ERROR"}, str(ex)) | self.report({"ERROR"}, str(ex)) | ||||
| return {"CANCELLED"} | return {"CANCELLED"} | ||||
| bpy.ops.object.empty_add( | bpy.ops.object.empty_add( | ||||
| 'INVOKE_REGION_WIN', | 'INVOKE_REGION_WIN', | ||||
| type='IMAGE', | type='IMAGE', | ||||
| location=cursor, | location=cursor, | ||||
| view_align=self.view_align, | view_align=self.view_align, | ||||
| ) | ) | ||||
| obj = context.active_object | obj = context.active_object | ||||
| obj.data = image | obj.data = image | ||||
| obj.empty_display_size = 5.0 | obj.empty_display_size = 5.0 | ||||
| self.set_settings(context, obj) | |||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| def set_settings(self, context, obj): | |||||
| pass | |||||
| class LoadBackgroundImage(LoadImageAsEmpty, Operator): | |||||
| """Add a reference image into the background behind objects""" | |||||
| bl_idname = "object.load_background_image" | |||||
| bl_label = "Load Background Image" | |||||
| def set_settings(self, context, obj): | |||||
| obj.empty_image_depth = "BACK" | |||||
| obj.show_empty_image_backside = False | |||||
| if context.space_data.type == "VIEW_3D": | |||||
| if context.space_data.region_3d.is_perspective: | |||||
| obj.show_empty_image_orthographic = False | |||||
| else: | |||||
| obj.show_empty_image_perspective = False | |||||
| class LoadReferenceImage(LoadImageAsEmpty, Operator): | |||||
| """Add a reference image into the scene between objects""" | |||||
| bl_idname = "object.load_reference_image" | |||||
| bl_label = "Load Reference Image" | |||||
| def set_settings(self, context, obj): | |||||
| pass | |||||
| classes = ( | classes = ( | ||||
| ClearAllRestrictRender, | ClearAllRestrictRender, | ||||
| DupliOffsetFromCursor, | DupliOffsetFromCursor, | ||||
| IsolateTypeRender, | IsolateTypeRender, | ||||
| JoinUVs, | JoinUVs, | ||||
| LoadImageAsEmpty, | LoadBackgroundImage, | ||||
| LoadReferenceImage, | |||||
| MakeDupliFace, | MakeDupliFace, | ||||
| SelectCamera, | SelectCamera, | ||||
| SelectHierarchy, | SelectHierarchy, | ||||
| SelectPattern, | SelectPattern, | ||||
| ShapeTransfer, | ShapeTransfer, | ||||
| SubdivisionSet, | SubdivisionSet, | ||||
| TransformsToDeltas, | TransformsToDeltas, | ||||
| TransformsToDeltasAnim, | TransformsToDeltasAnim, | ||||
| ) | ) | ||||