Advertisement
spookymunky

SymmThings 2.0 - Scale CL Cluster (VBS)

Mar 25th, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '-----------------------------------------------------------------------------------------------------------------'
  2. 'To use this script you must first create a point / edge cluster of all the components along the center that you 'want included in the scale op. The cluster should be named CL, but if it isn't this script wil do a few (very) 'simple checks for clusters it could use. Probably the best way is to have the cluster you want to use selected 'when you run this, and it will ask if you want to rename it to CL, otherwise it will look for a cluster named 'Edge, then a cluster named Point and ask if you want to use those hehe, clicking no to one check will just let 'the script go on to the next, at the end it will check if there is any CL cluster, if not it will cancel out.
  3.  
  4. 'Once it runs, it will scale the CL cluster to 0 on the selected object(s) x axis, and move the new MoveComponent 'Op into the animation stack.
  5.  
  6. '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 movecomponentop(s) are all in the modelling stack.
  7.  
  8. 'If you really don't want to freeze anything, you could do this manually by selecting the CL cluster and running 'my Zero X script and move the new movecomponent op manually (drag and drop :) into the animation stack.
  9. '-----------------------------------------------------------------------------------------------------------------'
  10.  
  11. dim oSelecto, ScriptCancel, BP, POINTstr, EDGEstr, CLstr, oPointObj, oEdgeObj, oCLObj, oMCobj, pref
  12. dim regEx, Match, Matches, oSubdCtrlCheck, MoveComponentCount, MCstr, StopLoop, JustIncaseAbort
  13.  
  14. 'Set up a regExp for later use
  15. set regEx = New RegExp
  16.  
  17. 'Define a collection(oCol) for adding objects to
  18. Set oCol = CreateObject( "XSI.Collection" )
  19.  
  20. 'Check if an object is selected
  21. if Application.Selection.count > 1 Then
  22.  
  23.     'Add the application selection to oCol
  24.     Set oSelection = Application.Selection
  25.    
  26.     for i = 0 to (oSelection.Count - 1)
  27.    
  28.         'Set a new Regex pattern that finds any letters after - at the end of its name
  29.         regEx.Pattern = "-[a-zA-Z]+$"
  30.            
  31.         'Reset oSubdCtrlCheck
  32.         oSubdCtrlCheck = "Nothing"
  33.            
  34.         'Execute the regex on the selection
  35.         Set Matches = regEx.Execute(oSelection(i))
  36.         For Each Match in Matches
  37.             oSubdCtrlCheck = Match.Value
  38.         Next
  39.            
  40.         'If the selection doesnt end in -SubdCtrl then add it to the oCol Collection.
  41.         if oSubdCtrlCheck <> "-SubdCtrl" then
  42.            
  43.             Logmessage oSelection(i) & " is pure evil, added to oCol"
  44.             oCol.add oSelection(i)
  45.                
  46.         else
  47.            
  48.             Logmessage oSelection(i) & " is suspiciously nice, rejected"
  49.                
  50.         end if
  51.        
  52.     next   
  53.  
  54. elseIf Application.Selection.count = 1 Then
  55.  
  56.     oCol.add Application.Selection(0)
  57.        
  58. else   
  59.  
  60.     'If no object is selected, start a picksession
  61.     LogMessage "Select The Control Mesh (-Modelling)"
  62.     PickObject "Select The Control Mesh (-Modelling)", " ", oSelecto
  63.  
  64.     'Add Picksession object to oCol
  65.     oCol.add oSelecto
  66.    
  67. end if
  68.  
  69. for i = 0 to (oCol.count-1)
  70.  
  71.     set oSelecto = oCol(i)
  72.  
  73.     'Check if the cluster is selected instead of the mesh, saves having to re-select the mesh after creating the CL cluster
  74.     if TypeName( oSelecto ) = "Cluster" then
  75.    
  76.         oSelecto = oSelecto.Parent3DObject
  77.        
  78.     end if
  79.  
  80.     'Make sure the selection is a Polymesh, if it isn't then give the user one last try to select one.
  81.     set oSelecto = Dictionary.GetObject( oSelecto, false )
  82.    
  83.     if oSelecto.Type = "polymsh" then
  84.    
  85.         ScriptCancel = "no"
  86.        
  87.     else
  88.    
  89.         LogMessage oSelecto & " is a " & oSelecto.Type & ", not a polymsh"
  90.            
  91.         BP = XSIUIToolkit.Msgbox( oSelecto & " is not a polymsh, do you want to select something else?", 4, "No Polygon Mesh Selected" )
  92.        
  93.             if BP = 6 then
  94.            
  95.                 PickObject "Please select a polygon mesh", " ", oSelecto
  96.                
  97.                 if oSelecto.Type = "polymsh" then
  98.            
  99.                     ScriptCancel = "no"    
  100.        
  101.                 else               
  102.                        
  103.                     XSIUIToolkit.Msgbox "Bah, I give up.. " & oSelecto & " is a " & oSelecto.Type & " !", 1, "No Polygon Mesh Selected"
  104.                     Logmessage "Script Cancelled - Next time select a Polygon Mesh instead of a " & oSelecto.Type & "! :)"
  105.  
  106.                     ScriptCancel = "yes"
  107.  
  108.                 end if
  109.                
  110.             else
  111.                    
  112.                 ScriptCancel = "yes"
  113.  
  114.             end if
  115.     end if
  116.  
  117.     POINTstr = oSelecto & ".polymsh.cls.Point"
  118.     EDGEstr = oSelecto & ".polymsh.cls.edge.clslist.Edge"
  119.     CLstr = oSelecto & ".polymsh.cls.CL"
  120.     set oPointObj = Dictionary.GetObject( POINTstr, false )
  121.     set oEdgeObj = Dictionary.GetObject( EDGEstr, false )
  122.     set oCLObj = Dictionary.GetObject( CLstr, false )
  123.  
  124.     'Check if CL / point / edge cluster exists
  125.     if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName( oEdgeObj ) = "Nothing" and TypeName( oPointObj ) = "Nothing" and TypeName( ocol(i) ) <> "Cluster" then
  126.        
  127.         XSIUIToolkit.Msgbox "You need to create an edge / point cluster of the center loop for " & oSelecto & " and name it CL", 1, "No CL Cluster Found"
  128.         Logmessage "You need to create an edge / point cluster of the center loop for " & oSelecto & " and name it CL"
  129.                    
  130.         ScriptCancel = "yes"
  131.  
  132.     end if
  133.    
  134.     if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName( oCol(i) ) = "Cluster" then
  135.         Logmessage "Selection is a cluster"
  136.        
  137.         BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but you had a cluster selected when you ran this script, do you want to rename it to CL ? (" & oCol(i) & ")", 4, "Edge Cluster Detected" )
  138.        
  139.             if BP = 6 then
  140.                
  141.                 LogMessage oCol(i).FullName
  142.                 SetValue oCol(i) & ".Name" , "CL"
  143.                 logmessage "Selected cluster renamed to CL"
  144.                 set oCLObj = Dictionary.GetObject( CLstr, false )
  145.            
  146.             end if
  147.            
  148.     end if
  149.    
  150.     'If no CL cluster exists but an Edge cluster exists, ask if user wants to rename it to CL
  151.     if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName ( oEdgeObj ) = "Cluster" and oCol(i).Name <> "Edge" then
  152.         Logmessage "Edge Cluster Detected"
  153.  
  154.         BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but an Edge cluster was detected, do you want to rename it to CL ?", 4, "Edge Cluster Detected" )
  155.  
  156.             if BP = 6 then
  157.            
  158.                 SetValue oSelecto & ".polymsh.cls.edge.clslist.Edge.Name", "CL"
  159.                 logmessage "Edge cluster renamed to CL"
  160.                 set oCLObj = Dictionary.GetObject( CLstr, false )
  161.            
  162.             end if
  163.                
  164.     end if
  165.  
  166.     'If no CL cluster exists but a Point cluster exists, ask if user wants to rename it to CL
  167.     if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName ( oPointObj ) = "Cluster" and oCol(i).Name <> "Point" then
  168.         LogMessage "Point Cluster Detected"
  169.        
  170.         BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but a Point cluster was detected, do you want to rename it to CL ?", 4, "Point Cluster Detected" )
  171.            
  172.             if BP = 6 then
  173.            
  174.                 SetValue oSelecto & ".polymsh.cls.Point.Name", "CL"
  175.                 logmessage "Point cluster renamed to CL"
  176.                 set oCLObj = Dictionary.GetObject( CLstr, false )
  177.                
  178.             end if
  179.                
  180.     end if
  181.    
  182.     if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" then
  183.        
  184.         ScriptCancel = "yes"
  185.         LogMessage oSelecto & " was skipped since it has no CL cluster"
  186.    
  187.     end if
  188.  
  189.     'Check if a MoveComponent op already exists
  190.     MCstr = oSelecto & ".polymsh.movecomponentop"
  191.     set oMCobj = Dictionary.GetObject( MCstr, false )
  192.    
  193.     if TypeName( oMCobj ) <> "Nothing" and ScriptCancel = "no" then
  194.    
  195.         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 & "?" )
  196.        
  197.             if BP = 6 then
  198.            
  199.                 LogMessage "Freezing Object"
  200.                 FreezeObj oSelecto
  201.                
  202.             elseIf BP = 7 then
  203.    
  204.                 LogMessage "Move Component operator already in place, determining what number the new one will be"
  205.            
  206.                 'Reset some variables
  207.                 JustIncaseAbort = 0
  208.                 MoveComponentCount = 0
  209.                 StopLoop = "no"
  210.                
  211.                 '-----------------------------Loop Start-----------------------------'
  212.                
  213.                 do
  214.                
  215.                 'Add 1 onto the counter that will be used to see how many movecomponent ops exist
  216.                 MoveComponentCount = MoveComponentCount + 1
  217.                
  218.                 'Check to see if a movecomponent op with the count number exists e.g. movecomponentop[15]
  219.                 MCstr = oSelecto & ".polymsh.movecomponentop["&MoveComponentCount&"]"
  220.                 set oMCobj = Dictionary.GetObject( MCstr, false )
  221.                
  222.                 if TypeName( oMCobj ) = "Nothing" then
  223.                     StopLoop = "yes"
  224.                 end if
  225.                
  226.                 'Increment an abort counter to stop an infinite loop
  227.                 JustIncaseAbort = JustIncaseAbort + 1
  228.                
  229.                 Loop Until StopLoop = "yes" or JustIncaseAbort = 10000
  230.                
  231.                 '-----------------------------Loop Finish-----------------------------'
  232.                
  233.                 'If the abort number has been reached then cancel the script
  234.                 if JustIncaseAbort = 10000 then
  235.                     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 :)"
  236.                     ScriptCancel = "yes"
  237.                 end if
  238.                
  239.                 LogMessage oSelecto & " had " & MoveComponentCount & " movecomponentops"
  240.                
  241.                 if ScriptCancel = "no" then
  242.                
  243.                     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" )
  244.                    
  245.                         if BP = 6 then
  246.                        
  247.                             MoveComponentCount = MoveComponentCount - 1
  248.                            
  249.                             set DeleteMoveOp = Dictionary.GetObject( oSelecto&".movecomponentop[" & MoveComponentCount & "]", false )
  250.                             DeleteObj DeleteMoveOp
  251.                            
  252.                             MCstr = oSelecto&".polymsh.movecomponentop["&MoveComponentCount&"]"
  253.                            
  254.                             LogMessage oSelecto & ".polymsh.movecomponentop[" & MoveComponentCount & "] was deleted"
  255.                            
  256.                         elseIf BP = 2 then
  257.                        
  258.                             LogMessage "Cancelling Script"
  259.                             ScriptCancel = "yes"
  260.                        
  261.                         end if
  262.                
  263.                 end if
  264.                
  265.             else
  266.            
  267.                 LogMessage "Cancelling Script"
  268.                 ScriptCancel = "yes"
  269.            
  270.             end if
  271.        
  272.     else
  273.        
  274.         MCstr = oSelecto & ".polymsh.movecomponentop"
  275.        
  276.     end if
  277.  
  278.     if ScriptCancel = "no" then
  279.  
  280.         'Get the status of proportional modelling setting
  281.         pref = GetUserPref ("3D_TRANSFO_PROPORTIONAL_CHANGED")
  282.  
  283.         'If proportional modelling was enabled, turn it off
  284.         if pref = 1 then
  285.             SetUserPref "3D_TRANSFO_PROPORTIONAL_CHANGED", 0
  286.         end if
  287.  
  288.         'Select the CL cluster and scale it to 0 on the x axis
  289.         Scale oCLObj, 0, 1, 1, siRelative, siParent, siObj, siX, , , , , , , , 0
  290.         SelectObj oSelecto
  291.  
  292.         'Move the scale op to the animation stack
  293.         MoveOperatorAfter oSelecto & ".polymsh", MCstr, oSelecto & ".polymsh.shapemarker"
  294.  
  295.         'If proportional modelling was previously enabled, turn it back on
  296.         if pref = 1 then
  297.             SetUserPref "3D_TRANSFO_PROPORTIONAL_CHANGED", 1
  298.         end if
  299.  
  300.         LogMessage oSelecto&".polymsh.cls.CL" & " was scaled to 0 on the x axis and the MoveComponent op transferred to the animation stack. "
  301.        
  302.     end if
  303.  
  304. Next
  305.  
  306. SelectObj oCol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement