Hide
Solve a problem – Filter by language, license, keyword, owner, or search text to find code & info fast. Join Siafoo Now or Learn More

Blender phantom object cleaner Atom Feed 0

In Brief This very very basic script helps clean out crazy phantom objects that sometimes get produces when using the DXF Import script under Blender,... more
# 's
 1#!BPY
2"""
3Name: 'Phantom object cleaner'
4Blender: 245
5Group: 'Object'
6Tooltip: 'Links phantom objects to current scene (Only works if you have one scene)'
7"""
8
9# This "code" is left in the Public Domain
10
11from Blender import Window, sys, Mesh, Object
12from Blender.Mesh import *
13
14import bpy
15
16from Blender import Mesh
17
18def do_stuff(sce):
19
20 # Remove these when writing your own tool
21 print 'Blend object count', len(bpy.data.objects)
22 print 'Scene object count', len(sce.objects)
23
24 phantoms = len(bpy.data.objects) - len(sce.objects)
25
26 if phantoms == 0:
27 print 'No Phantoms Found'
28 return
29
30 print 'Possible Phantoms', phantoms
31
32 # context means its selected, in the view layer and not hidden.
33 print 'Scene context count', len(sce.objects.context)
34
35 ct = 0
36 for obj in bpy.data.objects:
37 bpy.data.objects
38 if obj not in sce.objects:
39 sce.link(obj)
40 m = obj.getData(mesh=True)
41# print obj, m, len(m.verts)
42
43# if hasattr(m, 'verts') and len(m.verts) == 0:
44# ct += 1
45# print obj, m, len(m.verts)
46# Mesh.Unlink(m.name)
47# if obj not in sce.objects:
48# sce.objects.link(obj)
49
50 print 'Objects with verteces %i' % ct
51
52def main():
53
54 # Gets the current scene, there can be many scenes in 1 blend file.
55 sce = bpy.data.scenes.active
56
57 Window.WaitCursor(1)
58 t = sys.time()
59
60 # Run the object editing function
61 do_stuff(sce)
62
63 # Timing the script is a good way to be aware on any speed hits when scripting
64 print 'My Script finished in %.2f seconds' % (sys.time()-t)
65 Window.WaitCursor(0)
66
67
68# This lets you can import the script without running it
69if __name__ == '__main__':
70 main()

This very very basic script helps clean out crazy phantom objects that sometimes get produces when using the DXF Import script under Blender,

See bug report for more information

Cleaning Phantoms

  1. Open script in Blender text editor
  2. Hide all your normal objects
  3. Run script
  4. Select All (A key)
  5. Remove from all groups (Ctrl+G Remove from all groups
  6. Delete
  7. Save and Close file (or Blender)

It may be necessary to repeat these steps a couple of times (for me it took 2-3 iterations). Keep your eye on the console it will display the number of phantom objects.

Warning

This script considers objects not in the current scene phantoms, be careful if you have multiple scenes.