Advertisement
spookymunky

SymmThings 2.0 - Cloned Symmetry (VBS)

Mar 25th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '-----------------------------------------------------------------------------------------------------------------'
  2. 'This script is pretty much the same as my other Cloned Symmetry script, but without the slice polygons / gator 'ops. It will duplicate the selected polygon mesh(s), leaving the original hidden but otherwise untouched. If the 'polygon mesh's center is not exactly on the cut line, you may need to adjust it, Generally I just hold control to 'enable snapping(with all objects and points enabled) and drag the center along it's X-axis until it snaps to one 'of the centerline points.
  3.  
  4. 'Next the new duplicate mesh(*-Modelling) is cloned(*-ClonedHalf) and expressions put in place linking it to the 'Modelling half, with the x axis expression being multiplied by -1, then both halves are merged.
  5.  
  6. 'The merged mesh(*-MergedMesh) then gets it's selectability disabled, and expressions added to link it's 'subdivision levels to a newly created cube(*-SubdCtrl) that is parented to the modelling mesh. If you want to 'control the MergedMesh's subd levels directly just delete the SubdCtrl cube. To re-enable Selectability on the 'MergedMesh either open up its visibility settings and tick the selectability box, or select the MergedMesh from 'explorer and click "Select-Selectability-Toggle Selected Objects".
  7.  
  8. 'To view the Modelling half as a proper mesh instead of a wireframe, re-enable override object properties for the 'camera viewport, and to undo everything just branch select the Modelling mesh and delete it, then unhide the 'original.
  9.  
  10. 'I have also added expressions linking the final result (-MergedMesh) to the modelling half since I noticed if you 'were using the modelling object to move things around the center of MergedMesh was staying at zero. If this 'causes any problems you could just remove all animation for mergedmesh, otherwise when you are finished modelling 'freeze MergedMesh's modelling stack, branch select -Modelling and delete, you should have a final mesh to work 'with then that has no expressions but its SRT will be where you'd expect :)
  11.  
  12. 'And finally, if the mesh you have selected ends with one of the naming conventions I have used (e.g. sphere-'Modelling), or versions already exist that end like that, then it will try and undo things that may have been put 'in place by my script previously, and run through a simple loop checking incrementally for the next available 'name. This lets you create new copys of either the original object or the finished result quickly without having 'the names get all messy.
  13. '-----------------------------------------------------------------------------------------------------------------'
  14.  
  15. dim oCol, oSelection, oSelecto, oFinalSelect, BP, ScriptCancel, oDupe, oClone, oMerge, oGenOp, oSubdCtrl
  16. dim oModelo, oSelName, oSubdCtrlCheck, AfterDashCheck, oSelectoSubdOgl, oSelectoSubdRdr
  17. dim oMergeScale, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, CtrlXtrans, CtrlYtrans, CtrlZtrans, CtrlScale
  18. dim oDupeScaleX, oDupeScaleY, oDupeScaleZ, oSelTest3
  19. dim oDupeRotX, oDupeRotY, oDupeRotZ, oSelTest4
  20. dim oDupePosX, oDupePosY, oDupePosZ, oSelTest5
  21. dim regEx, oModellingCheck, oModellingCheck2, Match, Matches, NumberCheck, objNumber, JustIncaseAbort, oSelTest
  22. dim oExpExist, ExpStr, oExpCheck, oSelTest2, WereRenamed, oShrinkWrapCheck, SWStr
  23.  
  24. 'Set up a regExp for later use
  25. set regEx = New RegExp
  26.  
  27. 'Define a collection(oCol) for adding objects to
  28. Set oCol = CreateObject( "XSI.Collection" )
  29.  
  30. 'Check if something is selecteds
  31. if Application.Selection.count > 1 Then
  32.  
  33.     'Add the application selection to oCol
  34.     Set oSelection = Application.Selection
  35.    
  36.     for i = 0 to (oSelection.Count - 1)
  37.    
  38.         'Set a new Regex pattern that finds any letters after - at the end of its name
  39.         regEx.Pattern = "-[a-zA-Z]+$"
  40.            
  41.         'Reset oSubdCtrlCheck
  42.         oSubdCtrlCheck = "Nothing"
  43.            
  44.         'Execute the regex on the selection
  45.         Set Matches = regEx.Execute(oSelection(i))
  46.         For Each Match in Matches
  47.             oSubdCtrlCheck = Match.Value
  48.         Next
  49.            
  50.         'If the selection doesnt end in -SubdCtrl then add it to the oCol Collection.
  51.         if oSubdCtrlCheck <> "-SubdCtrl" then
  52.            
  53.             Logmessage oSelection(i) & " smells of roses, added to oCol"
  54.             oCol.add oSelection(i)
  55.                
  56.         else
  57.            
  58.             Logmessage oSelection(i) & " smells of cheese, totally rejected!"
  59.                
  60.         end if
  61.        
  62.     next   
  63.  
  64. elseIf Application.Selection.count = 1 Then
  65.  
  66.     oCol.add Application.Selection(0)
  67.        
  68. else
  69.  
  70.     'If no object is selected, start a picksession
  71.     LogMessage "Select a polymesh"
  72.     PickObject "Select a polymesh", " ", oSelecto
  73.  
  74.     'Add Picksession object to oCol
  75.     oCol.add oSelecto
  76.    
  77. end if
  78.  
  79. 'Create a collection to add objects to for selection at the end
  80. Set oFinalSelect = CreateObject( "XSI.Collection" )
  81.  
  82. for i = 0 to (oCol.count-1)
  83.     set oSelecto = oCol(i)
  84.    
  85.     'Make sure the oSelecto is a Polymesh, if it isn't then give the user one last try to select one
  86.     set oSelecto = Dictionary.GetObject( oSelecto, false )
  87.    
  88.     if oSelecto.Type = "polymsh" then
  89.    
  90.         ScriptCancel = "no"
  91.        
  92.     else
  93.    
  94.         LogMessage oSelecto & " is a " & oSelecto.Type & ",not a polymsh"
  95.        
  96.         BP = XSIUIToolkit.Msgbox( oSelecto & " is not a polymsh, do you want to select something else?", 4, "No Polygon Mesh Selected" )
  97.        
  98.             if BP = 6 then
  99.            
  100.                 PickObject "Please select a polygon mesh", " ", oSelecto
  101.                
  102.                 if oSelecto.Type = "polymsh" then  
  103.        
  104.                     ScriptCancel = "no"
  105.            
  106.                 else               
  107.                    
  108.                     XSIUIToolkit.Msgbox "Bah, I give up.. " & oSelecto & " is a " & oSelecto.Type & " !", 1, "No Polygon Mesh Selected"
  109.                     Logmessage "Script Cancelled - Next time select a Polygon Mesh instead of a " & oSelecto.Type & "! :)"
  110.  
  111.                     ScriptCancel = "yes"
  112.  
  113.                 end if
  114.                    
  115.             else
  116.            
  117.             LogMessage "Script Cancelled - " & oSelecto & " isn't a polygon mesh"
  118.             ScriptCancel = "yes"
  119.  
  120.             end if
  121.            
  122.     end if
  123.    
  124.     if ScriptCancel = "no" then
  125.  
  126.         'Set a new Regex pattern that finds any letters after - at the end of its name
  127.         regEx.Pattern = "-[a-zA-Z]+$"
  128.                
  129.         'Reset AfterDashCheck
  130.         AfterDashCheck = "Nothing"
  131.                
  132.         'Execute the regex on the selection
  133.         Set Matches = regEx.Execute(oSelecto)
  134.         For Each Match in Matches
  135.             AfterDashCheck = Match.Value
  136.         Next
  137.        
  138.         'Reset SliceAway
  139.         SliceAway = "no"
  140.            
  141.         'If the selection ends in -MergedMesh ask the user if they want to cut it
  142.         if AfterDashCheck = "-MergedMesh" or AfterDashCheck = "-Gator" then
  143.  
  144.             LogMessage oSelecto & " looks like a merged result, should I cut ?"
  145.             BP = XSIUIToolkit.Msgbox( oSelecto & " looks like a merged result, do you want to cut it ?", 3, "Merged Mesh Detected" )
  146.        
  147.                 if BP = 6 then
  148.                    
  149.                     LogMessage "OK, slicing " & oSelecto & ", gonna slice him up real good!"
  150.                     SliceAway = "yes"
  151.                    
  152.                 elseIf BP = 7 then
  153.                        
  154.                     LogMessage "Alrighty, no slice and dice for " & oSelecto & ", sorry for bothering you ! :)"
  155.                     SliceAway = "no"
  156.                    
  157.                 else
  158.                        
  159.                     LogMessage "Skipping " & oSelecto & " completely"
  160.                     ScriptCancel = "yes"
  161.                        
  162.                 end if
  163.                    
  164.         end if
  165.  
  166.         if ScriptCancel = "no" then
  167.  
  168.             'Store the original object's subdivision levels for later use
  169.             set oSelectoSubdOgl = Dictionary.GetObject( oSelecto & ".geomapprox.gapproxmosl", false )
  170.             set oSelectoSubdRdr = Dictionary.GetObject( oSelecto & ".geomapprox.gapproxmordrsl", false )
  171.             oSelectoSubdOgl = oSelectoSubdOgl.Value
  172.             oSelectoSubdRdr = oSelectoSubdRdr.Value
  173.  
  174.             'Duplicate original mesh
  175.             set oDupe = Duplicate (oSelecto, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
  176.            
  177.             'Remove any animation on gemoetry approximation (incase the input object had any)
  178.             RemoveAnimation oDupe & ".geomapprox.gapproxmosl", 10
  179.             RemoveAnimation oDupe & ".geomapprox.gapproxmordrsl", 10
  180.        
  181.             'Set oDupe's subdivision levels to the same value as the input object
  182.             SetValue oDupe & ".geomapprox.gapproxmosl", oSelectoSubdOgl
  183.             SetValue oDupe & ".geomapprox.gapproxmordrsl", oSelectoSubdRdr
  184.  
  185.             if SliceAway = "yes" then
  186.            
  187.                 'Slice the duplicate in half, set the reference plane to local, and delete -x polys
  188.                 ApplyTopoOp "SlicePolygons", oDupe, siUnspecified, siPersistentOperation
  189.                 SetValue oDupe&".polymsh.slicepolygonsop.planeref", 1
  190.                 SetValue oDupe&".polymsh.slicepolygonsop.sliceaction", 3
  191.                
  192.             end if
  193.  
  194.             'Create a clone of the duplicate
  195.             set oClone = Clone (oDupe, , 1, 1, 0, 0, 1, 0, 1)
  196.  
  197.             'Merge the duplicate and clone, transfer all properties
  198.             oGenOp = ApplyGenOp ("MeshMerge", , oDupe &","& oClone, 3, siPersistentOperation, siKeepGenOpInputs)
  199.             oMerge = replace (oGenOp, ".polymsh.mergemesh", "")
  200.             TransferAllPropertiesAcrossGenOp oGenOp, oMerge, , True, True
  201.            
  202.             'Set the Merge tolerance to 0.1
  203.             SetValue oGenOp & ".tolerance", 0.1
  204.  
  205.             'Create a cube named SubdCtrl to control the merged mesh's subdivision levels via expressions
  206.             Preferences.SetPreferenceValue "Interaction.autoinspect", false
  207.             set oSubdCtrl = CreatePrim ("Cube", "MeshSurface", "SubdCtrl")
  208.             Preferences.SetPreferenceValue "Interaction.autoinspect", true
  209.            
  210.             'Make SubdCtrl and mergedmesh's geometry approximation local
  211.             MakeLocal oMerge & ".geomapprox", siDefaultPropagation
  212.             MakeLocal oSubdCtrl & ".geomapprox", siDefaultPropagation
  213.            
  214.             'Link MergedMesh's geometry approximation to SubdCtrl via expressions
  215.             SetExpr oMerge & ".geomapprox.gapproxmosl", oSubdCtrl & ".geomapprox.gapproxmosl"
  216.             SetExpr oMerge & ".geomapprox.gapproxmordrsl", oSubdCtrl & ".geomapprox.gapproxmordrsl"
  217.  
  218.             'Match SubdCtrl's subdivision levels to the original object
  219.             SetValue oSubdCtrl & ".geomapprox.gapproxmosl", oSelectoSubdOgl
  220.             SetValue oSubdCtrl & ".geomapprox.gapproxmordrsl", oSelectoSubdRdr
  221.  
  222.             'Give SubdCtrl the same material as the merged mesh
  223.             AssignMaterial oMerge & ".*," & oSubdCtrl, siLetLocalMaterialsOverlap
  224.  
  225.             'Set SubdCtrl's Visibility options
  226.             SetValue oSubdCtrl & ".visibility.rendvis", False
  227.             SetValue oSubdCtrl & ".visibility.primray", False
  228.             SetValue oSubdCtrl & ".visibility.scndray", False
  229.             SetValue oSubdCtrl & ".visibility.shdwcast", False
  230.             SetValue oSubdCtrl & ".visibility.shdwrecv", False
  231.             SetValue oSubdCtrl & ".visibility.trnscast", False
  232.             SetValue oSubdCtrl & ".visibility.trnsvis", False
  233.             SetValue oSubdCtrl & ".visibility.globcast", False
  234.             SetValue oSubdCtrl & ".visibility.globvis", False
  235.             SetValue oSubdCtrl & ".visibility.causvis", False
  236.  
  237.             'Set the clone's visibility options
  238.             SetValue oClone & ".visibility.viewvis", False
  239.             SetValue oClone & ".visibility.rendvis", False
  240.             SetValue oClone & ".visibility.primray", False
  241.             SetValue oClone & ".visibility.scndray", False
  242.             SetValue oClone & ".visibility.shdwcast", False
  243.             SetValue oClone & ".visibility.shdwrecv", False
  244.             SetValue oClone & ".visibility.trnscast", False
  245.             SetValue oClone & ".visibility.trnsvis", False
  246.             SetValue oClone & ".visibility.globcast", False
  247.             SetValue oClone & ".visibility.globvis", False
  248.             SetValue oClone & ".visibility.causvis", False
  249.            
  250.             'Set oClone's subdivision levels to 0
  251.             SetValue oClone & ".geomapprox.gapproxmosl", 0
  252.             SetValue oClone & ".geomapprox.gapproxmordrsl", 0
  253.  
  254.             'Set the duplicate's Visibility options
  255.             SetValue oDupe & ".visibility.viewvis", True
  256.             SetValue oDupe & ".visibility.rendvis", False
  257.            
  258.             if AfterDashCheck <> "-Modelling" then
  259.            
  260.                 'Set the duplicate's Display options (0 is wireframe, 5 is bounding box)
  261.                 MakeLocal oDupe & ".display", siDefaultPropagation
  262.                 SetValue oDupe & ".display.staticsel", 0
  263.                 SetValue oDupe & ".display.intsel", 0
  264.                 SetValue oDupe & ".display.playbacksel", 0
  265.                 SetValue oDupe & ".display.staticunselnear", 5
  266.                 SetValue oDupe & ".display.intunselnear", 5
  267.                 SetValue oDupe & ".display.playbackunselnear", 5
  268.                 SetValue oDupe & ".display.staticunselfar", 5
  269.                 SetValue oDupe & ".display.intunselfar", 5
  270.                 SetValue oDupe & ".display.playbackunselfar", 5
  271.                
  272.             end if
  273.  
  274.             'Disable the merged mesh's Selectability
  275.             SetValue oMerge & ".visibility.selectability", False
  276.  
  277.             'Disable Camera's override object properties option
  278.             SetValue "Camera.camdisp.mixviewmode", True
  279.  
  280.             'Change the duplicate's wireframe display colour
  281.             SetValue oDupe & ".display.wirecolorr", 0.12
  282.             SetValue oDupe & ".display.wirecolorg", 0.14
  283.             SetValue oDupe & ".display.wirecolorb", 0.18
  284.  
  285.             'Set the clone's scale expressions linking it to the modelling half
  286.             SetExpr oClone & ".kine.local.sclx", oDupe & ".kine.local.sclx*-1"
  287.             SetExpr oClone & ".kine.local.scly", oDupe & ".kine.local.scly"
  288.             SetExpr oClone & ".kine.local.sclz", oDupe & ".kine.local.sclz"
  289.  
  290.             'Set the clone's rotation expressions linking it to the modelling half
  291.             SetExpr oClone & ".kine.local.rotx", oDupe & ".kine.local.rotx"
  292.             SetExpr oClone & ".kine.local.roty", oDupe & ".kine.local.roty"
  293.             SetExpr oClone & ".kine.local.rotz", oDupe & ".kine.local.rotz"
  294.  
  295.             'Set the clone's translation expressions linking it to the modelling half
  296.             SetExpr oClone & ".kine.local.posx", oDupe & ".kine.local.posx"
  297.             SetExpr oClone & ".kine.local.posy", oDupe & ".kine.local.posy"
  298.             SetExpr oClone & ".kine.local.posz", oDupe & ".kine.local.posz"
  299.            
  300.             'Store oDupe's SRT to use for matching up oMerge's Center
  301.             oDupeScaleX = GetValue (oSelecto & ".kine.Global.scl.sclx")
  302.             oDupeScaleY = GetValue (oSelecto & ".kine.Global.scl.sclY")
  303.             oDupeScaleZ = GetValue (oSelecto & ".kine.Global.scl.sclZ")
  304.  
  305.             oDupeRotX = GetValue (oSelecto & ".kine.Global.ori.euler.rotx")
  306.             oDupeRotY = GetValue (oSelecto & ".kine.Global.ori.euler.rotY")
  307.             oDupeRotZ = GetValue (oSelecto & ".kine.Global.ori.euler.rotZ")
  308.  
  309.             oDupePosX = GetValue (oSelecto & ".kine.Global.pos.posx")
  310.             oDupePosY = GetValue (oSelecto & ".kine.Global.pos.posY")
  311.             oDupePosZ = GetValue (oSelecto & ".kine.Global.pos.posZ")
  312.  
  313.             'Match oMerge's Center to oDupe's SRT
  314.             Translate oMerge, oDupePosX, oDupePosY, oDupePosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
  315.             Rotate oMerge, oDupeRotX, oDupeRotY, oDupeRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  316.             Scale oMerge, oDupeScaleX, oDupeScaleY, oDupeScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  317.            
  318.             'Set the Merged Mesh's scale expressions linking it to the modelling half
  319.             SetExpr oMerge & ".kine.local.sclx", oDupe & ".kine.local.sclx"
  320.             SetExpr oMerge & ".kine.local.scly", oDupe & ".kine.local.scly"
  321.             SetExpr oMerge & ".kine.local.sclz", oDupe & ".kine.local.sclz"
  322.  
  323.             'Set the Merged Mesh's rotation expressions linking it to the modelling half
  324.             SetExpr oMerge & ".kine.local.rotx", oDupe & ".kine.local.rotx"
  325.             SetExpr oMerge & ".kine.local.roty", oDupe & ".kine.local.roty"
  326.             SetExpr oMerge & ".kine.local.rotz", oDupe & ".kine.local.rotz"
  327.  
  328.             'Set the Merged Mesh's translation expressions linking it to the modelling half
  329.             SetExpr oMerge & ".kine.local.posx", oDupe & ".kine.local.posx"
  330.             SetExpr oMerge & ".kine.local.posy", oDupe & ".kine.local.posy"
  331.             SetExpr oMerge & ".kine.local.posz", oDupe & ".kine.local.posz"
  332.            
  333.             'Get oMerge's bounding box co-ordinates to use in setting up relative values for SubdCtrl
  334.             GetBBox oMerge, TRUE, Xmin, Ymin, Zmin, Xmax, Ymax, Zmax
  335.    
  336.             oMergeScale = ( ( ( Xmax - Xmin ) / 2 ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 3
  337.            
  338.             CtrlXtrans = ( Xmin + Xmax ) / 2
  339.             CtrlYtrans = Ymax + ( oMergeScale / 2.2 )
  340.             CtrlZtrans = ( Zmin + Zmax ) / 2
  341.            
  342.             CtrlScale = oMergeScale * 0.01
  343.                
  344.             'Move and scale SubdCtrl using the above values
  345.             Scale oSubdCtrl, CtrlScale, CtrlScale, CtrlScale, siRelative, siGlobal, siObj, siXYZ, , , , , , , , 0
  346.             Translate oSubdCtrl, CtrlXtrans, CtrlYtrans, CtrlZtrans, siAbsolute , siGlobal, siObj, siXYZ, , , , , , , , , , 0
  347.            
  348.             'Add the SubdCtrl object to the oFinalSelect collection
  349.             oFinalSelect.Add oSubdCtrl
  350.            
  351.             'Remove the model name from selection
  352.             oModelo = oSelecto.Model
  353.             oSelName = replace( oSelecto, oModelo&".", "")
  354.                
  355.             'Set some dictionary lookups to check if anything created by this script in the past still exists
  356.             oSelTest = oCol(i) & "-Modelling"
  357.             set ModellingTest = Dictionary.GetObject( oSelTest, false )
  358.             oSelTest = oCol(i) & "-ClonedHalf"
  359.             set ClonedTest = Dictionary.GetObject( oSelTest, false )
  360.             oSelTest = oCol(i) & "-MergedMesh"
  361.             set MergedTest = Dictionary.GetObject( oSelTest, false )
  362.             oSelTest = oCol(i) & "-Gator"
  363.             set GatorTest = Dictionary.GetObject( oSelTest, false )
  364.  
  365.             'Reset WereRenamed
  366.             WereRenamed = 0
  367.                
  368.             'If the selected object is already created by one of my scripts, or has objects related to one of my scripts, find a new name for it and remove any annoyingness :P
  369.             if AfterDashCheck = "-MergedMesh" or AfterDashCheck = "-Gator" or AfterDashCheck = "-Modelling" or TypeName( ModellingTest ) <> "Nothing" or TypeName( ClonedTest ) <> "Nothing" or TypeName( MergedTest ) <> "Nothing" or TypeName( GatorTest ) <> "Nothing" then
  370.                    
  371.                 if AfterDashCheck = "-MergedMesh" or AfterDashCheck = "-Gator" then
  372.                    
  373.                     LogMessage oSelName & " is already a merged result, removing expressions and finding a new name for it to keep things nice!"
  374.                     SetValue oDupe & ".visibility.selectability", True
  375.                     oSelName = Replace (oSelName, AfterDashCheck, "")
  376.                        
  377.                     oExpExist = "no"
  378.                
  379.                     ExpStr = oDupe & ".kine.local.scl.sclx.Expression"
  380.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  381.                     if TypeName( oExpCheck ) <> "Nothing" then
  382.                         RemoveAnimation oDupe & ".kine.local.sclx", 1
  383.                         oExpExist = "yes"
  384.                     end if
  385.                            
  386.                     ExpStr = oDupe & ".kine.local.scl.scly.Expression"
  387.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  388.                     if TypeName( oExpCheck ) <> "Nothing" then
  389.                         RemoveAnimation oDupe & ".kine.local.scly", 1
  390.                         oExpExist = "yes"
  391.                     end if
  392.                        
  393.                     ExpStr = oDupe & ".kine.local.scl.sclz.Expression"
  394.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  395.                     if TypeName( oExpCheck ) <> "Nothing" then
  396.                         RemoveAnimation oDupe & ".kine.local.sclz", 1
  397.                         oExpExist = "yes"
  398.                     end if
  399.                        
  400.                     ExpStr = oDupe & ".kine.local.ori.euler.rotx.Expression"
  401.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  402.                     if TypeName( oExpCheck ) <> "Nothing" then
  403.                         RemoveAnimation oDupe & ".kine.local.rotx", 1
  404.                         oExpExist = "yes"
  405.                     end if
  406.                        
  407.                     ExpStr = oDupe & ".kine.local.ori.euler.roty.Expression"
  408.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  409.                     if TypeName( oExpCheck ) <> "Nothing" then
  410.                         RemoveAnimation oDupe & ".kine.local.roty", 1
  411.                         oExpExist = "yes"
  412.                     end if
  413.                        
  414.                     ExpStr = oDupe & ".kine.local.ori.euler.rotz.Expression"
  415.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  416.                     if TypeName( oExpCheck ) <> "Nothing" then
  417.                         RemoveAnimation oDupe & ".kine.local.rotz", 1
  418.                         oExpExist = "yes"
  419.                     end if
  420.                        
  421.                     ExpStr = oDupe & ".kine.local.pos.posx.Expression"
  422.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  423.                     if TypeName( oExpCheck ) <> "Nothing" then
  424.                         RemoveAnimation oDupe & ".kine.local.posx", 1
  425.                         oExpExist = "yes"
  426.                     end if
  427.                        
  428.                     ExpStr = oDupe & ".kine.local.pos.posy.Expression"
  429.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  430.                     if TypeName( oExpCheck ) <> "Nothing" then
  431.                         RemoveAnimation oDupe & ".kine.local.posy", 1
  432.                         oExpExist = "yes"
  433.                     end if
  434.                        
  435.                     ExpStr = oDupe & ".kine.local.pos.posz.Expression"
  436.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  437.                     if TypeName( oExpCheck ) <> "Nothing" then
  438.                         RemoveAnimation oDupe & ".kine.local.posz", 1
  439.                         oExpExist = "yes"
  440.                     end if
  441.                        
  442.                 elseIf AfterDashCheck = "-Modelling" then
  443.                        
  444.                     LogMessage oSelName & " is a Modelling half, finding a new name for it to keep things nice!"
  445.                     oSelName = Replace (oSelName, "-Modelling", "")
  446.                        
  447.                     'Check if the new modelling half has a shrink wrap op, if it does, freeze it
  448.                     SWStr = oDupe & ".polymsh.shrinkwrap"
  449.                     set oShrinkWrapCheck = Dictionary.GetObject( SWStr, false )
  450.                     if TypeName( oShrinkWrapCheck ) <> "Nothing" then
  451.                         FreezeObj oDupe & ".polymsh.shrinkwrap"
  452.                         LogMessage SWStr & " was Frozen"
  453.                     end if
  454.                        
  455.                 else
  456.                    
  457.                     LogMessage oSelecto & " already has some objects previously created by this script, finding a new name"
  458.                    
  459.                     'Hide the original mesh
  460.                     SetValue oSelecto & ".visibility.viewvis", False
  461.                     SetValue oSelecto & ".visibility.rendvis", False
  462.                        
  463.                 end if
  464.                    
  465.                 'Reset NumberCheck
  466.                 NumberCheck = "Nothing"
  467.                    
  468.                 'Set a new Regex pattern that finds any numbers at the end of its name
  469.                 regEx.Pattern = "[0-9]+$"
  470.                    
  471.                 'Execute the regex on the selection
  472.                 Set Matches = regEx.Execute(oSelName)
  473.                    
  474.                 For Each Match in Matches
  475.                     NumberCheck = Match.Value
  476.                 Next
  477.                    
  478.                 'If there are no numbers on the end then set objNumber to 0 (another 1 will be added on later)
  479.                 if NumberCheck = "Nothing" then
  480.            
  481.                     objNumber = "0"
  482.                        
  483.                 else
  484.                        
  485.                     'If there is a number, set objNumber to the number found above
  486.                     objNumber = NumberCheck
  487.                        
  488.                     'Now get the name without and numbers
  489.                     regEx.Pattern =  "^.*?(?=[0-9])"              
  490.                     Set Matches = regEx.Execute(oSelName)
  491.                        
  492.                     For Each Match in Matches
  493.                         oSelName =  Match.Value
  494.                     Next
  495.                    
  496.                 end if
  497.                    
  498.                 'Reset a counter I use to stop infinite loops, just incase :)
  499.                 JustIncaseAbort = 0
  500.                    
  501.                 'Temporarily rename things to get them out of the way
  502.                 oDupe = SetValue (oDupe & ".Name", oSelName & "-modellingTemp")
  503.                 oClone = SetValue (oClone & ".Name", oSelName & "-cloneTemp")
  504.                 oMerge = SetValue (oMerge & ".Name", oSelName & "-mergeTemp")
  505.                 WereRenamed = 1
  506.                    
  507.                 'This Do part will add a number to the object's name then check if that name is already taken
  508.                 'if it is, it will loop and add on another number etc, until it finds a free name (or my failsafe reaches 1000)
  509.  
  510.                     '-----------------------------Loop Start-----------------------------'
  511.                    
  512.                 Do
  513.                    
  514.                 'Increase objNumber by 1
  515.                 objNumber = objNumber + 1
  516.                    
  517.                 'Check if the model name needs to be added on to the test name
  518.                 if oModelo = "Scene_Root" then
  519.                    
  520.                     'Add on the new number to the name to see if it exists
  521.                     oSelTest = oSelName & objNumber
  522.                     oSelTest2 = oSelName & objNumber & "-MergedMesh"
  523.                     oSelTest3 = oSelName & objNumber & "-Modelling"
  524.                     oSelTest4 = oSelName & objNumber & "-ClonedHalf"
  525.                     oSelTest5 = oSelName & objNumber & "-Gator"
  526.                        
  527.                 else
  528.                    
  529.                     'Add on the model name aswell as the new number to the name to see if it exists
  530.                     oSelTest = oModelo & "." & oSelName & objNumber
  531.                     oSelTest2 = oModelo & "." & oSelName & objNumber & "-MergedMesh"
  532.                     oSelTest3 = oModelo & "." & oSelName & objNumber & "-Modelling"
  533.                     oSelTest4 = oModelo & "." & oSelName & objNumber & "-ClonedHalf"
  534.                     oSelTest5 = oModelo & "." & oSelName & objNumber & "-Gator"
  535.                    
  536.                 end if
  537.                
  538.                 LogMessage "Checking if the name " & oSelTest & " is available .."
  539.                            
  540.                 set oSelTest = Dictionary.GetObject( oSelTest, false )
  541.                 set oSelTest2 = Dictionary.GetObject( oSelTest2, false )
  542.                 set oSelTest3 = Dictionary.GetObject( oSelTest3, false )
  543.                 set oSelTest4 = Dictionary.GetObject( oSelTest4, false )
  544.                 set oSelTest5 = Dictionary.GetObject( oSelTest5, false )
  545.                    
  546.                 'Add 1 onto the abort counter
  547.                 JustIncaseAbort = JustIncaseAbort + 1
  548.                
  549.                 if TypeName( oSelTest ) <> "Nothing" then
  550.                     LogMessage oSelTest & " already exists"
  551.                 end if
  552.                    
  553.                 if TypeName( oSelTest2 ) <> "Nothing" then
  554.                     LogMessage oSelTest2 & " already exists"
  555.                 end if
  556.                
  557.                 if TypeName( oSelTest3 ) <> "Nothing" then
  558.                     LogMessage oSelTest3 & " already exists"
  559.                 end if
  560.  
  561.                 if TypeName( oSelTest4 ) <> "Nothing" then
  562.                     LogMessage oSelTest4 & " already exists"
  563.                 end if
  564.                
  565.                 if TypeName( oSelTest5 ) <> "Nothing" then
  566.                     LogMessage oSelTest5 & " already exists"
  567.                 end if
  568.        
  569.                 'Loop until there is a free name or the abort counter reaches 1000
  570.                 Loop Until TypeName( oSelTest ) = "Nothing" and TypeName( oSelTest2 ) = "Nothing" and TypeName( oSelTest3 ) = "Nothing" and TypeName( oSelTest4 ) = "Nothing"and TypeName( oSelTest5 ) = "Nothing"  or JustIncaseAbort = 1000
  571.                    
  572.                 '-----------------------------Loop Finish-----------------------------'
  573.  
  574.                 'Add the final number onto oSelName
  575.                 oSelName = oSelName & objNumber
  576.                
  577.                 if JustIncaseAbort = 1000 then
  578.                
  579.                     LogMessage "Name checking loop aborted after 1000 unsuccessfull attempts, doh!"
  580.                    
  581.                     else
  582.                    
  583.                     LogMessage "Woohoo, " & oSelName & " was available!"
  584.                    
  585.                 end if
  586.                
  587.             else
  588.            
  589.                 'Hide the original mesh
  590.                 SetValue oSelecto & ".visibility.viewvis", False
  591.                 SetValue oSelecto & ".visibility.rendvis", False
  592.            
  593.             end if     
  594.            
  595.             'If the selection is in a model and things were renamed earlier..
  596.             if oModelo <> "Scene_Root" and WereRenamed = 1 then
  597.                
  598.                 'Add the model name back into oClone and oDupe
  599.                 oClone = oModelo & "." & oClone
  600.                 oDupe = oModelo & "." & oDupe
  601.                
  602.             end if
  603.            
  604.             'Parent SubdCtrl to the modelling mesh
  605.             ParentObj "B:" & oDupe, oSubdCtrl
  606.            
  607.             set oDupe = Dictionary.GetObject( oDupe, False )
  608.             set oMerge = Dictionary.GetObject( oMerge, False )
  609.                
  610.             'Check to see if the merged mesh and the modelling mesh share the same parent object
  611.             if oDupe.Parent <> oMerge.Parent then
  612.                
  613.                 'If they don't, give the new clone the same parent as the selection
  614.                 ParentObj "B:" & oDupe.Parent, oMerge
  615.                    
  616.             end if
  617.            
  618.             'Rename things
  619.             oClone = SetValue (oClone & ".Name", oSelName & "-ClonedHalf")
  620.             oMerge = SetValue (oMerge & ".Name", oSelName & "-MergedMesh")
  621.             oSubdCtrl = SetValue (oSubdCtrl & ".Name", oSelName & "-Merged-SubdCtrl")
  622.             oDupe = SetValue (oDupe & ".Name", oSelName & "-Modelling")
  623.            
  624.             if oExpExist = "yes" then
  625.                 LogMessage "SRT expressions were removed from " & oDupe
  626.             end if
  627.            
  628.             LogMessage oDupe & ", " & oClone & ", " & oMerge & ", and " & oSubdCtrl & " were created, happy days :)"
  629.            
  630.             'Each time I rename something it loses it's model name..
  631.             if oModelo <> "Scene_Root" then
  632.                 oDupe = oModelo & "." & oDupe
  633.             end if
  634.            
  635.             'Add the -Modelling object to the oFinalSelect collection
  636.             oFinalSelect.Add oDupe
  637.            
  638.         end if
  639.        
  640.     end if
  641.    
  642. Next
  643.  
  644. 'Select all the objects in the oFinalSelect collection
  645. SelectObj oFinalSelect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement