[Closed] couple of problems with array modifier script
I got some problems with the script im working on. The script is a kinda of a Array Object modifier, which creates instances of the object like the array function, but more handy if you need to be able to change the amount or spacing.
Got these problems:
-
When the modifier is added, the ‘2D’ and ‘3D’ spinners doesn’t get disabled at startup. Also when the object gets deselected, the same happens, all fields gets enabled. I tried to add the enabled:true to the parameter rollout, but it apparently doesn’t work.
-
I got some variables which gets reset every time I deselect the object. I tried to use global but I can’t use that because it affects all objects that got the array object modifier on them. So if the modifier is applied to more then one object, it gets screwed up.
Here is the script:
--------------------------------------------
-- arrayobject.ms --
-- By Anders K. Nielsen (akn@mcgreed.dk) --
-- v 0.5 --
-- Created On: 16/12/05 --
-- Modified On: 04/01/05 --
-- tested using 3DS Max 7.0 SP1 --
--------------------------------------------
-- Description: --
-- Well, I'll get to that....one day --
--------------------------------------------
(
plugin modifier ArrayObjectMod
name:"Array Object"
classID:#(0x216072cc, 0x69dc1a4a)
(
parameters main rollout:ArraySettings (
boundingBox type:#boolean animatable:false ui:showAsBoundingBox default:false
dimSelect type:#integer animatable:false ui:dimensionsSelect default:1
arrAmount1 type:#integer animatable:false ui:arrayAmount1 default:5 enabled:true
arrSpaceX1 type:#float animatable:false ui:arraySpaceX1 default:50 enabled:true
arrSpaceY1 type:#float animatable:false ui:arraySpaceY1 default:0 enabled:true
arrSpaceZ1 type:#float animatable:false ui:arraySpaceZ1 default:0 enabled:true
arrAmount2 type:#integer animatable:false ui:arrayAmount2 default:1 enabled:false
arrSpaceX2 type:#float animatable:false ui:arraySpaceX2 default:0 enabled:false
arrSpaceY2 type:#float animatable:false ui:arraySpaceY2 default:0 enabled:false
arrSpaceZ2 type:#float animatable:false ui:arraySpaceZ2 default:0 enabled:false
arrAmount3 type:#integer animatable:false ui:arrayAmount3 default:1 enabled:false
arrSpaceX3 type:#float animatable:false ui:arraySpaceX3 default:0 enabled:false
arrSpaceY3 type:#float animatable:false ui:arraySpaceY3 default:0 enabled:false
arrSpaceZ3 type:#float animatable:false ui:arraySpaceZ3 default:0 enabled:false
)
rollout ArraySettings "Array Modifier" (
group "General:" (
checkbox showAsBoundingBox "Bounding Box?"
button updateArrayButton "Update" width:100 height:24
)
group "Array Dimensions" (
radiobuttons dimensionsSelect labels:#("1D", "2D", "3D") columns:3 align:#left
)
group "1D Dimension" (
spinner arrayAmount1 "Amount 1D:" range:[1,1000,5] fieldwidth:40 align:#right type:#integer
spinner arraySpaceX1 "Spacing X:" range:[-9999999,9999999,50] fieldwidth:50 align:#right type:#float
spinner arraySpaceY1 "Spacing Y:" range:[-9999999,9999999,0] fieldwidth:50 align:#right type:#float
spinner arraySpaceZ1 "Spacing Z:" range:[-9999999,9999999,0] fieldwidth:50 align:#right type:#float
) -- End group 'Settings - 1D'
group "2D Dimension" (
spinner arrayAmount2 "Amount 2D:" range:[1,1000,1] fieldwidth:40 align:#right type:#integer
spinner arraySpaceX2 "Spacing X:" range:[-9999999,9999999,0] fieldwidth:50 align:#right type:#float
spinner arraySpaceY2 "Spacing Y:" range:[-9999999,9999999,0] fieldwidth:50 align:#right type:#float
spinner arraySpaceZ2 "Spacing Z:" range:[-9999999,9999999,0] fieldwidth:50 align:#right type:#float
) -- End group 'Settings - 2D'
group "3D Dimension" (
spinner arrayAmount3 "Amount 3D:" range:[1,1000,1] fieldwidth:40 align:#right type:#integer
spinner arraySpaceX3 "Spacing X:" range:[-9999999,9999999,0] fieldwidth:50 align:#right type:#float
spinner arraySpaceY3 "Spacing Y:" range:[-9999999,9999999,0] fieldwidth:50 align:#right type:#float
spinner arraySpaceZ3 "Spacing Z:" range:[-9999999,9999999,0] fieldwidth:50 align:#right type:#float
) -- End group 'Settings - 3D'
group "Other:" (
button eraseButton "Erase Array Objects" height:24
)
global parentObjID
global Parent_Obj_Name
global Parent_Obj_Pos
global Parent_Obj_Color
global arrParentObjs
global BoundingBox
global Obj_Amount1
global Obj_SpaceX1
global Obj_SpaceY1
global Obj_SpaceZ1
global Obj_Amount2
global Obj_SpaceX2
global Obj_SpaceY2
global Obj_SpaceZ2
global Obj_Amount3
global Obj_SpaceX3
global Obj_SpaceY3
global Obj_SpaceZ3
global Obj_Amount1Old
global Obj_Amount2Old
global Obj_Amount3Old
global dimensionsSelectOld
fn createObject L1D L2D L3D = (
strNewChildName = Parent_Obj_Name + ".arr_" + (L1D as string) + "x" + (L2D as string) + "x" + (L3D as string)
child_pos_x = Parent_Obj_Pos[1] + (L1D * Obj_SpaceX1)
child_pos_y = Parent_Obj_Pos[2] + (L1D * Obj_SpaceY1)
child_pos_z = Parent_Obj_Pos[3] + (L1D * Obj_SpaceZ1)
if dimensionsSelect.state > 1 do (
child_pos_x = child_pos_x + (L2D * Obj_SpaceX2)
child_pos_y = child_pos_y + (L2D * Obj_SpaceY2)
child_pos_z = child_pos_z + (L2D * Obj_SpaceZ2)
)
if dimensionsSelect.state > 2 do (
child_pos_x = child_pos_x + (L3D * Obj_SpaceX3)
child_pos_y = child_pos_y + (L3D * Obj_SpaceY3)
child_pos_z = child_pos_z + (L3D * Obj_SpaceZ3)
)
objectCheck = execute ("$'" + strNewChildName + "'")
if objectCheck == undefined then (
-- Object doesn't exist, create new instance
objectCheck = instance arrParentObjs[parentObjID] name:strNewChildName
)
objectCheck.pos = [child_pos_x, child_pos_y, child_pos_z]
objectCheck.wireColor = Parent_Obj_Color
objectCheck.boxMode = showAsBoundingBox.checked
)
fn updateCheck = (
-- Check if there is objects that isn't in the array any longer but still in scene after changes
Redudent_Amount = false
If Obj_Amount1Old == undefined do (
Obj_Amount1Old = 0
)
If Obj_Amount2Old == undefined do (
Obj_Amount2Old = 0
)
If Obj_Amount3Old == undefined do (
Obj_Amount3Old = 0
)
If dimensionsSelectOld == undefined do (
dimensionsSelectOld = 1
)
If arrParentObjs == undefined do (
arrParentObjs = selection as array
)
If Obj_Amount1 < Obj_Amount1Old do (
Redudent_Amount = true
)
if (Obj_Amount2 < Obj_Amount2Old and dimensionsSelect.state > 1) do (
Redudent_Amount = true
)
if (Obj_Amount3 < Obj_Amount3Old and dimensionsSelect.state > 2) do (
Redudent_Amount = true
)
if dimensionsSelect.state < dimensionsSelectOld do (
Redudent_Amount = true
)
if Redudent_Amount == true do (
confirmDelete = queryBox("There is objects that will not belong to the modifier after changes.
Do you want all array objects to be deleted before proceeding?")
if confirmDelete == true do (
execute ("delete $'" + Parent_Obj_Name + ".arr_*'")
)
)
)
fn updateArray = (
-- BEGIN - Update array
Obj_Amount1 = arrayAmount1.value
Obj_SpaceX1 = arraySpaceX1.value
Obj_SpaceY1 = arraySpaceY1.value
Obj_SpaceZ1 = arraySpaceZ1.value
Obj_Amount2 = arrayAmount2.value
Obj_SpaceX2 = arraySpaceX2.value
Obj_SpaceY2 = arraySpaceY2.value
Obj_SpaceZ2 = arraySpaceZ2.value
Obj_Amount3 = arrayAmount3.value
Obj_SpaceX3 = arraySpaceX3.value
Obj_SpaceY3 = arraySpaceY3.value
Obj_SpaceZ3 = arraySpaceZ3.value
updateCheck()
-- BEGIN - Check how many objects will be created and warn if there is many
tempCount = Obj_Amount1
if dimensionsSelect.state > 1 do (
tempCount = tempCount * Obj_Amount2
)
if dimensionsSelect.state > 2 do (
tempCount = tempCount * Obj_Amount3
)
confirmArray = true
if tempCount > 100 do (
confirmArray = queryBox "The amount of objects created by the array
is 100+. This might take a while.
Sure you want to proceed?" title:"Confirm Array"
)
if confirmArray == true do (
for x = 1 to selection.count do (
-- get all objects in selection
parentObjID = x
Parent_Obj_Name = arrParentObjs[parentObjID].name
Parent_Obj_Pos = arrParentObjs[parentObjID].pos
Parent_Obj_Color = arrParentObjs[parentObjID].wireColor as color
case dimensionsSelect.state of (
1:(
for loop1D = 0 to (Obj_Amount1 - 1) do (
if loop1D != 0 do (
createObject loop1D 0 0
)
)
) -- end case 1
2:(
for loop2D = 0 to (Obj_Amount2 - 1) do (
for loop1D = 0 to (Obj_Amount1 - 1) do (
if not (loop1D == 0 and loop2D == 0) do (
createObject loop1D loop2D 0
)
)
)
) -- end case 2
3:(
for loop3D = 0 to (Obj_Amount3 - 1) do (
for loop2D = 0 to (Obj_Amount2 - 1) do (
for loop1D = 0 to (Obj_Amount1 - 1) do (
if not (loop1D == 0 and loop2D == 0 and loop3D == 0) do (
createObject loop1D loop2D loop3D
)
)
)
)
) -- end case 3
) -- end case statement dimensionsSelect
) -- end for
-- Update old values for amount check
Obj_Amount1Old = Obj_Amount1
Obj_Amount2Old = Obj_Amount2
Obj_Amount3Old = Obj_Amount3
dimensionsSelectOld = dimensionsSelect.state
)
)
fn eraseArray = (
confirmDelete = queryBox("Do you want all array objects to be deleted?
Original will be left alone.")
if confirmDelete == true do (
execute ("delete $'" + Parent_Obj_Name + ".arr_*'")
)
)
on updateArrayButton pressed do updateArray()
on dimensionsSelect changed state do (
-- change which spinners and inputfields is active
case dimensionsSelect.state of (
1:(
arrayAmount2.enabled = false
arrayAmount3.enabled = false
arraySpaceX2.enabled = false
arraySpaceY2.enabled = false
arraySpaceZ2.enabled = false
arraySpaceX3.enabled = false
arraySpaceY3.enabled = false
arraySpaceZ3.enabled = false
)
2:(
arrayAmount2.enabled = true
arrayAmount3.enabled = false
arraySpaceX2.enabled = true
arraySpaceY2.enabled = true
arraySpaceZ2.enabled = true
arraySpaceX3.enabled = false
arraySpaceY3.enabled = false
arraySpaceZ3.enabled = false
)
3:(
arrayAmount2.enabled = true
arrayAmount3.enabled = true
arraySpaceX2.enabled = true
arraySpaceY2.enabled = true
arraySpaceZ2.enabled = true
arraySpaceX3.enabled = true
arraySpaceY3.enabled = true
arraySpaceZ3.enabled = true
)
)
)
on eraseButton pressed do eraseArray()
) -- End rollout 'Array Modifier'
on create do (
arrParentObjs = selection as array
Obj_Amount1Old = 0
Obj_Amount2Old = 0
Obj_Amount3Old = 0
dimensionsSelectOld = 1
)
rollout AboutArray "About..." rolledUp:false (
label TitleLabel "Array Object Modifier v0.5"
label CreatedByLabel "Created by"
label CreatedByName "Anders K. 'McGreed' Nielsen"
label NoteLabel1 "tested using 3DS Max 7"
)
)
)