Advertisement
spookymunky

SymmThings 2.0 - Mirror Clone (VBS)

Mar 25th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '-----------------------------------------------------------------------------------------------------------------'
  2. 'This script will either clone or duplicate the selected object(s) depending on their type (e.g. polygon meshes 'and curves etc will be cloned, while lights / control objects etc will be duplicated), then setup mirror like 'expressions - inverted on scale x axis, position x axis, and rotation y and z axis, with the other expressions 'being a direct copy. If the selected object is a polygon or surface mesh then the clone will also get expressions 'linking its subdivision / SurfaceUV levels to the original.
  3.  
  4. 'If clones have already been created by this script (and still have -Clone in their name) and you run this on the 'original object again, it will duplicate both the selected object and its clone and rename them so that every 'object should have a direct -Clone .. e.g. if the duplicate of an object turns out to be cube21 its clone will be 'named cube21-Clone.
  5.  
  6. 'If you have more than one object selected then only the objects that don't end in -Clone are added to the 'collection for either duplication or cloning, so if you need to run it on a -Clone object then you must select it 'on its own. On the plus side you don't have to be too cautious when selecting objects if you want to quickly 'duplicate a large group of objects and their clones, aslong as all the non-clones you want are selected it 'doesn't matter how many(if any) -Clones are selected.. if that makes sense :).
  7. '-----------------------------------------------------------------------------------------------------------------'
  8.  
  9. dim oCol, oSelection, oSelecto, regEx, oCloneCheck, Match, Matches, oFinalSelect, oDupeStr, oDupeCol
  10. dim oDupes, oModelo, oName, oSelName, oParent1, oParent2, oClone, IsAClone
  11.  
  12. set regEx = New RegExp
  13.  
  14. 'Define a collection(oCol) for adding objects to
  15. Set oCol = CreateObject( "XSI.Collection" )
  16.  
  17. 'Check if an object is selected
  18. if application.selection.count > 0 Then
  19.  
  20.     Set oSelection = Application.Selection
  21.    
  22.     'Check if more than one object is selected
  23.     if application.selection.count > 1 Then
  24.    
  25.         for i = 0 to (oSelection.Count - 1)
  26.        
  27.             'Set a new Regex pattern that finds any letters after - at the end of its name
  28.             regEx.Pattern = "-[a-zA-Z]+$"
  29.            
  30.             'Reset oCloneCheck
  31.             oCloneCheck = "nothing"
  32.            
  33.             'Execute the regex on the selection
  34.             Set Matches = regEx.Execute(oSelection(i))
  35.             For Each Match in Matches
  36.                 oCloneCheck = Match.Value
  37.             Next
  38.            
  39.             'If the selection doesnt end in -Clone then add it to the oCol Collection.
  40.             if oCloneCheck <> "-Clone" then
  41.            
  42.                 Logmessage oSelection(i) & " is righteous and pure, added to oCol"
  43.                 oCol.add oSelection(i)
  44.                
  45.             else
  46.            
  47.                 Logmessage oSelection(i) & " was deemed an inferior being and rejected."
  48.                
  49.             end if
  50.            
  51.         next
  52.        
  53.     else
  54.    
  55.         'If only one object is selected, add it to the oCol Collection
  56.         oCol.add oSelection(0)
  57.        
  58.     end if
  59.  
  60. else
  61.  
  62.     'If no object is selected, start a picksession
  63.     LogMessage "Select an object"
  64.     PickObject "Select an object", " ", oSelecto
  65.     oCol.add oSelecto
  66.    
  67. end if
  68.  
  69. 'Create a collection to add objects to for selection at the end
  70. Set oFinalSelect = CreateObject( "XSI.Collection" )
  71.  
  72. for i = 0 to (oCol.count-1)
  73.  
  74.     if TypeName( oCol(i) ) = "X3DObject" or TypeName( oCol(i) ) = "Null" or TypeName( oCol(i) ) = "Model" or TypeName( oCol(i) ) = "Light" then
  75.    
  76.         set oSelecto = oCol(i)
  77.        
  78.         'Check if a clone of the selected object exists
  79.         oDupeStr = oCol(i)&"-Clone"
  80.         set oObj = Dictionary.GetObject( oDupeStr, false )
  81.  
  82.         if TypeName( oObj ) <> "Nothing" then
  83.                
  84.             'Create a collection and add the selected object and its already existing clone
  85.             Set oDupeCol = CreateObject("XSI.Collection")
  86.                            
  87.             oDupeCol.Add oSelecto
  88.             oDupeCol.Add oSelecto&"-Clone"
  89.                
  90.             'Duplicate the Collection
  91.             set oDupes = Duplicate (oDupeCol, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
  92.            
  93.             'Remove Model name from oDupes(0)
  94.             oModelo = oDupes(0).Model
  95.             oName = replace( oDupes(0), oModelo&".", "")
  96.            
  97.             'Rename the newly created clone
  98.             SetValue oDupes(1)&".Name", oName&"-Clone"
  99.            
  100.             'Check if the the new clone and the original selection share the same parent
  101.             oParent1 = oCol(0).Parent
  102.             oParent2 = oDupes(1).Parent
  103.            
  104.             if oParent1 <> oParent2 then
  105.            
  106.                 'If they don't, give the new clone the same parent as the selection
  107.                 ParentObj "B:" & oParent1, oDupes(1)
  108.                
  109.             end if
  110.            
  111.             LogMessage "Clone detected, " & oDupeCol(0) & " and " & oDupeCol(1) & " were duplicated (" & oDupes(0) & "), (" & oDupes(1) &")"
  112.             oFinalSelect.Add oDupes(0)
  113.            
  114.         else
  115.        
  116.             'If there is no -Clone detected and the selection is a suitable X3DObject clone it, otherwise duplicate
  117.             if TypeName( oCol(i) ) = "X3DObject" and  oCol(i).Type <> "wave" and oCol(i).Type <> "volume_deform" and oCol(i).Type <> "attractor" and oCol(i).Type <> "drag" and oCol(i).Type <> "eddy" and oCol(i).Type <> "fan" and oCol(i).Type <> "gravity" and oCol(i).Type <> "Toric_Force" and oCol(i).Type <> "turbulence" and oCol(i).Type <> "vortex" and oCol(i).Type <> "wind" and oCol(i).Type <> "standin" and oCol(i).Type <> "lattice" then
  118.            
  119.                 set oClone = Clone (oSelecto, , 1, 1, 0, 0, 1, 0, 1)
  120.                 IsAClone = "yes"
  121.                
  122.             else
  123.            
  124.                 set oClone = Duplicate (oSelecto, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
  125.                 IsAClone = "no"
  126.                
  127.             end if
  128.      
  129.             'Scale Expressions
  130.             SetExpr oClone&".kine.local.sclx", oSelecto&".kine.local.sclx*-1"
  131.             SetExpr oClone&".kine.local.scly", oSelecto&".kine.local.scly"
  132.             SetExpr oClone&".kine.local.sclz", oSelecto&".kine.local.sclz"
  133.      
  134.             'Rotation Expressions
  135.             SetExpr oClone&".kine.local.rotx", oSelecto&".kine.local.rotx"
  136.             SetExpr oClone&".kine.local.roty", oSelecto&".kine.local.roty*-1"
  137.             SetExpr oClone&".kine.local.rotz", oSelecto&".kine.local.rotz*-1"
  138.      
  139.             'Translation Expressions
  140.             SetExpr oClone&".kine.local.posx", oSelecto&".kine.local.posx*-1"
  141.             SetExpr oClone&".kine.local.posy", oSelecto&".kine.local.posy"
  142.             SetExpr oClone&".kine.local.posz", oSelecto&".kine.local.posz"
  143.      
  144.             'If object is a polymesh
  145.             if oSelecto.Type = "polymsh" then
  146.                
  147.                 'Make geometry approximation local
  148.                 MakeLocal oSelecto&".geomapprox", siDefaultPropagation
  149.                 MakeLocal oClone&".geomapprox", siDefaultPropagation
  150.                
  151.                 'Set subdivision level expresssions
  152.                 SetExpr oClone&".geomapprox.gapproxmosl", oSelecto&".geomapprox.gapproxmosl"
  153.                 SetExpr oClone&".geomapprox.gapproxmordrsl", oSelecto&".geomapprox.gapproxmordrsl"
  154.                
  155.             end if
  156.            
  157.             'If object is a surfmsh
  158.             if oSelecto.Type = "surfmsh" then
  159.                
  160.                 'Make geometry approximation local
  161.                 MakeLocal oSelecto&".geomapprox", siDefaultPropagation
  162.                 MakeLocal oClone&".geomapprox", siDefaultPropagation
  163.                
  164.                 'Set subdivision level expresssions
  165.                 SetExpr oClone&".geomapprox.gapproxvwustep", oSelecto&".geomapprox.gapproxvwustep"
  166.                 SetExpr oClone&".geomapprox.gapproxvwvstep", oSelecto&".geomapprox.gapproxvwvstep"
  167.                
  168.             end if
  169.        
  170.             'Set a new Regex pattern that finds any letters after - at the end of its name
  171.             regEx.Pattern = "-[a-zA-Z]+$"
  172.            
  173.             'Reset oMergedCheck
  174.             oMergedCheck = "nothing"
  175.            
  176.             'Execute the regex on the selection
  177.             Set Matches = regEx.Execute(oSelecto)
  178.             For Each Match in Matches
  179.                 oCloneCheck = Match.Value
  180.             Next
  181.            
  182.             'If the selection doesnt end in -MergedMesh then re-enable its selectability
  183.             if oMergedCheck <> "-MergedMesh" then
  184.                 SetValue oClone & ".visibility.selectability", True
  185.             end if
  186.            
  187.             'Remove Model name from oSelecto
  188.             oModelo = oSelecto.Model
  189.             oSelName = replace( oSelecto, oModelo&".", "")
  190.            
  191.             'Rename The Clone
  192.             SetValue oClone & ".Name", oSelName&"-Clone"
  193.        
  194.             'Select original object
  195.             SelectObj oSelecto
  196.  
  197.             if IsAClone = "yes" then   
  198.        
  199.                 LogMessage "Created a mirror clone of " & oSelecto & " (" & oSelName & "-Clone)"
  200.                
  201.             else
  202.            
  203.                 LogMessage "Created a mirror duplicate of " & oSelecto & " (" & oSelName & "-Clone)"
  204.                
  205.             end if
  206.            
  207.             oFinalSelect.Add oSelecto
  208.        
  209.         end if
  210.  
  211.     else
  212.    
  213.         LogMessage oCol(i) & " is an invalid selection type (" & TypeName( oCol(i) ) & ")"
  214.        
  215.     end if
  216.  
  217. next
  218.  
  219. 'If there is more than one item in oCol then select the objects in the oFinalSelect collection
  220. if oCol.Count > 1 then
  221.     SelectObj oFinalSelect
  222. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement