Advertisement
nux95

Cloner Export v0.2

May 2nd, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 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. delimiter_1 = ':'
  21. delimiter_2 = ';'
  22. precision = 3
  23. Omograph_cloner = 1018544
  24.  
  25. def filter_objects(doc, type_id, children=False):
  26.     def callback(op):
  27.         if op.CheckType(type_id):
  28.             yield op
  29.             if not children: return
  30.         for child in op.GetChildren():
  31.             for obj in callback(child):
  32.                 yield obj
  33.  
  34.     for obj in doc.GetObjects():
  35.         for o in callback(obj):
  36.             yield o
  37.  
  38. def main():
  39.     flname = c4d.storage.SaveDialog(force_suffix='txt')
  40.     if not flname:
  41.         return
  42.     if os.path.exists(flname) and not os.path.isfile(flname):
  43.         c4d.gui.MessageDialog('Invalid file-name.')
  44.         return
  45.  
  46.     try:
  47.         fl = open(flname, 'w')
  48.     except IOError, OSError:
  49.         c4d.gui.MessageDialog('Could not open file.')
  50.         return
  51.  
  52.     for cloner in filter_objects(doc, Omograph_cloner):
  53.         name = cloner.GetName().replace(delimiter_1, '\\%s' % delimiter_1)
  54.         fl.write(name + delimiter_1)
  55.         cache = cloner.GetCache()
  56.         if cache:
  57.             values = []
  58.             for clones in cache.GetChildren():
  59.                 pos = clones.GetMg().off
  60.                 values.extend([pos.x, pos.y, pos.z])
  61.             format = '%%.%df' % precision
  62.             line = delimiter_2.join(format % v for v in values)
  63.             fl.write(line)
  64.         fl.write('\n')
  65.  
  66.     fl.close()
  67.  
  68. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement