Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '-----------------------------------------------------------------------------------------------------------------'
- 'This script creates a new model for each of the selected items and matches all transforms, then the item is 'parented to the new model and it's own transforms are reset.
- 'If the selected item is either a clone or an instance created by one of my mirror scripts (and still end in '-Clone or -Instance) it will also check if each SRT channel has an expression, and if they do it will disable 'them and give the newly created model the same mirror like expressions the clone/instance would originally have 'had.
- 'The primary intent of this script is so you can offset the clones / instances on one side so they aren't 'completely symmetrical but still retain the mirror like expressions. For example, if you used one of my mirror 'scripts to create a characters teeth, you can run this on all the cloned / instanced teeth then offset them 'slightly so they aren't perfect and still have the ability to quickly re-arrange the originals and have the other 'side match up if say you need to widen the jaw or something :)
- '-----------------------------------------------------------------------------------------------------------------'
- dim oCol, oSelection, oSelecto, oParent1, oParent2, oModelo, oSelName, oModelName, oSelOrig
- dim regEx, oCloInstCheck, Match, Matches, oCloneCheck, oInstaCheck, CheckExp
- dim oExpExist, oExpStr, oExpPosx, oExpPosy, oExpPosz, oExpRotx
- dim oExpRoty, oExpRotz, oExpSclx, oExpScly, oExpSclz
- 'Define a collection(oCol) for adding objects to
- Set oCol = CreateObject( "XSI.Collection" )
- 'Check if an object is selected
- if application.selection.count > 0 Then
- 'Convert application selection into a Collection named oCol
- Set oSelection = Application.Selection
- for i = 0 to (oSelection.Count - 1)
- oCol.add oSelection(i)
- next
- else
- 'If no object is selected, start a picksession
- LogMessage "Select a Model"
- PickObject "Select a Model", " ", oSelecto
- oCol.add oSelecto
- end if
- for i = 0 to (oCol.count-1)
- set oSelecto = oCol(i)
- oParent1 = oCol(i).Parent
- 'Remove model name from selection
- oModelo = oSelecto.Model
- oSelName = replace( oSelecto, oModelo&".", "")
- oModelName = oSelName & "-Model"
- 'Create an empty model, match translation to the clone and parent the clone to model
- DeselectAll
- Preferences.SetPreferenceValue "Interaction.autoinspect", false
- CreateModel , oModelName, , oModel
- Preferences.SetPreferenceValue "Interaction.autoinspect", true
- MatchTransform "B:" & oModel, oSelecto, siSRT
- 'Set a new Regex pattern that finds any letters after - at the end of its name
- set regEx = New RegExp
- regEx.Pattern = "-[a-zA-Z]+$"
- 'Reset oCloInstCheck
- oCloInstCheck = "Nothing"
- 'Reset CheckExp
- CheckExp = "No"
- 'Execute the regex on the selection
- Set Matches = regEx.Execute(oSelName)
- For Each Match in Matches
- oCloInstCheck = Match.Value
- Next
- 'Check if the selected object ends in -Clone
- if oCloInstCheck = "-Clone" then
- oSelOrig = replace (oSelecto, "-Clone", "" )
- 'Reset oCloneCheck
- oCloneCheck = "Nothing"
- 'Check if the non-clone exists
- set oCloneCheck = Dictionary.GetObject( oSelOrig, false )
- if TypeName( oCloneCheck ) <> "Nothing" then
- LogMessage oSelecto & " should be an instance of " & oSelOrig & ", setting up the expressions for " & oModel & " accordingly"
- CheckExp = "yes"
- end if
- 'Check if the selected object ends in -Instance
- elseIf oCloInstCheck = "-Instance" then
- oSelOrig = replace (oSelecto, "-Instance", "" )
- 'Reset oInstaCheck
- oInstaCheck = "Nothing"
- 'Check if the non-Instance exists
- set oInstaCheck = Dictionary.GetObject( oSelOrig, false )
- if TypeName( oInstaCheck ) <> "Nothing" then
- LogMessage oSelecto & " should be a clone of " & oSelOrig & ", setting up the expressions for " & oModel & " accordingly"
- CheckExp = "yes"
- end if
- end if
- 'If the object is either a clone or an instance then check each expression individually to see if they still exist
- 'If they do, disable the objects versions and give the new model the mirror type expressions the object would have originally had
- if CheckExp = "yes" then
- oExpExist = "no"
- ExpStr = oSelecto & ".kine.local.pos.posx.Expression"
- set oExpPosx = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpPosx ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.pos.posx.Expression.Active", False
- SetExpr oModel&".kine.local.posx", oSelOrig&".kine.local.posx*-1"
- oExpExist = "yes"
- end if
- ExpStr = oSelecto & ".kine.local.pos.posy.Expression"
- set oExpPosy = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpPosy ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.pos.posy.Expression.Active", False
- SetExpr oModel&".kine.local.posy", oSelOrig&".kine.local.posy"
- oExpExist = "yes"
- end if
- ExpStr = oSelecto & ".kine.local.pos.posz.Expression"
- set oExpPosz = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpPosz ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.pos.posz.Expression.Active", False
- SetExpr oModel&".kine.local.posz", oSelOrig&".kine.local.posz"
- oExpExist = "yes"
- end if
- ExpStr = oSelecto & ".kine.local.ori.euler.rotx.Expression"
- set oExpRotx = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpRotx ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.ori.euler.rotx.Expression.Active", False
- SetExpr oModel&".kine.local.rotx", oSelOrig&".kine.local.rotx"
- oExpExist = "yes"
- end if
- ExpStr = oSelecto & ".kine.local.ori.euler.roty.Expression"
- set oExpRoty = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpRoty ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.ori.euler.roty.Expression.Active", False
- SetExpr oModel&".kine.local.roty", oSelOrig&".kine.local.roty*-1"
- oExpExist = "yes"
- end if
- ExpStr = oSelecto & ".kine.local.ori.euler.rotz.Expression"
- set oExpRotz = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpRotz ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.ori.euler.rotz.Expression.Active", False
- SetExpr oModel&".kine.local.rotz", oSelOrig&".kine.local.rotz*-1"
- oExpExist = "yes"
- end if
- ExpStr = oSelecto & ".kine.local.scl.sclx.Expression"
- set oExpSclx = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpSclx ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.scl.sclx.Expression.Active", False
- SetExpr oModel&".kine.local.sclx", oSelOrig&".kine.local.sclx*-1"
- oExpExist = "yes"
- end if
- ExpStr = oSelecto & ".kine.local.scl.scly.Expression"
- set oExpScly = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpScly ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.scl.scly.Expression.Active", False
- SetExpr oModel&".kine.local.scly", oSelOrig&".kine.local.scly"
- oExpExist = "yes"
- end if
- ExpStr = oSelecto & ".kine.local.scl.sclz.Expression"
- set oExpSclz = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpSclz ) <> "Nothing" then
- SetValue oSelecto & ".kine.local.scl.sclz.Expression.Active", False
- SetExpr oModel&".kine.local.sclz", oSelOrig&".kine.local.sclz"
- oExpExist = "yes"
- end if
- end if
- 'Parent oSelecto to the new model
- ParentObj "B:" & oModel, oSelecto
- 'Reset all transforms on the input object
- ResetTransform oModel & "." & oSelName, siObj, siSRT, siXYZ
- 'Check if the the new clone and the first object in selection share the same parent
- 'If they don't, give the new Model the same parent as the the clone
- oParent2 = oModel.Parent
- if oParent1 <> oParent2 then
- ParentObj "B:" & oParent1, oModel
- end if
- If oExpExist = "yes" then
- LogMessage oModel & " was created for " & oSelName
- LogMessage oSelName & "'s expressions were disabled, and expressions were added to " & oModel & ", inversly linking it to " & oSelOrig
- else
- LogMessage oModel & " was created for " & oSelName
- end if
- next
- SelectObj oCol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement