Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '-----------------------------------------------------------------------------------------------------------------'
- 'To use this script you must first create a point / edge cluster of all the components along the center that you 'want included in the scale op. The cluster should be named CL, but if it isn't this script wil do a few (very) 'simple checks for clusters it could use. Probably the best way is to have the cluster you want to use selected 'when you run this, and it will ask if you want to rename it to CL, otherwise it will look for a cluster named 'Edge, then a cluster named Point and ask if you want to use those hehe, clicking no to one check will just let 'the script go on to the next, at the end it will check if there is any CL cluster, if not it will cancel out.
- 'Once it runs, it will scale the CL cluster to 0 on the selected object(s) x axis, and move the new MoveComponent 'Op into the animation stack.
- 'If there is already a movecomponentop in place the script will ask you if you want to freeze the object, if you 'select no, it will count how many move operators exist and then ask if you want to delete the highest one found, 'click yes if you have only one movecomponentop op in either the shape modelling or animation stacks, or click no 'if the existing movecomponentop(s) are all in the modelling stack.
- 'If you really don't want to freeze anything, you could do this manually by selecting the CL cluster and running 'my Zero X script and move the new movecomponent op manually (drag and drop :) into the animation stack.
- '-----------------------------------------------------------------------------------------------------------------'
- dim oSelecto, ScriptCancel, BP, POINTstr, EDGEstr, CLstr, oPointObj, oEdgeObj, oCLObj, oMCobj, pref
- dim regEx, Match, Matches, oSubdCtrlCheck, MoveComponentCount, MCstr, StopLoop, JustIncaseAbort
- 'Set up a regExp for later use
- 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 > 1 Then
- 'Add the application selection to oCol
- Set oSelection = Application.Selection
- 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 oSubdCtrlCheck
- oSubdCtrlCheck = "Nothing"
- 'Execute the regex on the selection
- Set Matches = regEx.Execute(oSelection(i))
- For Each Match in Matches
- oSubdCtrlCheck = Match.Value
- Next
- 'If the selection doesnt end in -SubdCtrl then add it to the oCol Collection.
- if oSubdCtrlCheck <> "-SubdCtrl" then
- Logmessage oSelection(i) & " is pure evil, added to oCol"
- oCol.add oSelection(i)
- else
- Logmessage oSelection(i) & " is suspiciously nice, rejected"
- end if
- next
- elseIf Application.Selection.count = 1 Then
- oCol.add Application.Selection(0)
- else
- 'If no object is selected, start a picksession
- LogMessage "Select The Control Mesh (-Modelling)"
- PickObject "Select The Control Mesh (-Modelling)", " ", oSelecto
- 'Add Picksession object to oCol
- oCol.add oSelecto
- end if
- for i = 0 to (oCol.count-1)
- set oSelecto = oCol(i)
- 'Check if the cluster is selected instead of the mesh, saves having to re-select the mesh after creating the CL cluster
- if TypeName( oSelecto ) = "Cluster" then
- oSelecto = oSelecto.Parent3DObject
- end if
- 'Make sure the selection is a Polymesh, if it isn't then give the user one last try to select one.
- set oSelecto = Dictionary.GetObject( oSelecto, false )
- if oSelecto.Type = "polymsh" then
- ScriptCancel = "no"
- else
- LogMessage oSelecto & " is a " & oSelecto.Type & ", not a polymsh"
- BP = XSIUIToolkit.Msgbox( oSelecto & " is not a polymsh, do you want to select something else?", 4, "No Polygon Mesh Selected" )
- if BP = 6 then
- PickObject "Please select a polygon mesh", " ", oSelecto
- if oSelecto.Type = "polymsh" then
- ScriptCancel = "no"
- else
- XSIUIToolkit.Msgbox "Bah, I give up.. " & oSelecto & " is a " & oSelecto.Type & " !", 1, "No Polygon Mesh Selected"
- Logmessage "Script Cancelled - Next time select a Polygon Mesh instead of a " & oSelecto.Type & "! :)"
- ScriptCancel = "yes"
- end if
- else
- ScriptCancel = "yes"
- end if
- end if
- POINTstr = oSelecto & ".polymsh.cls.Point"
- EDGEstr = oSelecto & ".polymsh.cls.edge.clslist.Edge"
- CLstr = oSelecto & ".polymsh.cls.CL"
- set oPointObj = Dictionary.GetObject( POINTstr, false )
- set oEdgeObj = Dictionary.GetObject( EDGEstr, false )
- set oCLObj = Dictionary.GetObject( CLstr, false )
- 'Check if CL / point / edge cluster exists
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName( oEdgeObj ) = "Nothing" and TypeName( oPointObj ) = "Nothing" and TypeName( ocol(i) ) <> "Cluster" then
- XSIUIToolkit.Msgbox "You need to create an edge / point cluster of the center loop for " & oSelecto & " and name it CL", 1, "No CL Cluster Found"
- Logmessage "You need to create an edge / point cluster of the center loop for " & oSelecto & " and name it CL"
- ScriptCancel = "yes"
- end if
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName( oCol(i) ) = "Cluster" then
- Logmessage "Selection is a cluster"
- BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but you had a cluster selected when you ran this script, do you want to rename it to CL ? (" & oCol(i) & ")", 4, "Edge Cluster Detected" )
- if BP = 6 then
- LogMessage oCol(i).FullName
- SetValue oCol(i) & ".Name" , "CL"
- logmessage "Selected cluster renamed to CL"
- set oCLObj = Dictionary.GetObject( CLstr, false )
- end if
- end if
- 'If no CL cluster exists but an Edge cluster exists, ask if user wants to rename it to CL
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName ( oEdgeObj ) = "Cluster" and oCol(i).Name <> "Edge" then
- Logmessage "Edge Cluster Detected"
- BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but an Edge cluster was detected, do you want to rename it to CL ?", 4, "Edge Cluster Detected" )
- if BP = 6 then
- SetValue oSelecto & ".polymsh.cls.edge.clslist.Edge.Name", "CL"
- logmessage "Edge cluster renamed to CL"
- set oCLObj = Dictionary.GetObject( CLstr, false )
- end if
- end if
- 'If no CL cluster exists but a Point cluster exists, ask if user wants to rename it to CL
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName ( oPointObj ) = "Cluster" and oCol(i).Name <> "Point" then
- LogMessage "Point Cluster Detected"
- BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but a Point cluster was detected, do you want to rename it to CL ?", 4, "Point Cluster Detected" )
- if BP = 6 then
- SetValue oSelecto & ".polymsh.cls.Point.Name", "CL"
- logmessage "Point cluster renamed to CL"
- set oCLObj = Dictionary.GetObject( CLstr, false )
- end if
- end if
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" then
- ScriptCancel = "yes"
- LogMessage oSelecto & " was skipped since it has no CL cluster"
- end if
- 'Check if a MoveComponent op already exists
- MCstr = oSelecto & ".polymsh.movecomponentop"
- set oMCobj = Dictionary.GetObject( MCstr, false )
- if TypeName( oMCobj ) <> "Nothing" and ScriptCancel = "no" then
- BP = XSIUIToolkit.Msgbox( "Do you want to freeze " & oSelecto & " ? : If there is more than one movecomponent op in either the Shape Modelling or Animation stacks then this won't work (clicking no will determine how many move component ops there are, then ask if you want to delete the highest one)", 3, "Move Component Ops Detected, Freeze " & oselecto & "?" )
- if BP = 6 then
- LogMessage "Freezing Object"
- FreezeObj oSelecto
- elseIf BP = 7 then
- LogMessage "Move Component operator already in place, determining what number the new one will be"
- 'Reset some variables
- JustIncaseAbort = 0
- MoveComponentCount = 0
- StopLoop = "no"
- '-----------------------------Loop Start-----------------------------'
- do
- 'Add 1 onto the counter that will be used to see how many movecomponent ops exist
- MoveComponentCount = MoveComponentCount + 1
- 'Check to see if a movecomponent op with the count number exists e.g. movecomponentop[15]
- MCstr = oSelecto & ".polymsh.movecomponentop["&MoveComponentCount&"]"
- set oMCobj = Dictionary.GetObject( MCstr, false )
- if TypeName( oMCobj ) = "Nothing" then
- StopLoop = "yes"
- end if
- 'Increment an abort counter to stop an infinite loop
- JustIncaseAbort = JustIncaseAbort + 1
- Loop Until StopLoop = "yes" or JustIncaseAbort = 10000
- '-----------------------------Loop Finish-----------------------------'
- 'If the abort number has been reached then cancel the script
- if JustIncaseAbort = 10000 then
- LogMessage "Either something has gone horribly wrong or you have more than 10,000 move component ops ?? in which case it might be time to freeze the modelling stack :)"
- ScriptCancel = "yes"
- end if
- LogMessage oSelecto & " had " & MoveComponentCount & " movecomponentops"
- if ScriptCancel = "no" then
- BP = XSIUIToolkit.Msgbox( MoveComponentCount & " movemomponent ops were found, is there one (singular) in either the Shape Modelling or Animation stack ? ( clicking yes will delete MoveComponent[" & MoveComponentCount - 1 &"] )", 3, "Move Component Ops Detected" )
- if BP = 6 then
- MoveComponentCount = MoveComponentCount - 1
- set DeleteMoveOp = Dictionary.GetObject( oSelecto&".movecomponentop[" & MoveComponentCount & "]", false )
- DeleteObj DeleteMoveOp
- MCstr = oSelecto&".polymsh.movecomponentop["&MoveComponentCount&"]"
- LogMessage oSelecto & ".polymsh.movecomponentop[" & MoveComponentCount & "] was deleted"
- elseIf BP = 2 then
- LogMessage "Cancelling Script"
- ScriptCancel = "yes"
- end if
- end if
- else
- LogMessage "Cancelling Script"
- ScriptCancel = "yes"
- end if
- else
- MCstr = oSelecto & ".polymsh.movecomponentop"
- end if
- if ScriptCancel = "no" then
- 'Get the status of proportional modelling setting
- pref = GetUserPref ("3D_TRANSFO_PROPORTIONAL_CHANGED")
- 'If proportional modelling was enabled, turn it off
- if pref = 1 then
- SetUserPref "3D_TRANSFO_PROPORTIONAL_CHANGED", 0
- end if
- 'Select the CL cluster and scale it to 0 on the x axis
- Scale oCLObj, 0, 1, 1, siRelative, siParent, siObj, siX, , , , , , , , 0
- SelectObj oSelecto
- 'Move the scale op to the animation stack
- MoveOperatorAfter oSelecto & ".polymsh", MCstr, oSelecto & ".polymsh.shapemarker"
- 'If proportional modelling was previously enabled, turn it back on
- if pref = 1 then
- SetUserPref "3D_TRANSFO_PROPORTIONAL_CHANGED", 1
- end if
- LogMessage oSelecto&".polymsh.cls.CL" & " was scaled to 0 on the x axis and the MoveComponent op transferred to the animation stack. "
- end if
- Next
- SelectObj oCol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement