Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '-----------------------------------------------------------------------------------------------------------------'
- 'This script will either clone or duplicate the selected object(s) depending on their type (e.g. polygon meshes 'and curves etc will be cloned, while lights / control objects etc will be duplicated), 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 the selected object is a polygon or surface mesh then the clone will also get expressions 'linking its subdivision / SurfaceUV levels to the original.
- 'If clones have already been created by this script (and still have -Clone in their name) and you run this on the 'original object again, it will duplicate both the selected object and its clone and rename them so that every 'object should have a direct -Clone .. e.g. if the duplicate of an object turns out to be cube21 its clone will be 'named cube21-Clone.
- 'If you have more than one object selected then only the objects that don't end in -Clone are added to the 'collection for either duplication or cloning, so if you need to run it on a -Clone object then you must select it 'on its own. On the plus side you don't have to be too cautious when selecting objects if you want to quickly 'duplicate a large group of objects and their clones, aslong as all the non-clones you want are selected it 'doesn't matter how many(if any) -Clones are selected.. if that makes sense :).
- '-----------------------------------------------------------------------------------------------------------------'
- dim oCol, oSelection, oSelecto, regEx, oCloneCheck, Match, Matches, oFinalSelect, oDupeStr, oDupeCol
- dim oDupes, oModelo, oName, oSelName, oParent1, oParent2, oClone, IsAClone
- set regEx = New RegExp
- '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
- Set oSelection = Application.Selection
- 'Check if more than one object is selected
- if application.selection.count > 1 Then
- for i = 0 to (oSelection.Count - 1)
- 'Set a new Regex pattern that finds any letters after - at the end of its name
- regEx.Pattern = "-[a-zA-Z]+$"
- 'Reset oCloneCheck
- oCloneCheck = "nothing"
- 'Execute the regex on the selection
- Set Matches = regEx.Execute(oSelection(i))
- For Each Match in Matches
- oCloneCheck = Match.Value
- Next
- 'If the selection doesnt end in -Clone then add it to the oCol Collection.
- if oCloneCheck <> "-Clone" then
- Logmessage oSelection(i) & " is righteous and pure, added to oCol"
- oCol.add oSelection(i)
- else
- Logmessage oSelection(i) & " was deemed an inferior being and rejected."
- end if
- next
- else
- 'If only one object is selected, add it to the oCol Collection
- oCol.add oSelection(0)
- end if
- else
- 'If no object is selected, start a picksession
- LogMessage "Select an object"
- PickObject "Select an object", " ", oSelecto
- oCol.add oSelecto
- end if
- 'Create a collection to add objects to for selection at the end
- Set oFinalSelect = CreateObject( "XSI.Collection" )
- for i = 0 to (oCol.count-1)
- if TypeName( oCol(i) ) = "X3DObject" or TypeName( oCol(i) ) = "Null" or TypeName( oCol(i) ) = "Model" or TypeName( oCol(i) ) = "Light" then
- set oSelecto = oCol(i)
- 'Check if a clone of the selected object exists
- oDupeStr = oCol(i)&"-Clone"
- set oObj = Dictionary.GetObject( oDupeStr, false )
- if TypeName( oObj ) <> "Nothing" then
- 'Create a collection and add the selected object and its already existing clone
- Set oDupeCol = CreateObject("XSI.Collection")
- oDupeCol.Add oSelecto
- oDupeCol.Add oSelecto&"-Clone"
- 'Duplicate the Collection
- set oDupes = Duplicate (oDupeCol, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
- 'Remove Model name from oDupes(0)
- oModelo = oDupes(0).Model
- oName = replace( oDupes(0), oModelo&".", "")
- 'Rename the newly created clone
- SetValue oDupes(1)&".Name", oName&"-Clone"
- 'Check if the the new clone and the original selection share the same parent
- oParent1 = oCol(0).Parent
- oParent2 = oDupes(1).Parent
- if oParent1 <> oParent2 then
- 'If they don't, give the new clone the same parent as the selection
- ParentObj "B:" & oParent1, oDupes(1)
- end if
- LogMessage "Clone detected, " & oDupeCol(0) & " and " & oDupeCol(1) & " were duplicated (" & oDupes(0) & "), (" & oDupes(1) &")"
- oFinalSelect.Add oDupes(0)
- else
- 'If there is no -Clone detected and the selection is a suitable X3DObject clone it, otherwise duplicate
- if TypeName( oCol(i) ) = "X3DObject" and oCol(i).Type <> "wave" and oCol(i).Type <> "volume_deform" and oCol(i).Type <> "attractor" and oCol(i).Type <> "drag" and oCol(i).Type <> "eddy" and oCol(i).Type <> "fan" and oCol(i).Type <> "gravity" and oCol(i).Type <> "Toric_Force" and oCol(i).Type <> "turbulence" and oCol(i).Type <> "vortex" and oCol(i).Type <> "wind" and oCol(i).Type <> "standin" and oCol(i).Type <> "lattice" then
- set oClone = Clone (oSelecto, , 1, 1, 0, 0, 1, 0, 1)
- IsAClone = "yes"
- else
- set oClone = Duplicate (oSelecto, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
- IsAClone = "no"
- end if
- 'Scale Expressions
- SetExpr oClone&".kine.local.sclx", oSelecto&".kine.local.sclx*-1"
- SetExpr oClone&".kine.local.scly", oSelecto&".kine.local.scly"
- SetExpr oClone&".kine.local.sclz", oSelecto&".kine.local.sclz"
- 'Rotation Expressions
- SetExpr oClone&".kine.local.rotx", oSelecto&".kine.local.rotx"
- SetExpr oClone&".kine.local.roty", oSelecto&".kine.local.roty*-1"
- SetExpr oClone&".kine.local.rotz", oSelecto&".kine.local.rotz*-1"
- 'Translation Expressions
- SetExpr oClone&".kine.local.posx", oSelecto&".kine.local.posx*-1"
- SetExpr oClone&".kine.local.posy", oSelecto&".kine.local.posy"
- SetExpr oClone&".kine.local.posz", oSelecto&".kine.local.posz"
- 'If object is a polymesh
- if oSelecto.Type = "polymsh" then
- 'Make geometry approximation local
- MakeLocal oSelecto&".geomapprox", siDefaultPropagation
- MakeLocal oClone&".geomapprox", siDefaultPropagation
- 'Set subdivision level expresssions
- SetExpr oClone&".geomapprox.gapproxmosl", oSelecto&".geomapprox.gapproxmosl"
- SetExpr oClone&".geomapprox.gapproxmordrsl", oSelecto&".geomapprox.gapproxmordrsl"
- end if
- 'If object is a surfmsh
- if oSelecto.Type = "surfmsh" then
- 'Make geometry approximation local
- MakeLocal oSelecto&".geomapprox", siDefaultPropagation
- MakeLocal oClone&".geomapprox", siDefaultPropagation
- 'Set subdivision level expresssions
- SetExpr oClone&".geomapprox.gapproxvwustep", oSelecto&".geomapprox.gapproxvwustep"
- SetExpr oClone&".geomapprox.gapproxvwvstep", oSelecto&".geomapprox.gapproxvwvstep"
- end if
- 'Set a new Regex pattern that finds any letters after - at the end of its name
- regEx.Pattern = "-[a-zA-Z]+$"
- 'Reset oMergedCheck
- oMergedCheck = "nothing"
- 'Execute the regex on the selection
- Set Matches = regEx.Execute(oSelecto)
- For Each Match in Matches
- oCloneCheck = Match.Value
- Next
- 'If the selection doesnt end in -MergedMesh then re-enable its selectability
- if oMergedCheck <> "-MergedMesh" then
- SetValue oClone & ".visibility.selectability", True
- end if
- 'Remove Model name from oSelecto
- oModelo = oSelecto.Model
- oSelName = replace( oSelecto, oModelo&".", "")
- 'Rename The Clone
- SetValue oClone & ".Name", oSelName&"-Clone"
- 'Select original object
- SelectObj oSelecto
- if IsAClone = "yes" then
- LogMessage "Created a mirror clone of " & oSelecto & " (" & oSelName & "-Clone)"
- else
- LogMessage "Created a mirror duplicate of " & oSelecto & " (" & oSelName & "-Clone)"
- end if
- oFinalSelect.Add oSelecto
- end if
- else
- LogMessage oCol(i) & " is an invalid selection type (" & TypeName( oCol(i) ) & ")"
- end if
- next
- 'If there is more than one item in oCol then select the objects in the oFinalSelect collection
- if oCol.Count > 1 then
- SelectObj oFinalSelect
- end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement