Advertisement
spookymunky

XSI - Select Child Materials (vbs)

Jun 30th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dim ChildMaterials, ObjCollection, oSelecto, oBaseObj, oCls, oBaseClusters, oChildren, oItem, oClusters
  2.  
  3. 'Create a collection to add the materials to
  4. Set ChildMaterials = CreateObject( "XSI.Collection" )
  5.  
  6. 'Create a collection for adding objects to
  7. Set ObjCollection = CreateObject( "XSI.Collection" )
  8.  
  9. if application.selection.count = 0 then
  10.  
  11.     LogMessage "Select an object"
  12.     PickObject "Select an object", " ", oSelecto
  13.    
  14.     'add oSelecto to ObjCollection collection
  15.     ObjCollection.add oSelecto
  16.  
  17. else
  18.    
  19.     'Add the application selection to ObjCollection collection
  20.     Set oSelecto = Application.Selection
  21.    
  22.     for i = 0 to (oSelecto.Count - 1)
  23.        
  24.         ObjCollection.add oSelecto(i)
  25.    
  26.     next
  27.    
  28. end if
  29.  
  30. for x = 0 to (ObjCollection.count - 1)
  31.    
  32.     set oBaseObj = ObjCollection(x)
  33.    
  34.     DeselectAll
  35.    
  36.     'select the object's material
  37.     SelectMaterialsUsedBy oBaseObj
  38.    
  39.     'add the material to the collection
  40.     ChildMaterials.add application.Selection(0)
  41.    
  42.     'if it is a polygon / nurb surface then look for clusters and add their materials too
  43.     if oBaseObj.type = "polymsh" or oBaseObj.type = "surfmsh" then
  44.    
  45.         set oBaseClusters = oBaseObj.ActivePrimitive.Geometry.Clusters
  46.              
  47.                
  48.         for each oCls in oBaseClusters
  49.                    
  50.             DeselectAll
  51.                    
  52.             'select the cluster's material
  53.             SelectMaterialsUsedBy oCls
  54.                    
  55.             'add it to the ChildMaterials collection
  56.             ChildMaterials.add application.Selection(0)
  57.                    
  58.         next
  59.                
  60.     end if  
  61.  
  62.     'use findchildren to find the children ;)
  63.     Set oChildren = oBaseObj.FindChildren2
  64.  
  65.     'Itterate a simple material selection for each child and add to the collective
  66.     for i = 0 to (oChildren.Count - 1)
  67.        
  68.        DeselectAll
  69.        
  70.        'Select the child's material
  71.        SelectMaterialsUsedBy oChildren(i)
  72.        
  73.        'add it to the ChildMaterials collection
  74.        ChildMaterials.add application.Selection(0)
  75.        
  76.        'if it is a polygon / nurb surface then look for clusters and add their materials too
  77.        if oChildren(i).type = "polymsh" or oChildren(i).type = "surfmsh" then
  78.        
  79.           for each oItem in oChildren
  80.                
  81.              on error resume next
  82.          
  83.              set oClusters = oItem.ActivePrimitive.Geometry.Clusters
  84.              
  85.              if ( err = 0 ) then
  86.                
  87.                 for each oCls in oClusters
  88.                    
  89.                    DeselectAll
  90.                    
  91.                    'select the cluster's material
  92.                    SelectMaterialsUsedBy oCls
  93.                    
  94.                    'add it to the ChildMaterials collection
  95.                    ChildMaterials.add application.Selection(0)
  96.                    
  97.                 next
  98.                
  99.              end if  
  100.  
  101.           next
  102.        
  103.        end if
  104.  
  105.     next
  106.    
  107. next
  108.  
  109. 'Select the collection
  110. selectobj ChildMaterials
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement