Notifications
Clear all

[Closed] can you fix this script

i got some script
and modified this srcipt for my work
but there is problem
pls. can you fix them

fn UVWMapFit objArray useSel:#none=
(
undo “OS3D uvwfit ” on

for theObj in objArray do
( themap = theobj.uvwmap
–RESET THE GIZMO SCALE FIRST:
–Multiply the gizmo’s transformation with the inverse of a matrix created from its scale factor

theMap.gizmo.transform *= inverse (scaleMatrix theMap.gizmo.transform.scalepart)

–RESULT: the gizmo scaling will be reset to [1,1,1]

–GET THE MESH IN OBJECT SPACE BEFORE PRS AND WSM
–NOTE that this will get the mesh from TOP of the modifier stack just before PRS transforms.
–This means that the script SHOULD be applied to the UVW_Mapping modifier only when it is
–the TOP modifier on the stack, otherwise the geometry used might not be the geometry
–that the modifier is really applied to.

theMesh = theObj.mesh

–TRANSFORM ALL VERTICES IN GIZMO SPACE AND FIND MIN. AND MAX. OF GIZMO BBOX

minX = minY = minZ = 100000000 –initialize min.values to very large numbers
maxX = maxY = maxZ = -100000000 –initialize max.values to very low numbers
theTM = theMap.gizmo.transform –store the transformation matrix of the UVW gizmo in a variable
theTMInv = inverse theTM –calculate the inverse of the gizmo TM and store in another variable

–DEPENDING ON THE OPTIONAL 3RD ARGUMENT, GET THE VERTICES TO OPERATE ON:
theVerts = case useSel of
(
–If no selection is defined, use a bitarray containing ALL vertices.
#none: #{1…theMesh.numverts}

–If vertex selection is requested, get the selection from the mesh
#verts: (getVertSelection theMesh)

–if edge selection is requested, convert the edge selection to vertex list:
#edges: (meshop.getVertsUsingEdge theMesh (getEdgeSelection theMesh))

–if face selection is requested, convert the face selection to vertex list:
#faces: (meshop.getVertsUsingFace theMesh (getFaceSelection theMesh))
)

for v in theVerts do –loop through all vertices in the bitarray defined above
(
theVert = (getVert theMesh v) * theTMInv –get the vertex position in gizmo space

–Record min. and max. values for X, Y and Z:
if theVert.x > maxX do maxX = theVert.x
if theVert.y > maxY do maxY = theVert.y
if theVert.z > maxZ do maxZ = theVert.z
if theVert.x < minX do minX = theVert.x
if theVert.y < minY do minY = theVert.y
if theVert.z < minZ do minZ = theVert.z
)–end v loop

delete theMesh –delete the TriMesh value from memory

–CALCULATE THE GIZMO-ALIGNED BOX SIZE
case theMap.axis of –take into account axis orientation
(
0: (
X = maxZ – minZ –gizmo’s Z axis is aligned to the object’s local X axis
Y = maxY – minY
Z =maxX – minX
)
1: (
X = maxX – minX
Y = maxZ – minZ –gizmo’s Z axis is aligned to the object’s local Y axis
Z =maxY – minY
)
2: (
X = maxX – minX
Y = maxY – minY
Z = maxZ – minZ –gizmo’s Z axis is aligned to the object’s local Z axis
)
)–end case

if theVerts.numberset == 0 then –if no vertices processed, set all sizes to 10
X = Y = Z = 10
else –if any vertices are processed, add 0.1 % padding
(
X += 0.001X
Y += 0.001
Y
Z += 0.001*Z
)

–Set the values for length, width and height in the general case
theMap.length = Y
theMap.width = X
theMap.height= Z

case theMap.maptype of –now take into account the mapping type
(
default: theMap.width = theMap.length = amax #(X,Y) –get the bigger of the two values for width and length
0: () –do nothing for planar mode – will use the above general case
1: (
case theMap.axis of –special axis handling for cylinder!
(
0: (theMap.width = theMap.length = amax #(X,Z); theMap.height = Y)
1: (theMap.width = theMap.length = amax #(Y,Z); theMap.height = X)
2: (theMap.width = theMap.length = amax #(X,Y); theMap.height = Z)
)–end axis case
)
2: theMap.width = theMap.length = theMap.height = amax #(X,Y,Z) –radius from the largest of the 3 values
3: theMap.width = theMap.length = theMap.height = amax #(X,Y,Z) –radius from the largest of the 3 values
4: () –do nothing for box mode – will use the above general case
)–end maptype case

–CALCULATE THE CENTER IN GIZMO SPACE – IT IS THE MIDDLE OF THE BOX’S DIAGONAL
theCenter = ([maxX,maxY,maxZ] + [minX,minY,minZ])/2.0
–CONVERT THE CENTER INTO OBJECT SPACE BY MULTIPLYING WITH THE GIZMO TM
theCenter *= theTM
–THEN CENTER THE GIZMO
theTM.row4 = theCenter –set the translation part of the matrix to the new center
theMap.gizmo.transform = theTM –and assign the matrix back to the gizmo transformation
)

)

fn removeAllModifiers objArray =
(
undo “OS3D Remove All Modifiers” on

(
for item in objArray do
(
cc = item.modifiers.count
while cc>0 do
(
deleteModifier item cc
cc -= 1
)
)
)
)
fn SetMaterial InObject objArray =
(
undo “OS3D Set Material on selection” on
(
for item in objArray do
(
try (item.material = InObject.material)
catch(print (“Could not set material on:” + item.name))
)
)

)
fn copyModifiers InObject objArray applyToAll =
(
undo “OS3D Set Modifiers on selection” on
(
numMods = InObject.modifiers.count
if numMods != 0 then
(
for item in objArray do
(
test = numMods
if applyToAll then (run = true)
else
(
if item.modifiers.count == 0 then (run = true)
else
(
DispMessage = “The following item: ” + item.name + “
already has modifiers on it, do you still want to apply the modifiers to this?”
if querybox DispMessage then run = true else run = false
)
)

if run then
(
while test > 0 do
(
–print test
try
(
tmp = copy InObject.modifiers[test]
addModifier Item tmp
–addModifier Item InObject.modifiers[test] –all modifiers becomes an instance of the original
)
catch
(
print “something didnt work when applying the following modifier”
)
test -=1
)
)

)
)
else (print “no modifiers”)
)
)

rollout OS3DCopyMaterialModifiers “OS3D.se Copy materials and modifiers” width:272 height:136
(
local debug = false
local InputObject
local applyToAll

label lbl1 “Copy from” pos:[8,8] width:96 height:16
button btnPasteMaterial “Paste Material to selection” pos:[128,28] width:136 height:24 toolTip:“Paste Material to selection”
button btnPasteModifiers “Paste Modifers to selection” pos:[128,57] width:136 height:24 toolTip:“Paste Modifiers to selection”
label lbl2 “Copy to” pos:[128,8] width:96 height:16
button btnPasteMatAndMod “Paste Both to selection” pos:[128,86] width:136 height:24 toolTip:“Paste Both Material and Modifiers to selection”
button btnFromObj “Pick object” pos:[7,28] width:114 height:24 toolTip:“Pick object to copy modifiers and material from”
–label lbl3 “OS3D.se Single copy material and modiers. v0.1” pos:[8,3] width:256 height:16

button btnRemoveModifiers “Remove modifiers” pos:[7,106] width:114 height:24 toolTip:“Remove all modifiers on selection”
label lbl8 “Delete modifiers” pos:[7,88] width:95 height:13
button btnSelByName “Sel by Name” pos:[7,57] width:114 height:24 toolTip:“Select by name, show a listview”
button btnPasteMatAndModandFIT ” paste Both AND FIT ” pos:[7,86] width:114 height:22 toolTip:“OS3D uvwfit”
checkbox chk2 “Paste modifiers to all” pos:[129,116] width:136 height:16

on OS3DCopyMaterialModifiers open do
(
escapeEnabled = true
applyToAll = chk2.state
)
on chk2 changed state do
(
applyToAll = chk2.state
)
on btnPasteMaterial pressed do
(
selArray = selection as array
if inputObject != undefined and selArray != undefined then
(
SetMaterial inputObject selArray
)
)
on btnPasteModifiers pressed do
(
selArray = selection as array
if inputObject != undefined and selArray != undefined then
(
copyModifiers inputObject selArray applyToAll
)
)
on btnPasteMatAndMod pressed do
(
selArray = selection as array
if inputObject != undefined and selArray != undefined then
(
undo “OS3D Set Material and Modifiers on selection” on
(
SetMaterial inputObject selArray
copyModifiers inputObject selArray applyToAll
)
)
)

on btnPasteMatAndModandFIT pressed do
(
selArray = selection as array
if inputObject != undefined and selArray != undefined then
(
undo “OS3D uvwfit ” on
(
SetMaterial inputObject selArray
copyModifiers inputObject selArray applyToAll
uvwfit selArray useSel:#none=

)
)
)

on btnFromObj pressed do
(
–InputObject = pickobject()
if (selection as array).count != 1 then
(messagebox “You can only have one object selected as the from object”)
inputObject = (selection as array)[1]
if InputObject != undefined do
(
btnFromObj.caption = (“Pick-> ” + InputObject.name)
btnSelByName.caption = (“Sel-> ” + InputObject.name)
)
)
on btnRemoveModifiers pressed do
(
selArray = selection as array
if selArray != undefined then
(
removeAllModifiers selArray
)
)
on btnSelByName pressed do
(
InputObject = theShapes = selectByName title:“Select Object” buttonText:“Select input object” showHidden:true single:true
if InputObject != undefined do
(
btnFromObj.caption = (“Pick-> ” + InputObject.name)
btnSelByName.caption = (“Sel-> ” + InputObject.name)
)
)
)
createdialog OS3DCopyMaterialModifiers

4 Replies

How about telling us what your problem is?

yes
i add fn UVWMapFit objArray useSel:#none=
(

)

and

on btnPasteMatAndModandFIT pressed do
(
selArray = selection as array
if inputObject != undefined and selArray != undefined then
(
undo “OS3D uvwfit ” on
(
SetMaterial inputObject selArray
copyModifiers inputObject selArray applyToAll
uvwfit selArray useSel:#none=

)

i add routine above in old script
but after that , routine is not work
can you understand my situation
sorry my poor english skill

uvwfit selArray useSel:#none=

should be

uvwfit selArray useSel:#none

(no = sign after #none)

only i added function
i deleted = sign

ui screen is on ok
but i put buttons , all didn’t not work
what problem also ?
sorry my skills~