[Closed] Max Scrip button not functioning
Hey there.
I am trying to create a simple maxscrip with a rollout.
I got the button’s functionality from the listener and it works when I reun the script with an object selected without the rollout.
However when I use the rollout the botton doesn’t do anything, here is the script and thank you in advance:
(
rollout UVtools “UV tools” width:100 height:90
(
button Unwrap “Auto Unwrap” pos:[10,23] width:79 height:24
groupBox grp1 “UV tools” pos:[4,4] width:92 height:79
)
on execute do CreateDialog UVtools
on Unwrap pressed do
(
subobjectLevel = 1
$.EditablePoly.SetSelection #Vertex #{}
subobjectLevel = 2
$.EditablePoly.SetSelection #Edge #{}
subobjectLevel = 3
$.EditablePoly.SetSelection #Edge #{}
subobjectLevel = 4
$.EditablePoly.SetSelection #Face #{}
subobjectLevel = 5
$.EditablePoly.SetSelection #Face #{}
subobjectLevel = 0
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.modifiers[#unwrap_uvw].unwrap.move ()
$.modifiers[#Unwrap_UVW].texMapList.count = 0
$.modifiers[#Unwrap_UVW].texMapIDList.count = 0
$.modifiers[#Unwrap_UVW].baseMaterial_list.count = 1
$.modifiers[#Unwrap_UVW].baseMaterial_list[1] = sceneMaterials[“BWDA_Enlighten”]
$.modifiers[#Unwrap_UVW].texMapList.count = 1
$.modifiers[#Unwrap_UVW].texMapIDList.count = 1
$.modifiers[#Unwrap_UVW].texMapList.count = 2
$.modifiers[#Unwrap_UVW].texMapIDList.count = 2
$.modifiers[#Unwrap_UVW].texMapList[1] = Checker ()
$.modifiers[#Unwrap_UVW].texMapIDList[1] = -1
$.modifiers[#Unwrap_UVW].texMapList[2] = Checker ()
$.modifiers[#Unwrap_UVW].texMapIDList[2] = -1
subobjectLevel = 3
modPanel.setCurrentObject $.modifiers[#Unwrap_UVW]
actionMan.executeAction 0 “40021” – Selection: Select All
actionMan.executeAction 2077580866 “40047” – All Commands: Flatten Map Dialog
maxOps.CollapseNodeTo $ 1 off
subobjectLevel = 0
)
)
(
rollout UVtools "UV tools"
(
button Unwrap "Auto Unwrap" pos:[10,23] width:79 height:24
groupBox grp1 "UV tools" pos:[4,4] width:92 height:79
on Unwrap pressed do
(
subobjectLevel = 1
$.EditablePoly.SetSelection #Vertex #{}
subobjectLevel = 2
$.EditablePoly.SetSelection #Edge #{}
subobjectLevel = 3
$.EditablePoly.SetSelection #Edge #{}
subobjectLevel = 4
$.EditablePoly.SetSelection #Face #{}
subobjectLevel = 5
$.EditablePoly.SetSelection #Face #{}
subobjectLevel = 0
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.modifiers[#unwrap_uvw].unwrap.move ()
$.modifiers[#Unwrap_UVW].texMapList.count = 0
$.modifiers[#Unwrap_UVW].texMapIDList.count = 0
$.modifiers[#Unwrap_UVW].baseMaterial_list.count = 1
$.modifiers[#Unwrap_UVW].baseMaterial_list[1] = sceneMaterials["BWDA_Enlighten"]
$.modifiers[#Unwrap_UVW].texMapList.count = 1
$.modifiers[#Unwrap_UVW].texMapIDList.count = 1
$.modifiers[#Unwrap_UVW].texMapList.count = 2
$.modifiers[#Unwrap_UVW].texMapIDList.count = 2
$.modifiers[#Unwrap_UVW].texMapList[1] = Checker ()
$.modifiers[#Unwrap_UVW].texMapIDList[1] = -1
$.modifiers[#Unwrap_UVW].texMapList[2] = Checker ()
$.modifiers[#Unwrap_UVW].texMapIDList[2] = -1
subobjectLevel = 3
modPanel.setCurrentObject $.modifiers[#Unwrap_UVW]
actionMan.executeAction 0 "40021" -- Selection: Select All
actionMan.executeAction 2077580866 "40047" -- All Commands: Flatten Map Dialog
maxOps.CollapseNodeTo $ 1 off
subobjectLevel = 0
)
)
createDialog UVtools 100 90
)
Thank you!
Now I can see where I went wrong. Still have a lot to learn with this.
You’re welcome, glad I could help.
I got rid of the dialogue boxes for you in this version.
I also got rid of some of the unnecessary code related to unwrap_uv
I also added some error checking in it to check if an object is selected.
You could also check to see if its an edit poly as well. I’ll leave that to you
Try https://vimeo.com/user5796788/videos for some help.
If the object you are unwrapping has a known vert count you could get rid of
“actionMan.executeAction 0 “40021” – Selection: Select All” as well.
try(destroydialog UVtools) catch()
rollout UVtools "UV tools"
(
button Unwrap "Auto Unwrap" pos:[10,23] width:79 height:24
groupBox grp1 "UV tools" pos:[4,4] width:92 height:79
on Unwrap pressed do
(
if $ != undefined then
(
subobjectLevel = 1
$.EditablePoly.SetSelection #Vertex #{}
subobjectLevel = 2
$.EditablePoly.SetSelection #Edge #{}
subobjectLevel = 3
$.EditablePoly.SetSelection #Edge #{}
subobjectLevel = 4
$.EditablePoly.SetSelection #Face #{}
subobjectLevel = 5
$.EditablePoly.SetSelection #Face #{}
subobjectLevel = 0
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.modifiers[#Unwrap_UVW].baseMaterial_list[1] = sceneMaterials["BWDA_Enlighten"]
subobjectLevel = 3
modPanel.setCurrentObject $.modifiers[#Unwrap_UVW]
actionMan.executeAction 0 "40021" -- Selection: Select All
$.modifiers[#unwrap_uvw].unwrap2.fitRelax 50 0.1
$.modifiers[#unwrap_uvw].unwrap2.packNoParams()
--actionMan.executeAction 2077580866 "40047" -- All Commands: Flatten Map Dialog
convertToPoly $
--maxOps.CollapseNodeTo $ 1 off
subobjectLevel = 0
) else
(messageBox "You need to select an object" title:"Computer says no...")
)
)
createDialog UVtools 100 90
but it still needs some cleanup and double-check. there are some things fixed:
rollout UVtools "UV tools" width:100
(
group "UV tools" -- easier to use group instead of groupbox
(
button Unwrap "Auto Unwrap" pos:[10,23] width:79 height:24
)
on Unwrap pressed do
(
nodes = for node in selection where iskindof node GeometryClass collect node -- i want to support multiple selection. uwrap works for geometry class only
if nodes.count == 0 then (messageBox "You need to select an object" title:"Computer says no...")
else undo "Pack UVWs" on -- do it undoable
(
max modify mode -- unwrap modifier methods work only in modify mode
for node in nodes do
(
modi = Unwrap_UVW name:"Pack UVW"
if sceneMaterials["BWDA_Enlighten"] != undefined do append modi.baseMaterial_list sceneMaterials["BWDA_Enlighten"] -- default baseMaterial_list value is #()
addmodifier node modi -- add modifier individualliy (not to selection)
modPanel.setcurrentobject modi -- unwrap modifier method work only if the modifier is a current object
-- modi.fitRelax 50 0.1 -- i don't understand for it's for
modi.packNoParams() -- pack method if nothing selected works for all clusters
-- convertToPoly node -- if we want it
)
select nodes
)
)
)
createDialog UVtools
I just used some code from something I’d done before so the (– modi.fitRelax 50 0.1) so it was there for no real reason lol I can’t remember why though.
I’m getting a strange result with the unwrap as it’s not always giving me separate polygons.
eg If used on a box it gives me 3 polygons with the other 3 polygon on top of the others. Is this normal?
As usual I learned a lot from you DenisT thanks
that’s how it’s expected. if you want to have 6 clusters (one per every side) you have to Flatten UVWs first and do Pack after.