Selecting an object per name in local view?

Hy!
I have a question:
Is there a way to select an object per name when i stay with an another object in local view?


bpy.ops.object.select_pattern(pattern="Cube")

#or

object = bpy.data.objects['OBJECT']
object.select = True

Thank you JuhaW! The first one is excatly what i use, but i have to explain it better:

I only can go with the active object into the local view,
but to go further i have to check the view with a if-function,

i need something like:

if view3d = “LOCALVIEW”: < I don`t find the right discription for that view space
do something
else:
do something

I want to grab a second object and bring into the local, too!
I know how to toggle in and out, but for all other i trying without succes!

while in the context of the 3d view, it’s:

if context.space_data.local_view is not None: …

or iterate over all areas and find 3d views:

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        print("Local view?", area.spaces.active.local_view is not None)

THX! It works!

here is what i done:



bl_info = {
    "name": "BBox",
    "author": "mkbreuer / nikitron (bbox source)",
    "version": (0, 1, 0),
    "blender": (2, 7, 3),
    "location": "View3D",
    "description": "Bounding Boxes for selected Objects",
    "warning": "",
    "wiki_url": "",
    "category" : "Add Mesh"
}


import bpy, mathutils, math, re
from mathutils.geometry import intersect_line_plane
from mathutils import Vector
from math import radians
from bpy import*



############  Objectmode Operator  ############


### further function for BoundingBoxSource
class BoundingBox (bpy.types.Operator):
    """create a bound boxes for selected object"""      
    bl_idname = "object.bounding_boxers"
    bl_label = "BBox"
    bl_options = {'REGISTER', 'UNDO'}
                                 
    bbox_subdiv = bpy.props.IntProperty(name="Subdivide", description="How often?", default=0, min=0, soft_max=10, step=1)            

    bbox_wire = bpy.props.BoolProperty(name="Wire only", description="Delete Face", default= False) 

    bbox_origin = bpy.props.BoolProperty(name="Origin Center",  description="Origin to BBox-Center", default=False) 
                       
    bbox_freeze = bpy.props.BoolProperty(name="Freeze Selection",  description="Hide from selection", default=False)   

    def execute(self, context):

        if context.space_data.local_view is not None:
            bpy.ops.view3d.localview()
            bpy.ops.object.bounding_box_source()  
            bpy.ops.object.select_pattern(pattern="_bbox_edit", case_sensitive=False, extend=False)
        
        else:            
            bpy.ops.object.bounding_box_source()  
            bpy.ops.object.select_pattern(pattern="_bbox_edit", case_sensitive=False, extend=False)  
            
        
        bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
        
        for obj in bpy.context.selected_objects:            
            bpy.context.scene.objects.active = obj            
                                            
            bpy.ops.object.editmode_toggle()  
            bpy.ops.mesh.normals_make_consistent()                       
            
            for i in range(self.bbox_subdiv):
                bpy.ops.mesh.subdivide(number_cuts=1)

            for i in range(self.bbox_wire):
                bpy.ops.mesh.delete(type='ONLY_FACE')
            
            bpy.ops.object.editmode_toggle()

            for i in range(self.bbox_origin):
                bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')                    
                
            for i in range(self.bbox_freeze):
                bpy.context.object.hide_select = True

        bpy.context.object.name = "_bbox"        
        return {'FINISHED'}                        

    def invoke(self, context, event):
        return context.window_manager.invoke_props_popup(self, event)



### BoundingBoxSource from nikitron 
### http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Object/Nikitron_tools
class BoundingBoxSource (bpy.types.Operator):
    """Make bound boxes for selected objects"""      
    bl_idname = "object.bounding_box_source"
    bl_label = "Bounding boxes"
    bl_options = {'REGISTER', 'UNDO'}
    
    def execute(self, context):
        objects = bpy.context.selected_objects
        i = 0
        for a in objects:
            self.make_it(i, a)
            i += 1
            
        return {'FINISHED'}


    def make_it(self, i, obj):
        box = bpy.context.selected_objects[i].bound_box
        mw = bpy.context.selected_objects[i].matrix_world
        name = ('_bbox_edit')                               #name = (bpy.context.selected_objects[i].name + '_bbox') 
        me = bpy.data.meshes.new(name)                      #bpy.data.meshes.new(name + 'Mesh')
        ob = bpy.data.objects.new(name, me)
        
        ob.location = mw.translation
        ob.scale = mw.to_scale()
        ob.rotation_euler = mw.to_euler()
        ob.show_name = False
        bpy.context.scene.objects.link(ob)
        loc = []
        for ver in box:
            loc.append(mathutils.Vector((ver[0],ver[1],ver[2])))
        me.from_pydata((loc), [], ((0,1,2,3),(0,1,5,4),(4,5,6,7), (6,7,3,2),(0,3,7,4),(1,2,6,5)))
        me.update(calc_edges=True) 
        return

  

#add single operator to add menu [SHIFT+A]    
def draw_item(self, context):
    self.layout.operator("object.bounding_boxers","BBox", icon = "BBOX")
            
        

############  REGISTER  ############
  
def register():

    bpy.utils.register_class(BoundingBoxSource)
    bpy.utils.register_class(BoundingBox)

    #prepend = to MenuTop / append to MenuBottom 
    bpy.types.INFO_MT_add.prepend(draw_item) 

 
    
def unregister():
    
    bpy.utils.unregister_class(BoundingBoxSource)
    bpy.utils.unregister_class(BoundingBox)


 
if __name__ == "__main__":
    register()



Feel free to refine it… :slight_smile: