Advertisement
spookymunky

SymmThings 2.0 - Obj To Model (VBS)

Mar 25th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '-----------------------------------------------------------------------------------------------------------------'
  2. 'This script creates a new model for each of the selected items and matches all transforms, then the item is 'parented to the new model and it's own transforms are reset.
  3.  
  4. 'If the selected item is either a clone or an instance created by one of my mirror scripts (and still end in '-Clone or -Instance) it will also check if each SRT channel has an expression, and if they do it will disable 'them and give the newly created model the same mirror like expressions the clone/instance would originally have 'had.
  5.  
  6. 'The primary intent of this script is so you can offset the clones / instances on one side so they aren't 'completely symmetrical but still retain the mirror like expressions. For example, if you used one of my mirror 'scripts to create a characters teeth, you can run this on all the cloned / instanced teeth then offset them 'slightly so they aren't perfect and still have the ability to quickly re-arrange the originals and have the other 'side match up if say you need to widen the jaw or something :)
  7. '-----------------------------------------------------------------------------------------------------------------'
  8.  
  9. dim oCol, oSelection, oSelecto, oParent1, oParent2, oModelo, oSelName, oModelName, oSelOrig
  10. dim regEx, oCloInstCheck, Match, Matches, oCloneCheck, oInstaCheck, CheckExp
  11. dim oExpExist, oExpStr, oExpPosx, oExpPosy, oExpPosz, oExpRotx
  12. dim oExpRoty, oExpRotz, oExpSclx, oExpScly, oExpSclz
  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.     'Convert application selection into a Collection named oCol
  21.     Set oSelection = Application.Selection
  22.    
  23.     for i = 0 to (oSelection.Count - 1)
  24.         oCol.add oSelection(i)
  25.     next
  26.    
  27. else
  28.  
  29.     'If no object is selected, start a picksession
  30.     LogMessage "Select a Model"
  31.     PickObject "Select a Model", " ", oSelecto
  32.     oCol.add oSelecto
  33.  
  34. end if
  35.  
  36. for i = 0 to (oCol.count-1)
  37.  
  38.     set oSelecto = oCol(i)
  39.     oParent1 = oCol(i).Parent
  40.    
  41.     'Remove model name from selection
  42.     oModelo = oSelecto.Model
  43.     oSelName = replace( oSelecto, oModelo&".", "")
  44.     oModelName = oSelName & "-Model"
  45.  
  46.     'Create an empty model, match translation to the clone and parent the clone to model
  47.     DeselectAll
  48.     Preferences.SetPreferenceValue "Interaction.autoinspect", false
  49.     CreateModel , oModelName, , oModel
  50.     Preferences.SetPreferenceValue "Interaction.autoinspect", true
  51.  
  52.     MatchTransform "B:" & oModel, oSelecto, siSRT
  53.        
  54.     'Set a new Regex pattern that finds any letters after - at the end of its name
  55.     set regEx = New RegExp
  56.     regEx.Pattern = "-[a-zA-Z]+$"
  57.    
  58.     'Reset oCloInstCheck
  59.     oCloInstCheck = "Nothing"
  60.    
  61.     'Reset CheckExp
  62.     CheckExp = "No"
  63.            
  64.     'Execute the regex on the selection
  65.     Set Matches = regEx.Execute(oSelName)
  66.     For Each Match in Matches
  67.         oCloInstCheck = Match.Value
  68.     Next
  69.    
  70.     'Check if the selected object ends in -Clone
  71.     if oCloInstCheck = "-Clone" then
  72.    
  73.         oSelOrig = replace (oSelecto, "-Clone", "" )
  74.        
  75.         'Reset oCloneCheck
  76.         oCloneCheck = "Nothing"
  77.        
  78.         'Check if the non-clone exists
  79.         set oCloneCheck = Dictionary.GetObject( oSelOrig, false )
  80.        
  81.         if TypeName( oCloneCheck ) <> "Nothing" then       
  82.        
  83.             LogMessage oSelecto & " should be an instance of " & oSelOrig & ", setting up the expressions for " & oModel & " accordingly"
  84.             CheckExp = "yes"
  85.        
  86.         end if
  87.    
  88.     'Check if the selected object ends in -Instance
  89.     elseIf oCloInstCheck = "-Instance" then
  90.        
  91.         oSelOrig = replace (oSelecto, "-Instance", "" )
  92.        
  93.         'Reset oInstaCheck
  94.         oInstaCheck = "Nothing"
  95.        
  96.         'Check if the non-Instance exists
  97.         set oInstaCheck = Dictionary.GetObject( oSelOrig, false )
  98.        
  99.         if TypeName( oInstaCheck ) <> "Nothing" then       
  100.        
  101.             LogMessage oSelecto & " should be a clone of " & oSelOrig & ", setting up the expressions for " & oModel & " accordingly"
  102.             CheckExp = "yes"
  103.        
  104.         end if
  105.        
  106.     end if
  107.  
  108.     'If the object is either a clone or an instance then check each expression individually to see if they still exist
  109.     'If they do, disable the objects versions and give the new model the mirror type expressions the object would have originally had
  110.     if CheckExp = "yes" then
  111.  
  112.         oExpExist = "no"
  113.        
  114.         ExpStr = oSelecto & ".kine.local.pos.posx.Expression"
  115.         set oExpPosx = Dictionary.GetObject( ExpStr, false )
  116.         if TypeName( oExpPosx ) <> "Nothing" then
  117.             SetValue oSelecto & ".kine.local.pos.posx.Expression.Active", False
  118.             SetExpr oModel&".kine.local.posx", oSelOrig&".kine.local.posx*-1"
  119.             oExpExist = "yes"
  120.         end if
  121.        
  122.         ExpStr = oSelecto & ".kine.local.pos.posy.Expression"
  123.         set oExpPosy = Dictionary.GetObject( ExpStr, false )
  124.         if TypeName( oExpPosy ) <> "Nothing" then
  125.             SetValue oSelecto & ".kine.local.pos.posy.Expression.Active", False
  126.             SetExpr oModel&".kine.local.posy", oSelOrig&".kine.local.posy"
  127.             oExpExist = "yes"
  128.         end if
  129.        
  130.         ExpStr = oSelecto & ".kine.local.pos.posz.Expression"
  131.         set oExpPosz = Dictionary.GetObject( ExpStr, false )
  132.         if TypeName( oExpPosz ) <> "Nothing" then
  133.             SetValue oSelecto & ".kine.local.pos.posz.Expression.Active", False
  134.             SetExpr oModel&".kine.local.posz", oSelOrig&".kine.local.posz"
  135.             oExpExist = "yes"
  136.         end if
  137.        
  138.         ExpStr = oSelecto & ".kine.local.ori.euler.rotx.Expression"
  139.         set oExpRotx = Dictionary.GetObject( ExpStr, false )
  140.         if TypeName( oExpRotx ) <> "Nothing" then
  141.             SetValue oSelecto & ".kine.local.ori.euler.rotx.Expression.Active", False
  142.             SetExpr oModel&".kine.local.rotx", oSelOrig&".kine.local.rotx"
  143.             oExpExist = "yes"
  144.         end if
  145.        
  146.         ExpStr = oSelecto & ".kine.local.ori.euler.roty.Expression"
  147.         set oExpRoty = Dictionary.GetObject( ExpStr, false )
  148.         if TypeName( oExpRoty ) <> "Nothing" then
  149.             SetValue oSelecto & ".kine.local.ori.euler.roty.Expression.Active", False
  150.             SetExpr oModel&".kine.local.roty", oSelOrig&".kine.local.roty*-1"
  151.             oExpExist = "yes"
  152.         end if
  153.        
  154.         ExpStr = oSelecto & ".kine.local.ori.euler.rotz.Expression"
  155.         set oExpRotz = Dictionary.GetObject( ExpStr, false )
  156.         if TypeName( oExpRotz ) <> "Nothing" then
  157.             SetValue oSelecto & ".kine.local.ori.euler.rotz.Expression.Active", False
  158.             SetExpr oModel&".kine.local.rotz", oSelOrig&".kine.local.rotz*-1"
  159.             oExpExist = "yes"
  160.         end if
  161.        
  162.         ExpStr = oSelecto & ".kine.local.scl.sclx.Expression"
  163.         set oExpSclx = Dictionary.GetObject( ExpStr, false )
  164.         if TypeName( oExpSclx ) <> "Nothing" then
  165.             SetValue oSelecto & ".kine.local.scl.sclx.Expression.Active", False
  166.             SetExpr oModel&".kine.local.sclx", oSelOrig&".kine.local.sclx*-1"
  167.             oExpExist = "yes"
  168.         end if
  169.            
  170.         ExpStr = oSelecto & ".kine.local.scl.scly.Expression"
  171.         set oExpScly = Dictionary.GetObject( ExpStr, false )
  172.         if TypeName( oExpScly ) <> "Nothing" then
  173.             SetValue oSelecto & ".kine.local.scl.scly.Expression.Active", False
  174.             SetExpr oModel&".kine.local.scly", oSelOrig&".kine.local.scly"
  175.             oExpExist = "yes"
  176.         end if
  177.        
  178.         ExpStr = oSelecto & ".kine.local.scl.sclz.Expression"
  179.         set oExpSclz = Dictionary.GetObject( ExpStr, false )
  180.         if TypeName( oExpSclz ) <> "Nothing" then
  181.             SetValue oSelecto & ".kine.local.scl.sclz.Expression.Active", False
  182.             SetExpr oModel&".kine.local.sclz", oSelOrig&".kine.local.sclz"
  183.             oExpExist = "yes"
  184.         end if
  185.        
  186.     end if
  187.    
  188.     'Parent oSelecto to the new model
  189.     ParentObj "B:" & oModel, oSelecto
  190.    
  191.     'Reset all transforms on the input object
  192.     ResetTransform oModel & "." & oSelName, siObj, siSRT, siXYZ
  193.  
  194.     'Check if the the new clone and the first object in selection share the same parent
  195.     'If they don't, give the new Model the same parent as the the clone
  196.     oParent2 = oModel.Parent
  197.     if oParent1 <> oParent2 then  
  198.         ParentObj "B:" & oParent1, oModel
  199.     end if
  200.    
  201.     If oExpExist = "yes" then
  202.         LogMessage oModel & " was created for " & oSelName
  203.         LogMessage oSelName & "'s expressions were disabled, and expressions were added to " & oModel & ", inversly linking it to " & oSelOrig  
  204.     else
  205.         LogMessage oModel & " was created for " & oSelName
  206.     end if
  207.      
  208. next
  209.  
  210. SelectObj oCol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement