Advertisement
nux95

Cloner Export v0.1

May 1st, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. # Copyright (C) 2013, Niklas Rosenstein
  2. # All rights reserved.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Lesser General Public License as published
  6. # by the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the Lesser GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16.  
  17. import os
  18. import c4d
  19.  
  20. Omograph_cloner = 1018544
  21.  
  22. def filter_objects(doc, type_id, children=False):
  23.     def callback(op):
  24.         if op.CheckType(type_id):
  25.             yield op
  26.             if not children: return
  27.         for child in op.GetChildren():
  28.             for obj in callback(child):
  29.                 yield obj
  30.  
  31.     for obj in doc.GetObjects():
  32.         for o in callback(obj):
  33.             yield o
  34.  
  35. def main():
  36.     flname = c4d.storage.SaveDialog()
  37.     if not flname:
  38.         return
  39.     if os.path.exists(flname) and not os.path.isfile(flname):
  40.         c4d.gui.MessageDialog('Invalid file-name.')
  41.         return
  42.  
  43.     try:
  44.         fl = open(flname, 'w')
  45.     except IOError, OSError:
  46.         c4d.gui.MessageDialog('Could not open file.')
  47.         return
  48.  
  49.     for cloner in filter_objects(doc, Omograph_cloner):
  50.         name = cloner.GetName().replace(';', '\\;')
  51.         fl.write(name + ';')
  52.         cache = cloner.GetCache()
  53.         if cache:
  54.             for clones in cache.GetChildren():
  55.                 pos = clones.GetMg().off
  56.                 fl.write('%.3f;%.3f;%.3f;' % (pos.x, pos.y, pos.z))
  57.         fl.write('\n')
  58.  
  59.     fl.close()
  60.  
  61. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement