transfering uvw data via maxscript

transfering uvw data via maxscript

Anonymous
Not applicable
3,234 Views
22 Replies
Message 1 of 23

transfering uvw data via maxscript

Anonymous
Not applicable
i am completely new to maxscript, so maybe this is a dumb question:
i am trying to use maxscript to transfer uvw coordinates from one object to another.
my test file contains a poli called 01 and another one called 01a (the final file will have a series of such groups (02/02a, 03/03a,...)).
01 has an unwrapUVW modifier containing the correct cordinates which should be transferred to 01a.
i tried with recording a drag and drop action of the modifier, but this did not work.
i also tried to safe and load the uvs with the following script:

macroScript Macro27
category:"DragAndDrop"
toolTip:""
(
actionMan.executeAction 0 "40021" -- Selection: Select All
macros.run "Modifier Stack" "Convert_to_Poly"
$.material = meditMaterials
clearSelection()
select $a1
subobjectLevel = 4
$.EditablePoly.attach $1 $
subobjectLevel = 0
modPanel.addModToSelection (Uvwmap ()) ui:on
$.modifiers.length = 40.71
$.modifiers.width = 210.34
modPanel.setCurrentObject $.baseObject
subobjectLevel = 4
$.EditablePoly.SetSelection #Face #{1}
actionMan.executeAction 0 "40020" -- Edit: Delete Objects
$.EditablePoly.delete #Face
subobjectLevel = 0
modPanel.setCurrentObject $.modifiers
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.modifiers.unwrap.save ()
select $t1
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.modifiers.unwrap.load ()
)


basically it works, but it asks me where to safe the uvw-file and then again asks which uvw file to load, which is not so convinient. can i specify a path in the script, which says where to save and load the uv date?
of course i would prefer transferring the data without saving in between.
any help would be appreciated
0 Likes
3,235 Views
22 Replies
Replies (22)
Message 2 of 23

Anonymous
Not applicable
Maybe is a too simple idea, but why not to try just to copy modifier?
-- just example
-- myPairs = #($objA, $objB)
addModifier $objB (copy $objA.modifiers)
0 Likes
Message 3 of 23

Anonymous
Not applicable
thanks for the quick response!
basically it works, the modifier is transferred.
the problem is: the uvw-coordinates are not transferred.
when doing the same with a simple bend modifier or uvw mapping, it works as expected, all the settings within the modifiers are transferred.
btw: both my objects are prepared for uvw matching (same vertex count, etc.). tranferring manually via .uvw-file works fine
0 Likes
Message 4 of 23

Anonymous
Not applicable
Yes, I know, load/save via MaxScript without popup dialog feature is asked many times, unfortunately is not implemented yet.
0 Likes
Message 5 of 23

Anonymous
Not applicable
i see ....
do you know, if it is possible to specify a certain file name and path to temporarily safe and load the uv file?
0 Likes
Message 6 of 23

Anonymous
Not applicable
nope 😕 so em i wish to do this... nor yet third party SDK extensions for this.
0 Likes
Message 7 of 23

Steve_Curley
Mentor
Mentor
It is possible, but messy.


I cannot guarantee this will work on all systems - I don't have Vista or Win7 to try it on.
It does appear to work on XP-64.

Use at your own risk!


Also, if you get the situation where you would be overwriting a file, you will get the "Overwrite Yes/No" dialog. It would be best to ensure that the file does not exist (using the normal getFiles and deleteFile functions), though the following code could be expanded (duplicated, almost) to spot that dialog and auto-press the Yes button.

Enjoy - I'm off to sunnier climes where you (hopefully) can't find me...

DialogMonitorOPS.unRegisterNotification id:#eyeInTheSky

fn dmnotification =
(
WindowHandle = DialogMonitorOPS.GetWindowHandle()
WindowName = UIAccessor.GetWindowText WindowHandle
if WindowName != undefined then
(
if (findString WindowName "Save UVW") != undefined then
(
cWindows = UIAccessor.GetChildWindows WindowHandle
entryField = 0
for t = 1 to cWindows.count do
(
if cWindows != 0 then
(
if (UIAccessor.GetWindowClassName cWindows) == "ComboBoxEx32" then
entryField = cWindows
)
)
if entryField != 0 then
(
UIAccessor.SetWindowText entryField "C:\\Temp\\tmp.uvw"
UIAccessor.PressButtonByName WindowHandle "&Save"
)
)
)
true
)

DialogMonitorOPS.RegisterNotification dmnotification id:#eyeInTheSky
DialogMonitorOPS.Enabled = true

$.modifiers.unwrap.save()

DialogMonitorOPS.Enabled = false
DialogMonitorOPS.unRegisterNotification id:#eyeInTheSky


NB. This is one occasion where you cannot use "C:/Temp/Filename.ext" - you must use the \\ version.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 8 of 23

Anonymous
Not applicable
Wow, Steve, you're awesome person! Thanks a lot! :))
0 Likes
Message 9 of 23

Steve_Curley
Mentor
Mentor
It's not really much more than a modification to the sample code in the help for the UIAccessor functions. They tricky bit is having to run it (with lots of debug prints) to find the actual window you want, bearing in mind that every button, toolbar even the static text is a "window". Once you know which one you want it's not too bad.
Still a messy way to have to do it when a built-in function (with options for the filename, overwrite and so on) really shouldn't be too difficult to implement.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 10 of 23

Anonymous
Not applicable
I must admit that I had not the courage to play with the UIAccessor (yet) :)
Sincere thanks for all your help and tips!
0 Likes
Message 11 of 23

Steve_Curley
Mentor
Mentor
You're welcome :)

If you want a different example of using the UIAccessor functions see this thread. Fun and games trying to toggle a checkbox :)
I had to google for how to do that one...

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 12 of 23

Anonymous
Not applicable
A very useful example, thanks! It pointer me to the next step. You wrote a "clean" function (without arguments) and pass variable by changing globals, I like this trick :) Thanks again!
0 Likes
Message 13 of 23

Steve_Curley
Mentor
Mentor
You don't actually have much choice in that instance. Remember that the function is being called by a Windows Event - rather like an "on button pressed" routine in a dialog, but without knowing which button was pressed. The script reacts to the opening of the dialog so you can't really pass parameters to it because you (the rest of the script) didn't call it directly. A Global seemed the easiest way of getting around that :)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 14 of 23

Anonymous
Not applicable
hi steve,
thanks for the help.
i will try to build it into my script. as i said, i am an absolute beginner, so it will take some time to check it.
i am on x64, so hopefully it works.
0 Likes
Message 15 of 23

Steve_Curley
Mentor
Mentor
You're welcome. Just bear in mind that the above script only deals with the saving of the UVW file - you would need to deal with the loading of it by duplicating part of the function, checking for the different dialog and possibly a different component too.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 16 of 23

Anonymous
Not applicable
I'm still on "save" handle 'cause the issue is complicated :) but I think to share what I let out and how I solve (or plan to solve) incoming trammel, just to can help to others who plan to fight with this :)

So, first, buttonOPS are binded to their rollout, or shortly - Modify panel must be open and Unwrap_UVW modifier must be selected; else the "lovely" error ("system exception") will appear.
b = box() -- create Box
m = Unwrap_UVW()
addModifier b m
max modify mode -- open modify panel
modPanel.setCurrentObject m -- select Unwrap_UVW modifier
-- then call ...
m.save()

The second is bound to Max2009. In Max9 test shown no problem. So... to test in Max2009 just continue above example by executing (line by line) this code:
m.save() -- "sleep"
m.load() -- "sleep"
m.save() -- now works
m.load() -- now works

Shortly, some "sleep" bug in Max2009 tied to Unwrap Save/Load functions. They return OK but not execute corresponding dialog window, and "wake up" only...:
after push the button manual (at least once).
after call them in cross order, (inconvenient way) i.e:
m.save() ; m.load() ; m.save() -- to save .uvw
m.load() ; m.save() ; m.load() -- to load .uvw

If repeat the test, you'll see the functions need "wake up" for each modifier. This complicate the task too much 😕 If going in this direction then 'cause there no way to detect MaxScript accessibility to the functions, you'll need to reset Max, reopen the file and call both function for each modifiers. Not only complicated but not (always) works smoothly as well.
Well... I found third way too:
after "edit()" both (save/load) function react as needed/expected. So, now I'll need (i.e. I plan) to write DialogMonitorOPS for "edit" too to can fix this in Max2009.

Here is my auto-close callback for edit uvw dialog:
DialogMonitorOPS.unRegisterNotification id:#wakeupUnwrapButtons

fn closeEditUvwDialog =
(
WindowHandle = DialogMonitorOPS.GetWindowHandle()
WindowName = UIAccessor.GetWindowText WindowHandle
if WindowName != undefined do
(
if (findString WindowName "Edit UVWs") != undefined do
(
UIAccessor.CloseDialog WindowHandle
subobjectLevel = 0
)
)
true
)
DialogMonitorOPS.RegisterNotification closeEditUvwDialog id:#wakeupUnwrapButtons
DialogMonitorOPS.Enabled = true

$.modifiers.edit() -- test

DialogMonitorOPS.Enabled = false
DialogMonitorOPS.unRegisterNotification id:#wakeupUnwrapButtons


Any better solution (if you know?) is welcome of course.
0 Likes
Message 17 of 23

PiXeL_MoNKeY
Collaborator
Collaborator
If the vertex count is the same then you may want to look at ChannelInfo or using the Projection modifier to transfer the mapping data.

-Eric
0 Likes
Message 18 of 23

Anonymous
Not applicable
Thanks for your advice, ChannelInfo or Projection help in any cases... However, manual copy/paste unwrap_UVW also works fine, just doing via MaxScript is wrong but... I have a good news... I found a very elegant solution using "swap" function (an awesome miscellaneous funcion that save my *** :) many times in a lot of situations). If anybody need my way, I'll share "how to". Thanks again for the reply.
0 Likes
Message 19 of 23

Anonymous
Not applicable


You’re welcome. Just bear in mind that the above script only deals with the saving of the UVW file - you would need to deal with the loading of it by duplicating part of the function, checking for the different dialog and possibly a different component too.


thanks again for the elaborate explanation.
sounds good so far.
think i will take some help to adhere your tips.
cheers roberto
0 Likes
Message 20 of 23

Anonymous
Not applicable
If the vertex count is the same then you may want to look at ChannelInfo or using the Projection modifier to transfer the mapping data.

-Eric


sounds promising.
i will give it a try and feedback
0 Likes