Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '-----------------------------------------------------------------------------------------------------------------'
- 'This script will instantiate the selected model(s) then setup mirror like expressions - inverted on scale x axis, 'position x axis, and rotation y and z axis, with the other expressions being a direct copy.
- 'If instances have already been created by this script (and still have -Instance in their name) and you run this 'on the original model again, it will branch select the model and duplicate it first, then create a new instance 'of that model.
- 'If you have more than one model selected then only the models that don't end in -Instance are added to the 'collection for either duplication or instancing, so if you need to run it on a -Instance model then you must 'select it on its own. On the plus side you don't have to be too cautious when selecting models if you want to 'quickly duplicate a large group of them and their instances, aslong as all the non-instances you want are 'selected it doesn't matter how many(if any) -Instances are selected.
- 'This will also ignore any non-model item in the selection so you don't have to worry too much about just dragging 'a selection in the viewport, as long as a model null is part of the selection then it should work.
- 'If the selection isn't a model, this script will check if it's part of a model and ask the user if they want to 'use that instead. Or if the selection isn't part of any model it will ask the user if they want to create a new 'model for it.
- '-----------------------------------------------------------------------------------------------------------------'
- dim oSelecto, oSelection, oCol, regEx, oModel, oModelName
- dim oInstCheck, oModelCheck, oScriptCancel, BP, oObj, oFinalSelect
- 'Define a collection(oCol) for adding viable models to
- Set oCol = CreateObject( "XSI.Collection" )
- Set oSelection = Application.Selection
- oScriptCancel = "no"
- 'Check if any items are selected
- if oSelection.count > 0 Then
- 'Check if more than one item is selected
- if oSelection.count > 1 Then
- for i = 0 to (oSelection.Count - 1)
- 'Set a new Regex pattern that checks if a selected Model has "-Instance" at the end of its name
- set regEx = New RegExp
- regEx.Pattern = "-Instance"
- 'Reset oInstCheck
- oInstCheck = "nothing"
- 'Execute the regex on the selection
- Set Matches = regEx.Execute(oSelection(i))
- For Each Match in Matches
- oInstCheck = Match.Value
- Next
- 'If the selection doesnt end in -Instance and is a model then add it to the oCol Collection.
- if oInstCheck <> "-Instance" and TypeName ( oSelection(i) ) = "Model" then
- Logmessage oSelection(i) & " tastes like snozberries, added to oCol"
- oCol.add oSelection(i)
- else
- Logmessage oSelection(i) & " tastes like rejection!"
- end if
- next
- else
- 'If only one object is selected, make sure it is a model and add to the oCol Collection
- if TypeName ( oSelection(0) ) = "Model" then
- oCol.add oSelection(0)
- else
- 'If the selection isn't a model, send the user to the ModelCheck part of the script
- set oSelecto = oSelection(0)
- ModelCheck = "yes"
- end if
- end if
- else
- 'If no object is selected, start a picksession
- LogMessage "Select a Model"
- PickObject "Select a Model", " ", oSelecto
- if TypeName ( oSelection(0) ) = "Model" then
- oScriptCancel = "no"
- oCol.add oSelecto
- else
- 'If the selection isn't a model, send the user to the ModelCheck part of the script
- ModelCheck = "yes"
- end if
- end if
- if ModelCheck = "yes" then
- if oSelecto.Model <> "Scene_Root" then
- LogMessage oSelecto.Model & " detected, could use that instead!"
- BP = XSIUIToolkit.Msgbox( oSelecto.Name & " isn't a model, but it IS part of " & oSelecto.Model & ", should I just use that ?", 4, "No Model Selected" )
- if BP = 6 then
- LogMessage "OK, adding " & oSelecto.Model & " to oCol for instantiation or duplication :)"
- oScriptCancel = "no"
- oCol.Add oSelecto.Model
- else
- Logmessage "Script Cancelled - Next time select a Model instead of a " & TypeName( oSelecto ) & "! :)"
- oScriptCancel = "yes"
- end if
- else
- LogMessage oSelecto & " isn't even part of a model!"
- BP = XSIUIToolkit.Msgbox( oSelecto & " isn't part of a model, should I create one now?", 4, "No Model Selected" )
- if BP = 6 then
- LogMessage "Here goes, creating a model for " & oSelecto
- 'Define a name for the new model
- oModelName = oSelecto & "-Model"
- DeselectAll
- 'Create the new model using the oModelName as it's name :P
- Preferences.SetPreferenceValue "Interaction.autoinspect", false
- CreateModel , oModelName, , oModel
- Preferences.SetPreferenceValue "Interaction.autoinspect", true
- 'Match the model's translation to the input object
- MatchTransform "B:" & oModel, oSelecto, siTrn
- 'Parent the input object to the new model
- ParentObj "B:" & oModel, oSelecto
- 'Add the new model to oCol
- oCol.Add oModel
- LogMessage oModel & " was created for " & oSelecto
- oScriptCancel = "no"
- else
- Logmessage "Script Cancelled - Next time select a Model instead of a " & TypeName( oSelecto ) & "! :)"
- oScriptCancel = "yes"
- end if
- end if
- end if
- if oCol.Count = 0 then
- BP = XSIUIToolkit.Msgbox( "No models found in collection, do you want to try selecting a model again ?", 4, "No Model Selected" )
- if BP = 6 then
- PickObject "Please select a Model", " ", oSelecto
- if TypeName( oSelecto ) = "Model" then
- LogMessage "That's more like it !, " & oSelecto & " was added to oCol for instantiation or duplication :)"
- oCol.Add oSelecto
- oScriptCancel = "no"
- else
- if oSelecto.Model <> "Scene_Root" then
- LogMessage oSelecto.Model & " detected, could use that instead!"
- BP = XSIUIToolkit.Msgbox( oSelecto.Name & " isn't a model, but it IS part of " & oSelecto.Model & ", should I just use that ?", 4, "No Model Selected" )
- if BP = 6 then
- LogMessage "OK, adding " & oSelecto.Model & " to oCol for instantiation or duplication :)"
- oScriptCancel = "no"
- oCol.Add oSelecto.Model
- else
- Logmessage "Script Cancelled - Next time select a Model instead of a " & TypeName( oSelecto ) & "! :)"
- oScriptCancel = "yes"
- end if
- else
- LogMessage oSelecto & " isn't even part of a model!"
- BP = XSIUIToolkit.Msgbox( oSelecto & " isn't part of a model, should I create one now?", 4, "No Model Selected" )
- if BP = 6 then
- LogMessage "Creating a model for " & oSelecto
- 'Define a name for the new model
- oModelName = oSelecto & "-Model"
- DeselectAll
- 'Create the new model using the oModelName as it's name :P
- CreateModel , oModelName, , oModel
- 'Match the model's translation to the input object
- MatchTransform "B:" & oModel, oSelecto, siTrn
- 'Parent the input object to the new model
- ParentObj "B:" & oModel, oSelecto
- 'Add the new model to oCol
- oCol.Add oModel
- LogMessage oModel & " was created for " & oSelecto
- oScriptCancel = "no"
- else
- Logmessage "Script Cancelled - Next time select a Model instead of a " & TypeName( oSelecto ) & "! :)"
- oScriptCancel = "yes"
- end if
- end if
- end if
- else
- oScriptCancel = "yes"
- end if
- end if
- 'Create a collection to add new models to for selection at the end
- Set oFinalSelect = CreateObject( "XSI.Collection" )
- if oScriptCancel = "no" then
- for i = 0 to (oCol.count-1)
- 'Check if an instance of the selection exists
- strPMname = oCol(i)&"-Instance"
- Set oObj = Dictionary.GetObject( strPMname, false )
- if TypeName( oObj ) <> "Nothing" then
- 'Branch select the selection and duplicate it
- DeselectAll
- AddToSelection oCol(i), "BRANCH"
- oDupo = Duplicate (, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
- oDupo2 = replace (oDupo, "B:", "")
- 'Instance the newly duplicated model
- set oInsta = Instantiate ("B:" & oDupo, , 1, 1, 0, 1)
- 'Scale Expressions
- SetExpr oInsta&".kine.local.sclx", oDupo2+".kine.local.sclx*-1"
- SetExpr oInsta&".kine.local.scly", oDupo2+".kine.local.scly"
- SetExpr oInsta&".kine.local.sclz", oDupo2+".kine.local.sclz"
- 'Rotation Expressions
- SetExpr oInsta&".kine.local.rotx", oDupo2+".kine.local.rotx"
- SetExpr oInsta&".kine.local.roty", oDupo2+".kine.local.roty*-1"
- SetExpr oInsta&".kine.local.rotz", oDupo2+".kine.local.rotz*-1"
- 'Translation Expressions
- SetExpr oInsta&".kine.local.posx", oDupo2+".kine.local.posx*-1"
- SetExpr oInsta&".kine.local.posy", oDupo2+".kine.local.posy"
- SetExpr oInsta&".kine.local.posz", oDupo2+".kine.local.posz"
- 'Rename the new instance
- oNewName = replace (oInsta, "_Instance", "-Instance")
- SetValue oInsta&".Name", oNewName
- SelectObj oDupo
- LogMessage "Instance detected, " & oCol(i) & " was duplicated (" & oDupo2 & "), and given a new mirror instance (" & oNewName &")"
- oFinalSelect.Add oDupo
- else
- 'If there is no instance detected . . .
- set oSelecto = oCol(i)
- if oScriptCancel = "no" then
- 'Instantiate each model in selection
- set oInsta = Instantiate ("B:" & oSelecto, , 1, 1, 0, 1)
- 'Scale Expressions
- SetExpr oInsta&".kine.local.sclx", oSelecto+".kine.local.sclx*-1"
- SetExpr oInsta&".kine.local.scly", oSelecto+".kine.local.scly"
- SetExpr oInsta&".kine.local.sclz", oSelecto+".kine.local.sclz"
- 'Rotation Expressions
- SetExpr oInsta&".kine.local.rotx", oSelecto+".kine.local.rotx"
- SetExpr oInsta&".kine.local.roty", oSelecto+".kine.local.roty*-1"
- SetExpr oInsta&".kine.local.rotz", oSelecto+".kine.local.rotz*-1"
- 'Translation Expressions
- SetExpr oInsta&".kine.local.posx", oSelecto+".kine.local.posx*-1"
- SetExpr oInsta&".kine.local.posy", oSelecto+".kine.local.posy"
- SetExpr oInsta&".kine.local.posz", oSelecto+".kine.local.posz"
- 'Rename the new instance
- oNewName = replace (oInsta, "_Instance", "-Instance")
- SetValue oInsta&".Name", oNewName
- LogMessage "Created a mirror instance of " & oCol(i) & " (" & oNewName &")"
- oFinalSelect.Add oSelecto
- end if
- end if
- Next
- SelectObj oFinalSelect
- end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement