Advertisement
spookymunky

SymmThings 2.01 - Scale CL Cluster (VBS)

Aug 1st, 2013
199
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.        
  116.     end if
  117.  
  118.     CLExists = "no"
  119.  
  120.     for c=0 to c=1
  121.         on error resume next   
  122.         Dictionary.GetObject( oSelecto.activeprimitive.geometry.clusters("CL") )
  123.         if ( err = 0 ) then
  124.             CLExists = "yes"
  125.         end if
  126.     next
  127.  
  128.     EdgeExists = "no"
  129.  
  130.     for e=0 to e=1
  131.         on error resume next   
  132.         Dictionary.GetObject( oSelecto.activeprimitive.geometry.clusters("Edge") )
  133.         if ( err = 0 ) then
  134.             EdgeExists = "yes"
  135.         end if
  136.     next
  137.    
  138.     PointExists = "no"
  139.  
  140.     for p=0 to p=1
  141.         on error resume next   
  142.         Dictionary.GetObject( oSelecto.activeprimitive.geometry.clusters("Point") )
  143.         if ( err = 0 ) then
  144.             PointExists = "yes"
  145.         end if
  146.     next
  147.  
  148.     logmessage "CL Cluster : " & CLExists & " | Edge Cluster : " & EdgeExists & " | Point Cluster : " & PointExists
  149.    
  150.     'Check if CL / point / edge cluster exists
  151.     if ScriptCancel = "no" and CLExists = "no" and EdgeExists = "no" and PointExists = "no" and TypeName( ocol(i) ) <> "Cluster" then
  152.        
  153.         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"
  154.         Logmessage "You need to create an edge / point cluster of the center loop for " & oSelecto & " and name it CL"
  155.        
  156.         ScriptCancel = "yes"
  157.        
  158.     end if
  159.    
  160.     'if no CL Cluster exists but the selection is a cluster, ask if user wants to rename it to CL
  161.     if ScriptCancel = "no" and CLExists = "no" and TypeName( oCol(i) ) = "Cluster" then
  162.         Logmessage "Selection is a cluster"
  163.        
  164.         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" )
  165.        
  166.             if BP = 6 then
  167.                
  168.                 'rename the selected cluster to CL - Thanks to myara for the fix :)
  169.                 oSelecto.activeprimitive.geometry.clusters(oCol(i).Name).name = "CL"
  170.                
  171.                 logmessage oCol(i).Name & " renamed to CL"
  172.                 CLExists = "yes"
  173.                
  174.             end if
  175.        
  176.     end if
  177.    
  178.     'If no CL cluster exists but an Edge cluster exists, ask if user wants to rename it to CL
  179.     if ScriptCancel = "no" and CLExists = "no" and EdgeExists = "yes" then
  180.         Logmessage "Edge Cluster Detected"
  181.        
  182.         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" )
  183.        
  184.             if BP = 6 then
  185.                
  186.                 oSelecto.activeprimitive.geometry.clusters("Edge").name = "CL"
  187.                 logmessage "Edge cluster renamed to CL"
  188.                 CLExists = "yes"
  189.                
  190.             end if
  191.        
  192.     end if
  193.  
  194.     'If no CL cluster exists but a Point cluster exists, ask if user wants to rename it to CL
  195.     if ScriptCancel = "no" and CLExists = "no" and PointExists = "yes" then
  196.         LogMessage "Point Cluster Detected"
  197.        
  198.         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" )
  199.        
  200.             if BP = 6 then
  201.                
  202.                 oSelecto.activeprimitive.geometry.clusters("Point").name = "CL"
  203.                
  204.                 logmessage "Point cluster renamed to CL"
  205.                 CLExists = "yes"
  206.                
  207.             end if
  208.        
  209.     end if
  210.    
  211.     if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" then
  212.        
  213.         ScriptCancel = "yes"
  214.         LogMessage oSelecto & " was skipped since it has no CL cluster"
  215.        
  216.     end if
  217.  
  218.     'Check if a MoveComponent op already exists
  219.     MCstr = oSelecto & ".polymsh.movecomponentop"
  220.     set oMCobj = Dictionary.GetObject( MCstr, false )
  221.    
  222.     if TypeName( oMCobj ) <> "Nothing" and ScriptCancel = "no" then
  223.        
  224.         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 & "?" )
  225.        
  226.             if BP = 6 then
  227.                
  228.                 LogMessage "Freezing Object"
  229.                 FreezeObj oSelecto
  230.                
  231.             elseIf BP = 7 then
  232.                
  233.                 LogMessage "Move Component operator already in place, determining what number the new one will be"
  234.                
  235.                 'Reset some variables
  236.                 JustIncaseAbort = 0
  237.                 MoveComponentCount = 0
  238.                 StopLoop = "no"
  239.                
  240.                 '-----------------------------Loop Start-----------------------------'
  241.                
  242.                 do
  243.                
  244.                 'Add 1 onto the counter that will be used to see how many movecomponent ops exist
  245.                 MoveComponentCount = MoveComponentCount + 1
  246.                
  247.                 'Check to see if a movecomponent op with the count number exists e.g. movecomponentop[15]
  248.                 MCstr = oSelecto & ".polymsh.movecomponentop["&MoveComponentCount&"]"
  249.                 set oMCobj = Dictionary.GetObject( MCstr, false )
  250.                
  251.                 if TypeName( oMCobj ) = "Nothing" then
  252.                     StopLoop = "yes"
  253.                 end if
  254.                
  255.                 'Increment an abort counter to stop an infinite loop
  256.                 JustIncaseAbort = JustIncaseAbort + 1
  257.                
  258.                 Loop Until StopLoop = "yes" or JustIncaseAbort = 10000
  259.                
  260.                 '-----------------------------Loop Finish-----------------------------'
  261.                
  262.                 'If the abort number has been reached then cancel the script
  263.                 if JustIncaseAbort = 10000 then
  264.                     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 :)"
  265.                     ScriptCancel = "yes"
  266.                 end if
  267.                
  268.                 LogMessage oSelecto & " had " & MoveComponentCount & " movecomponentops"
  269.                
  270.                 if ScriptCancel = "no" then
  271.                    
  272.                     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" )
  273.                    
  274.                         if BP = 6 then
  275.                            
  276.                             MoveComponentCount = MoveComponentCount - 1
  277.                            
  278.                             set DeleteMoveOp = Dictionary.GetObject( oSelecto&".movecomponentop[" & MoveComponentCount & "]", false )
  279.                             DeleteObj DeleteMoveOp
  280.                            
  281.                             MCstr = oSelecto&".polymsh.movecomponentop["&MoveComponentCount&"]"
  282.                            
  283.                             LogMessage oSelecto & ".polymsh.movecomponentop[" & MoveComponentCount & "] was deleted"
  284.                            
  285.                         elseIf BP = 2 then
  286.                            
  287.                             LogMessage "Cancelling Script"
  288.                             ScriptCancel = "yes"
  289.                            
  290.                         end if
  291.                    
  292.                 end if
  293.                
  294.             else
  295.                
  296.                 LogMessage "Cancelling Script"
  297.                 ScriptCancel = "yes"
  298.                
  299.             end if
  300.        
  301.     else
  302.        
  303.         MCstr = oSelecto & ".polymsh.movecomponentop"
  304.        
  305.     end if
  306.  
  307.     if ScriptCancel = "no" then
  308.        
  309.         'Get the status of proportional modelling setting
  310.         pref = GetUserPref ("3D_TRANSFO_PROPORTIONAL_CHANGED")
  311.        
  312.         'If proportional modelling was enabled, turn it off
  313.         if pref = 1 then
  314.             SetUserPref "3D_TRANSFO_PROPORTIONAL_CHANGED", 0
  315.         end if
  316.        
  317.         'Select the CL cluster and scale it to 0 on the x axis
  318.         Scale oSelecto.activeprimitive.geometry.clusters("CL"), 0, 1, 1, siRelative, siParent, siObj, siX, , , , , , , , 0
  319.         SelectObj oSelecto
  320.        
  321.         'Move the scale op to the animation stack
  322.         MoveOperatorAfter oSelecto & ".polymsh", MCstr, oSelecto & ".polymsh.shapemarker"
  323.        
  324.         'If proportional modelling was previously enabled, turn it back on
  325.         if pref = 1 then
  326.             SetUserPref "3D_TRANSFO_PROPORTIONAL_CHANGED", 1
  327.         end if
  328.        
  329.         LogMessage oSelecto&".polymsh.cls.CL" & " was scaled to 0 on the x axis and the MoveComponent op transferred to the animation stack. "
  330.        
  331.     end if
  332.  
  333. Next
  334.  
  335. SelectObj oCol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement