PDA

View Full Version : is there a way to select cloth groups via script??


GMS-575
02-18-2009, 11:54 AM
Hi i searched the script help but i didn't find a way to select cloth groups via script. I want to save the vertices of the cloth groups to a file without to have to select the groups by "hand".

cheers georgios

ZeBoxx2
02-18-2009, 01:59 PM
I'm not too familiar with Cloth, but do you just want to collect all objects that have 1 (or more) Cloth modifiers applied?


-- modifier centric
clothMods = getClassInstances Cloth
objsWithClothMod = #()
for clothMod in clothMods do (
for ref in (refs.dependents clothMod) where (classOf ref == Editable_Mesh) do ( appendIfUnique objsWithClothMod ref )
)
objsWithClothMod

-- object centric
objsWithClothMod = #()
for o in objects do (
for i = 1 to o.modifiers.count do (
if (classOf o.modifiers[i] == Cloth) do ( appendIfUnique objsWithClothMod o; exit )
)
)
objsWithClothMod

GMS-575
02-18-2009, 02:08 PM
Hi ZeBoxx2,

its not about collecting the objects that have a cloth modifier, but its about groups that are made with/in the cloth modifier.

When you create a cloth group in the cloth modifier you can access the group if you switch to subobjectlevel "group" and than select the group in a listbox.

What i want to do is to read out all the cloth groups and save them to a file. And the problem is that i cant select the groups in the listbox via script.

But thank's anyway :beer:

ZeBoxx2
02-18-2009, 02:47 PM
hmmm... Cloth mod could use with some exposure, looks like.. there's not even a proper way to get a list of the group names (have to enumarate getPropNames()?), nevermind getting the vertices therein as you mentioned.

Sadly, that once again means ScaryCode with flashing screens and whatnot.

fn getClothGroupVertices obj clothmod index = (
-- windows codes
local WM_COMMAND = 0x111
local LB_SETCURSEL = 0x0186
local LBN_SELCHANGE = 0x0001

-- change to modify panel, open the modifier, and go to Group subobject
SetCommandPanelTaskMode #modify
modpanel.setCurrentObject clothmod
subObjectLevel = 1
-- get all the UI controls in max
local maxHWND = windows.getMaxHWND()
local maxChildren = windows.getChildrenHWND maxHWND
-- loop over them to find the listbox
for child in maxChildren do (
if (child[4] == "ListBox") then (
local listbox_hwnd = child[1]
local listbox_id = UIAccessor.GetWindowResourceID listbox_hwnd
-- check if it's the listbox we want (semi-iffy method)
if (listbox_id == 1047) then (
local listbox_parent = UIAccessor.getParentWindow listbox_hwnd

-- change the listbox selection
windows.sendmessage listbox_hwnd LB_SETCURSEL (index - 1) 0

-- let max know it's changed
windows.sendmessage listbox_parent WM_COMMAND ((bit.shift LBN_SELCHANGE 16) + listbox_id) listbox_hwnd

return (obj.selectedVerts as bitArray)
)
)
)
return undefined
)


usage:

-- <bitArray>getClothGroupVertices <object> <clothmod> <groupIndex>
selectedVerts = getClothGroupVertices $ $.modifiers[1] 1


As far as I can tell, that listbox's list has parity with the order in which group names appear in e.g. getPropNames, so you should be able to correlate a groupIndex with a group name with that.

Let me know if it explodes or you run into some other problem.

GMS-575
02-18-2009, 03:09 PM
i can filter the group names cause i give them the suffixe "_grp" so i can filter with getPropNames() :-).

I'll give it a try and i talk to you later :thumbsup:

GMS-575
02-18-2009, 04:59 PM
it works fine. i changed it a little bit so i can use it with the rest of my script.

at first it didn't work but then i figured out that the command panel has to be docked to the main toolbar.

is there a way to get the script work when the command panel is not docked??

cheers georgios

ZeBoxx2
02-18-2009, 07:00 PM
at first it didn't work but then i figured out that the command panel has to be docked to the main toolbar.
is there a way to get the script work when the command panel is not docked??
d'oh!
crazy people undocking things ;)

quick-and-dirty fix, replace "windows.getMaxHWND()" with "windows.getDesktopHWND()"

Edit: and there's no built-in method to detect whether the thing is floating or docked, apparently, so getDesktopHWND() it is (that will still collect everything inside max as well - just wastes a bit of time as it will go through everything else you have open, too - so if you're using this in a loop, you may wish to put the code to find the listbox outside of the loop :)

GMS-575
02-19-2009, 08:17 AM
i call myself crazy:banghead: ;-) .

I think i stay with the docked version of the script. But its good to know that it would also work with the undocked panel and i will check out how fast/slow the script will be with the undocked.

Many thanks ZeBoxx2.

Cheers Georgios

CGTalk Moderation
02-19-2009, 08:17 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.