probiner

MultiApplyICEop

Dec 26th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. ## from http://xsisupport.com/2011/12/10/scripting-applying-an-ice-compound-to-multiple-objects/ and fixed by probiner
  2.  
  3. from siutils import si      # Application
  4. if Application.Version().split('.')[0]>= "11":
  5.         si = si()                   # win32com.client.Dispatch('XSI.Application')
  6.  
  7. from siutils import log     # LogMessage
  8. from siutils import C       # win32com.client.constants
  9. from siutils import disp    # win32com.client.Dispatch
  10.  
  11. siut = disp('XSI.Utils')
  12. sifact = disp('XSI.Factory')
  13. siuitk = disp('XSI.UIToolkit')
  14. sisel = si.Selection
  15.  
  16.  
  17. #
  18. # Pop up a browser to select a compound
  19. #
  20. def getCompound():
  21.     initialDir = siut.BuildPath( si.InstallationPath( C.siUserPath ), "Data", "Compounds" )
  22.  
  23.     oFileBrowser = siuitk.FileBrowser
  24.     oFileBrowser.DialogTitle = "Select compound to apply"
  25.     oFileBrowser.InitialDirectory = initialDir
  26.     oFileBrowser.Filter = "All Files (*.*)|*.*||"
  27.     oFileBrowser.ShowOpen()
  28.  
  29.     return oFileBrowser.FilePathName
  30.  
  31. #
  32. # Apply op to
  33. # - the selected objects
  34. # OR
  35. # - the members of a selected group
  36. #
  37. def getTargetObjects():
  38.     objects = disp( "XSI.Collection" )
  39.  
  40.     if sisel.Count == 0:
  41.         log( "Please select either some objects or a group" )
  42.     elif sisel(0).IsClassOf( C.siGroupID ):
  43.         objects = sisel(0).Members
  44.     else:
  45.         objects = sisel
  46.  
  47.     return objects
  48.  
  49. #
  50. # Do it...
  51. #
  52. objects = getTargetObjects()    
  53. sCompound = getCompound()
  54.  
  55. if sCompound != "" and objects.Count > 0:
  56.     for o in objects:
  57.         si.ApplyICEOp( sCompound, o.FullName )
Advertisement
Add Comment
Please, Sign In to add comment