Advertisement
spookymunky

SymmThings 2.0 - Scale Component (VBS)

Mar 25th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '-----------------------------------------------------------------------------------------------------------------'
  2. 'This will scale the selected components (edges/vertices/polys) to 0 on the object's x axis, and move the new 'MoveComponent Op into the animation stack.
  3.  
  4. 'If there is already a movecomponentop in place the script will ask you if you want to freeze the object, if you 'select no, it will count how many move operators exist and then ask if you want to delete the highest one found, 'click yes if you have only one movecomponentop op in either the shape modelling or animation stacks, or click no 'if the existing movecomponentops are all in the modelling stack. Since xsi renames operators depending where they 'are in the stack, and I have yet to find a way of determining where they are.. sigh, this is the best I could 'come up with for now :P
  5.  
  6. 'If you really don't want to freeze anything, you could do this manually by selecting the edges or vertices you 'want then run my Zero X script and move the new movecomponent op manually (drag and drop) into the animation 'stack.
  7. '-----------------------------------------------------------------------------------------------------------------'
  8.  
  9. dim oSel, oSelecto, ScriptCancel, oMCobj, BP, pref, MCstr, MoveComponentCount, StopLoop, JustIncaseAbort
  10. dim oSelHack, oSelName
  11.  
  12. set oSel = application.selection(0)
  13.  
  14. 'Set up a regExp for later use
  15. set regEx = New RegExp
  16.  
  17. 'Reset ScriptCancel
  18. ScriptCancel = "no"
  19.  
  20. 'Check if the selection is a subcomponent and use a silly hack to get the full name (including model name) of the object.. since I couldnt find a normal way to do it :P
  21. if oSel.Type = "polySubComponent" then
  22.  
  23.     'Replace poly[ in the name of the selection with something I can find in regex
  24.     oSelHack = replace (osel, "poly[", "IsuckAtRegex")
  25.    
  26.     'Set a regex pattern to find everything up to (and annoyingly including) the "IsuckAtRegex" part I just added
  27.     regEx.Pattern = "^.*IsuckAtRegex"  
  28.     Set Matches = regEx.Execute(oSelHack)
  29.    
  30.     For Each Match in Matches
  31.         oSelName = Match.Value
  32.     Next
  33.    
  34.     'Get rid of ".IsuckAtRegex" to get the final output I want
  35.     oSelName = replace( oSelName, ".IsuckAtRegex", ""
  36.    
  37.     set oSelecto = Dictionary.GetObject( oSelName, false )
  38.     LogMessage "poly subcomponent of " & oSelecto & " detected"
  39.  
  40. elseif oSel.Type = "pntSubComponent" then
  41.  
  42.     oSelHack = replace (osel, "pnt[", "IsuckAtRegex")
  43.     regEx.Pattern = "^.*IsuckAtRegex"
  44.     Set Matches = regEx.Execute(oSelHack)
  45.     For Each Match in Matches
  46.         oSelName = Match.Value
  47.     Next
  48.     oSelName = replace( oSelName, ".IsuckAtRegex", "")
  49.     set oSelecto = Dictionary.GetObject( oSelName, false )
  50.     LogMessage "point subcomponent of " & oSelecto & " detected"
  51.    
  52. elseif oSel.Type = "edgeSubComponent" then
  53.  
  54.     oSelHack = replace (osel, "edge[", "IsuckAtRegex")
  55.     regEx.Pattern = "^.*IsuckAtRegex"
  56.     Set Matches = regEx.Execute(oSelHack)
  57.     For Each Match in Matches
  58.         oSelName = Match.Value
  59.     Next
  60.     oSelName = replace( oSelName, ".IsuckAtRegex", "")
  61.     set oSelecto = Dictionary.GetObject( oSelName, false )
  62.     LogMessage "edge subcomponent of " & oSelecto & " detected"
  63.    
  64. else
  65.  
  66.  
  67.     LogMessage "No components selected - Script Cancelled"
  68.     XSIUIToolkit.Msgbox "No components selected - You need to select the components you want scaled to 0 on the object's X axis, then run this again", 1, "No Components Detected"
  69.     ScriptCancel = "yes"
  70.    
  71. end if
  72.  
  73.     'Check if a MoveComponent op already exists
  74.     MCstr = ".polymsh.movecomponentop"
  75.     set oMCobj = Dictionary.GetObject( MCstr, false )
  76.    
  77.     if TypeName( oMCobj ) <> "Nothing" and ScriptCancel = "no" then
  78.    
  79.         BP = XSIUIToolkit.Msgbox( "Do you want to freeze " & oSelecto & " ? : If there is more than one movecomponent op in either the Shape Modelling or Animation stacks then this won't work (clicking no will determine how many move component ops there are, then ask if you want to delete the highest one)", 3, "Move Component Ops Detected, Freeze " & oselecto & "?" )
  80.        
  81.             if BP = 6 then
  82.            
  83.                 LogMessage "Freezing Object"
  84.                 FreezeObj oSelecto
  85.                
  86.             elseIf BP = 7 then
  87.    
  88.                 LogMessage "Move Component operator already in place, determining what number the new one will be"
  89.            
  90.                 'Reset some variables
  91.                 JustIncaseAbort = 0
  92.                 MoveComponentCount = 0
  93.                 StopLoop = "no"
  94.                
  95.                 '-----------------------------Loop Start-----------------------------'
  96.                
  97.                 do
  98.                
  99.                 'Add 1 onto the counter that will be used to see how many movecomponent ops exist
  100.                 MoveComponentCount = MoveComponentCount + 1
  101.                
  102.                 'Check to see if a movecomponent op with the count number exists e.g. movecomponentop[15]
  103.                 MCstr = oSelecto & ".polymsh.movecomponentop["&MoveComponentCount&"]"
  104.                 set oMCobj = Dictionary.GetObject( MCstr, false )
  105.                
  106.                 if TypeName( oMCobj ) = "Nothing" then
  107.                     StopLoop = "yes"
  108.                 end if
  109.                
  110.                 'Increment an abort counter to stop an infinite loop
  111.                 JustIncaseAbort = JustIncaseAbort + 1
  112.                
  113.                 Loop Until StopLoop = "yes" or JustIncaseAbort = 10000
  114.                
  115.                 '-----------------------------Loop Finish-----------------------------'
  116.                
  117.                 'If the abort number has been reached then cancel the script
  118.                 if JustIncaseAbort = 10000 then
  119.                     LogMessage "Either something has gone horribly wrong or you have more than 10,000 move component ops ?? in which case it might be time to freeze the modelling stack :)"
  120.                     ScriptCancel = "yes"
  121.                 end if
  122.                
  123.                 LogMessage oSelecto & " had " & MoveComponentCount & " movecomponentops"
  124.                
  125.                 if ScriptCancel = "no" then
  126.                
  127.                     BP = XSIUIToolkit.Msgbox( MoveComponentCount & " movemomponent ops were found, is there one (singular) in either the Shape Modelling or Animation stack ? ( clicking yes will delete MoveComponent[" & MoveComponentCount - 1 &"] )", 3, "Move Component Ops Detected" )
  128.                    
  129.                         if BP = 6 then
  130.                        
  131.                             MoveComponentCount = MoveComponentCount - 1
  132.                            
  133.                             DeleteObj oSelecto & ".movecomponentop[" & MoveComponentCount & "]"
  134.                            
  135.                             MCstr = oSelecto & ".polymsh.movecomponentop[" & MoveComponentCount & "]"
  136.                            
  137.                             LogMessage oSelecto & ".polymsh.movecomponentop[" & MoveComponentCount & "] was deleted"
  138.                            
  139.                         elseIf BP = 2 then
  140.                        
  141.                             LogMessage "Cancelling Script"
  142.                             ScriptCancel = "yes"
  143.                        
  144.                         end if
  145.                
  146.                 end if
  147.                
  148.             else
  149.            
  150.                 LogMessage "Cancelling Script"
  151.                 ScriptCancel = "yes"
  152.            
  153.             end if
  154.        
  155.     else
  156.        
  157.         MCstr = oSelecto & ".polymsh.movecomponentop"
  158.        
  159.     end if
  160.  
  161.  
  162. if ScriptCancel = "no" then
  163.  
  164.     'Get the status of proportional modelling setting
  165.     pref = GetUserPref ("3D_TRANSFO_PROPORTIONAL_CHANGED")
  166.  
  167.     'If proportional modelling was enabled, turn it off
  168.     if pref = 1 then
  169.         SetUserPref "3D_TRANSFO_PROPORTIONAL_CHANGED", 0
  170.     end if
  171.  
  172.     'Scale the selected components to 0 on the x axis and move the op to the animation stack
  173.     Scale , 0, 1, 1, siRelative, siParent, siObj, siX, , , , , , , , 0
  174.     MoveOperatorAfter oSelecto & ".polymsh", MCstr, oSelecto & ".polymsh.shapemarker"
  175.  
  176.     'If proportional modelling was previously enabled, turn it back on
  177.     if pref = 1 then
  178.         SetUserPref "3D_TRANSFO_PROPORTIONAL_CHANGED", 1
  179.     end if
  180.  
  181.     LogMessage "Selected components were scaled to 0 on the x axis, the operation should have been moved to the animation stack"
  182.  
  183. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement