Advertisement
spookymunky

SymmThings 2.01 - Cloned Symmetry (VBS)

Aug 1st, 2013
172
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", False
  279.             'Change the duplicate's wireframe display colour
  280.             SetValue oDupe & ".display.wirecolorr", 0.12
  281.             SetValue oDupe & ".display.wirecolorg", 0.14
  282.             SetValue oDupe & ".display.wirecolorb", 0.18
  283.  
  284.             'Set the clone's scale expressions linking it to the modelling half
  285.             SetExpr oClone & ".kine.local.sclx", oDupe & ".kine.local.sclx*-1"
  286.             SetExpr oClone & ".kine.local.scly", oDupe & ".kine.local.scly"
  287.             SetExpr oClone & ".kine.local.sclz", oDupe & ".kine.local.sclz"
  288.  
  289.             'Set the clone's rotation expressions linking it to the modelling half
  290.             SetExpr oClone & ".kine.local.rotx", oDupe & ".kine.local.rotx"
  291.             SetExpr oClone & ".kine.local.roty", oDupe & ".kine.local.roty"
  292.             SetExpr oClone & ".kine.local.rotz", oDupe & ".kine.local.rotz"
  293.  
  294.             'Set the clone's translation expressions linking it to the modelling half
  295.             SetExpr oClone & ".kine.local.posx", oDupe & ".kine.local.posx"
  296.             SetExpr oClone & ".kine.local.posy", oDupe & ".kine.local.posy"
  297.             SetExpr oClone & ".kine.local.posz", oDupe & ".kine.local.posz"
  298.            
  299.             'Store oDupe's SRT to use for matching up oMerge's Center
  300.             oDupeScaleX = GetValue (oSelecto & ".kine.Global.scl.sclx")
  301.             oDupeScaleY = GetValue (oSelecto & ".kine.Global.scl.sclY")
  302.             oDupeScaleZ = GetValue (oSelecto & ".kine.Global.scl.sclZ")
  303.  
  304.             oDupeRotX = GetValue (oSelecto & ".kine.Global.ori.euler.rotx")
  305.             oDupeRotY = GetValue (oSelecto & ".kine.Global.ori.euler.rotY")
  306.             oDupeRotZ = GetValue (oSelecto & ".kine.Global.ori.euler.rotZ")
  307.  
  308.             oDupePosX = GetValue (oSelecto & ".kine.Global.pos.posx")
  309.             oDupePosY = GetValue (oSelecto & ".kine.Global.pos.posY")
  310.             oDupePosZ = GetValue (oSelecto & ".kine.Global.pos.posZ")
  311.  
  312.             'Match oMerge's Center to oDupe's SRT
  313.             Translate oMerge, oDupePosX, oDupePosY, oDupePosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
  314.             Rotate oMerge, oDupeRotX, oDupeRotY, oDupeRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  315.             Scale oMerge, oDupeScaleX, oDupeScaleY, oDupeScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  316.            
  317.             'Set the Merged Mesh's scale expressions linking it to the modelling half
  318.             SetExpr oMerge & ".kine.local.sclx", oDupe & ".kine.local.sclx"
  319.             SetExpr oMerge & ".kine.local.scly", oDupe & ".kine.local.scly"
  320.             SetExpr oMerge & ".kine.local.sclz", oDupe & ".kine.local.sclz"
  321.  
  322.             'Set the Merged Mesh's rotation expressions linking it to the modelling half
  323.             SetExpr oMerge & ".kine.local.rotx", oDupe & ".kine.local.rotx"
  324.             SetExpr oMerge & ".kine.local.roty", oDupe & ".kine.local.roty"
  325.             SetExpr oMerge & ".kine.local.rotz", oDupe & ".kine.local.rotz"
  326.  
  327.             'Set the Merged Mesh's translation expressions linking it to the modelling half
  328.             SetExpr oMerge & ".kine.local.posx", oDupe & ".kine.local.posx"
  329.             SetExpr oMerge & ".kine.local.posy", oDupe & ".kine.local.posy"
  330.             SetExpr oMerge & ".kine.local.posz", oDupe & ".kine.local.posz"
  331.            
  332.             'Get oMerge's bounding box co-ordinates to use in setting up relative values for SubdCtrl
  333.             GetBBox oMerge, TRUE, Xmin, Ymin, Zmin, Xmax, Ymax, Zmax
  334.    
  335.             oMergeScale = ( ( ( Xmax - Xmin ) / 2 ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 3
  336.            
  337.             CtrlXtrans = ( Xmin + Xmax ) / 2
  338.             CtrlYtrans = Ymax + ( oMergeScale / 2.2 )
  339.             CtrlZtrans = ( Zmin + Zmax ) / 2
  340.            
  341.             CtrlScale = oMergeScale * 0.01
  342.                
  343.             'Move and scale SubdCtrl using the above values
  344.             Scale oSubdCtrl, CtrlScale, CtrlScale, CtrlScale, siRelative, siGlobal, siObj, siXYZ, , , , , , , , 0
  345.             Translate oSubdCtrl, CtrlXtrans, CtrlYtrans, CtrlZtrans, siAbsolute , siGlobal, siObj, siXYZ, , , , , , , , , , 0
  346.            
  347.             'Add the SubdCtrl object to the oFinalSelect collection
  348.             oFinalSelect.Add oSubdCtrl
  349.            
  350.             'Remove the model name from selection
  351.             oModelo = oSelecto.Model
  352.             oSelName = replace( oSelecto, oModelo&".", "")
  353.                
  354.             'Set some dictionary lookups to check if anything created by this script in the past still exists
  355.             oSelTest = oCol(i) & "-Modelling"
  356.             set ModellingTest = Dictionary.GetObject( oSelTest, false )
  357.             oSelTest = oCol(i) & "-ClonedHalf"
  358.             set ClonedTest = Dictionary.GetObject( oSelTest, false )
  359.             oSelTest = oCol(i) & "-MergedMesh"
  360.             set MergedTest = Dictionary.GetObject( oSelTest, false )
  361.             oSelTest = oCol(i) & "-Gator"
  362.             set GatorTest = Dictionary.GetObject( oSelTest, false )
  363.  
  364.             'Reset WereRenamed
  365.             WereRenamed = 0
  366.                
  367.             '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
  368.             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
  369.                    
  370.                 if AfterDashCheck = "-MergedMesh" or AfterDashCheck = "-Gator" then
  371.                    
  372.                     LogMessage oSelName & " is already a merged result, removing expressions and finding a new name for it to keep things nice!"
  373.                     SetValue oDupe & ".visibility.selectability", True
  374.                     oSelName = Replace (oSelName, AfterDashCheck, "")
  375.                        
  376.                     oExpExist = "no"
  377.                
  378.                     ExpStr = oDupe & ".kine.local.scl.sclx.Expression"
  379.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  380.                     if TypeName( oExpCheck ) <> "Nothing" then
  381.                         RemoveAnimation oDupe & ".kine.local.sclx", 1
  382.                         oExpExist = "yes"
  383.                     end if
  384.                            
  385.                     ExpStr = oDupe & ".kine.local.scl.scly.Expression"
  386.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  387.                     if TypeName( oExpCheck ) <> "Nothing" then
  388.                         RemoveAnimation oDupe & ".kine.local.scly", 1
  389.                         oExpExist = "yes"
  390.                     end if
  391.                        
  392.                     ExpStr = oDupe & ".kine.local.scl.sclz.Expression"
  393.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  394.                     if TypeName( oExpCheck ) <> "Nothing" then
  395.                         RemoveAnimation oDupe & ".kine.local.sclz", 1
  396.                         oExpExist = "yes"
  397.                     end if
  398.                        
  399.                     ExpStr = oDupe & ".kine.local.ori.euler.rotx.Expression"
  400.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  401.                     if TypeName( oExpCheck ) <> "Nothing" then
  402.                         RemoveAnimation oDupe & ".kine.local.rotx", 1
  403.                         oExpExist = "yes"
  404.                     end if
  405.                        
  406.                     ExpStr = oDupe & ".kine.local.ori.euler.roty.Expression"
  407.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  408.                     if TypeName( oExpCheck ) <> "Nothing" then
  409.                         RemoveAnimation oDupe & ".kine.local.roty", 1
  410.                         oExpExist = "yes"
  411.                     end if
  412.                        
  413.                     ExpStr = oDupe & ".kine.local.ori.euler.rotz.Expression"
  414.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  415.                     if TypeName( oExpCheck ) <> "Nothing" then
  416.                         RemoveAnimation oDupe & ".kine.local.rotz", 1
  417.                         oExpExist = "yes"
  418.                     end if
  419.                        
  420.                     ExpStr = oDupe & ".kine.local.pos.posx.Expression"
  421.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  422.                     if TypeName( oExpCheck ) <> "Nothing" then
  423.                         RemoveAnimation oDupe & ".kine.local.posx", 1
  424.                         oExpExist = "yes"
  425.                     end if
  426.                        
  427.                     ExpStr = oDupe & ".kine.local.pos.posy.Expression"
  428.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  429.                     if TypeName( oExpCheck ) <> "Nothing" then
  430.                         RemoveAnimation oDupe & ".kine.local.posy", 1
  431.                         oExpExist = "yes"
  432.                     end if
  433.                        
  434.                     ExpStr = oDupe & ".kine.local.pos.posz.Expression"
  435.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  436.                     if TypeName( oExpCheck ) <> "Nothing" then
  437.                         RemoveAnimation oDupe & ".kine.local.posz", 1
  438.                         oExpExist = "yes"
  439.                     end if
  440.                        
  441.                 elseIf AfterDashCheck = "-Modelling" then
  442.                        
  443.                     LogMessage oSelName & " is a Modelling half, finding a new name for it to keep things nice!"
  444.                     oSelName = Replace (oSelName, "-Modelling", "")
  445.                        
  446.                     'Check if the new modelling half has a shrink wrap op, if it does, freeze it
  447.                     SWStr = oDupe & ".polymsh.shrinkwrap"
  448.                     set oShrinkWrapCheck = Dictionary.GetObject( SWStr, false )
  449.                     if TypeName( oShrinkWrapCheck ) <> "Nothing" then
  450.                         FreezeObj oDupe & ".polymsh.shrinkwrap"
  451.                         LogMessage SWStr & " was Frozen"
  452.                     end if
  453.                        
  454.                 else
  455.                    
  456.                     LogMessage oSelecto & " already has some objects previously created by this script, finding a new name"
  457.                    
  458.                     'Hide the original mesh
  459.                     SetValue oSelecto & ".visibility.viewvis", False
  460.                     SetValue oSelecto & ".visibility.rendvis", False
  461.                        
  462.                 end if
  463.                    
  464.                 'Reset NumberCheck
  465.                 NumberCheck = "Nothing"
  466.                    
  467.                 'Set a new Regex pattern that finds any numbers at the end of its name
  468.                 regEx.Pattern = "[0-9]+$"
  469.                    
  470.                 'Execute the regex on the selection
  471.                 Set Matches = regEx.Execute(oSelName)
  472.                    
  473.                 For Each Match in Matches
  474.                     NumberCheck = Match.Value
  475.                 Next
  476.                    
  477.                 'If there are no numbers on the end then set objNumber to 0 (another 1 will be added on later)
  478.                 if NumberCheck = "Nothing" then
  479.            
  480.                     objNumber = "0"
  481.                        
  482.                 else
  483.                        
  484.                     'If there is a number, set objNumber to the number found above
  485.                     objNumber = NumberCheck
  486.                        
  487.                     'Now get the name without and numbers
  488.                     regEx.Pattern =  "^.*?(?=[0-9])"              
  489.                     Set Matches = regEx.Execute(oSelName)
  490.                        
  491.                     For Each Match in Matches
  492.                         oSelName =  Match.Value
  493.                     Next
  494.                    
  495.                 end if
  496.                    
  497.                 'Reset a counter I use to stop infinite loops, just incase :)
  498.                 JustIncaseAbort = 0
  499.                    
  500.                 'Temporarily rename things to get them out of the way
  501.                 oDupe = SetValue (oDupe & ".Name", oSelName & "-modellingTemp")
  502.                 oClone = SetValue (oClone & ".Name", oSelName & "-cloneTemp")
  503.                 oMerge = SetValue (oMerge & ".Name", oSelName & "-mergeTemp")
  504.                 WereRenamed = 1
  505.                    
  506.                 'This Do part will add a number to the object's name then check if that name is already taken
  507.                 'if it is, it will loop and add on another number etc, until it finds a free name (or my failsafe reaches 1000)
  508.  
  509.                     '-----------------------------Loop Start-----------------------------'
  510.                    
  511.                 Do
  512.                    
  513.                 'Increase objNumber by 1
  514.                 objNumber = objNumber + 1
  515.                    
  516.                 'Check if the model name needs to be added on to the test name
  517.                 if oModelo = "Scene_Root" then
  518.                    
  519.                     'Add on the new number to the name to see if it exists
  520.                     oSelTest = oSelName & objNumber
  521.                     oSelTest2 = oSelName & objNumber & "-MergedMesh"
  522.                     oSelTest3 = oSelName & objNumber & "-Modelling"
  523.                     oSelTest4 = oSelName & objNumber & "-ClonedHalf"
  524.                     oSelTest5 = oSelName & objNumber & "-Gator"
  525.                        
  526.                 else
  527.                    
  528.                     'Add on the model name aswell as the new number to the name to see if it exists
  529.                     oSelTest = oModelo & "." & oSelName & objNumber
  530.                     oSelTest2 = oModelo & "." & oSelName & objNumber & "-MergedMesh"
  531.                     oSelTest3 = oModelo & "." & oSelName & objNumber & "-Modelling"
  532.                     oSelTest4 = oModelo & "." & oSelName & objNumber & "-ClonedHalf"
  533.                     oSelTest5 = oModelo & "." & oSelName & objNumber & "-Gator"
  534.                    
  535.                 end if
  536.                
  537.                 LogMessage "Checking if the name " & oSelTest & " is available .."
  538.                            
  539.                 set oSelTest = Dictionary.GetObject( oSelTest, false )
  540.                 set oSelTest2 = Dictionary.GetObject( oSelTest2, false )
  541.                 set oSelTest3 = Dictionary.GetObject( oSelTest3, false )
  542.                 set oSelTest4 = Dictionary.GetObject( oSelTest4, false )
  543.                 set oSelTest5 = Dictionary.GetObject( oSelTest5, false )
  544.                    
  545.                 'Add 1 onto the abort counter
  546.                 JustIncaseAbort = JustIncaseAbort + 1
  547.                
  548.                 if TypeName( oSelTest ) <> "Nothing" then
  549.                     LogMessage oSelTest & " already exists"
  550.                 end if
  551.                    
  552.                 if TypeName( oSelTest2 ) <> "Nothing" then
  553.                     LogMessage oSelTest2 & " already exists"
  554.                 end if
  555.                
  556.                 if TypeName( oSelTest3 ) <> "Nothing" then
  557.                     LogMessage oSelTest3 & " already exists"
  558.                 end if
  559.  
  560.                 if TypeName( oSelTest4 ) <> "Nothing" then
  561.                     LogMessage oSelTest4 & " already exists"
  562.                 end if
  563.                
  564.                 if TypeName( oSelTest5 ) <> "Nothing" then
  565.                     LogMessage oSelTest5 & " already exists"
  566.                 end if
  567.        
  568.                 'Loop until there is a free name or the abort counter reaches 1000
  569.                 Loop Until TypeName( oSelTest ) = "Nothing" and TypeName( oSelTest2 ) = "Nothing" and TypeName( oSelTest3 ) = "Nothing" and TypeName( oSelTest4 ) = "Nothing"and TypeName( oSelTest5 ) = "Nothing"  or JustIncaseAbort = 1000
  570.                    
  571.                 '-----------------------------Loop Finish-----------------------------'
  572.  
  573.                 'Add the final number onto oSelName
  574.                 oSelName = oSelName & objNumber
  575.                
  576.                 if JustIncaseAbort = 1000 then
  577.                
  578.                     LogMessage "Name checking loop aborted after 1000 unsuccessfull attempts, doh!"
  579.                    
  580.                     else
  581.                    
  582.                     LogMessage "Woohoo, " & oSelName & " was available!"
  583.                    
  584.                 end if
  585.                
  586.             else
  587.            
  588.                 'Hide the original mesh
  589.                 SetValue oSelecto & ".visibility.viewvis", False
  590.                 SetValue oSelecto & ".visibility.rendvis", False
  591.            
  592.             end if     
  593.            
  594.             'If the selection is in a model and things were renamed earlier..
  595.             if oModelo <> "Scene_Root" and WereRenamed = 1 then
  596.                
  597.                 'Add the model name back into oClone and oDupe
  598.                 oClone = oModelo & "." & oClone
  599.                 oDupe = oModelo & "." & oDupe
  600.                
  601.             end if
  602.            
  603.             'Parent SubdCtrl to the modelling mesh
  604.             ParentObj "B:" & oDupe, oSubdCtrl
  605.            
  606.             set oDupe = Dictionary.GetObject( oDupe, False )
  607.             set oMerge = Dictionary.GetObject( oMerge, False )
  608.                
  609.             'Check to see if the merged mesh and the modelling mesh share the same parent object
  610.             if oDupe.Parent <> oMerge.Parent then
  611.                
  612.                 'If they don't, give the new clone the same parent as the selection
  613.                 ParentObj "B:" & oDupe.Parent, oMerge
  614.                    
  615.             end if
  616.            
  617.             'Rename things
  618.             oClone = SetValue (oClone & ".Name", oSelName & "-ClonedHalf")
  619.             oMerge = SetValue (oMerge & ".Name", oSelName & "-MergedMesh")
  620.             oSubdCtrl = SetValue (oSubdCtrl & ".Name", oSelName & "-Merged-SubdCtrl")
  621.             oDupe = SetValue (oDupe & ".Name", oSelName & "-Modelling")
  622.            
  623.             if oExpExist = "yes" then
  624.                 LogMessage "SRT expressions were removed from " & oDupe
  625.             end if
  626.            
  627.             LogMessage oDupe & ", " & oClone & ", " & oMerge & ", and " & oSubdCtrl & " were created, happy days :)"
  628.            
  629.             'Each time I rename something it loses it's model name..
  630.             if oModelo <> "Scene_Root" then
  631.                 oDupe = oModelo & "." & oDupe
  632.             end if
  633.            
  634.             'Add the -Modelling object to the oFinalSelect collection
  635.             oFinalSelect.Add oDupe
  636.            
  637.         end if
  638.        
  639.     end if
  640.    
  641. Next
  642.  
  643. 'Select all the objects in the oFinalSelect collection
  644. SelectObj oFinalSelect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement