View Full Version : Quick Weight Maps question

05 May 2008, 01:29 AM
Just getting a first taste of XSI. I'm playing around with dynamic Weight Maps etc..
Quick question: Is there a way to select components, like polys for example, from a Weight Map? Let's say I have an object with a weigh map, how do I select the equivalent polys the weigh map touches? I looked around a lot, but coun't find an answer.


05 May 2008, 03:01 AM
i believe you need to script this, select a mesh with a weightmap, and run this in the script editor. it should only use the first weightmap it finds. the threshold argument allows you to decide the smallest weight value to be selected.

import win32com.client

xsi = win32com.client.Dispatch( "XSI.Application" ).Application
xsiPrint = xsi.LogMessage

def SelectCompsFromWeightMap(mesh,threshold = 0.9):
if mesh.type == "polymsh":
clusters = mesh.activeprimitive.geometry.clusters
weightmap = None
for cls in clusters:
for prop in
if prop.type == "wtmap":
weightmap = prop

elements = weightmap.elements
comps = []
for i in range(elements.count):
if elements[i][0] > threshold:

xsi.selectgeometrycomponents( + ".pnt" + str(comps))
xsiPrint("select a mesh!")

sel = xsi.selection(0)


05 May 2008, 04:07 AM
Strang, thanks a lot. I tried this, but it's giving me an error. Could it be because I'm running XSI64 using python64? I've had similar problems with python scripts before.

# ERROR : Traceback (most recent call last):
# File "<Script Block >", line 31, in ?
# SelectCompsFromWeightMap(sel,0.9)
# File "<Script Block >", line 21, in SelectCompsFromWeightMap
# for i in range(elements.count):
# File "C:\Python24\Lib\site-packages\win32com\client\", line 454, in __getattr__
# raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr)
# AttributeError: '<win32com.gen_py.Softimage|XSI Object Model Library v1.5.ClusterElementCollection instance at 0x206121864>' object has no attribute 'count'
# - [line 21]

If that's the case do you happen to have the same script compiled in another language?


05 May 2008, 09:30 PM
i think you need to use this python hack...

let me know how it goes

05 May 2008, 10:30 PM
Works great!! (I wonder why XSI needs that hack though)

Thanks man! This is truly a time saver for a few things I was trying to achieve.

All the best.

05 May 2008, 10:33 PM
Not a huge fan of the hack to be honest, it can have other unpredictable effects.

Since I'm bored, here's the same script with a couple tweaks.
Shouldn't require any hacks, but it's untested and still far from ideal (edited in the glorious post text field :D, sorry but am on FC8 and don't feel like rebooting just to tweak a script)
It should work bar some potential tard out on syntax.

import win32com
from win32com.client import dynamic as D
DD = D.Dispatch

xsi = DD(Application)
xsiPrint = xsi.LogMessage

def SelectCompsFromWeightMap(oMesh,threshold):
if oMesh.type == "polymsh":
weightmap = None
for eachCls in oMesh.ActivePrimitive.Geometry.Clusters:
for eachProp in
if eachProp.Type == "wtmap":
weightmap = eachProp

aElements = weightmap.Elements.Array
aComponents = []
i = 0
for eachValue in aElements[0]:
if eachValue > threshold:
i += 1

if len(aComponents):
xsi.selectgeometrycomponents(oMesh.Name + ".pnt" + str(aComponents))
xsiPrint("select a mesh!")

sel = xsi.selection(0)

05 May 2008, 10:40 PM
Works great!! (I wonder why XSI needs that hack though)

Thanks man! This is truly a time saver for a few things I was trying to achieve.

All the best.

The hack is related to how some calls are dispatched.
Some of XSI's python wrapping can erroneously deal with some calls and might occasionally need to be forcefully made to dispatch a different way.

The hack enforces it across the board, but it's not needed, only a handful of things need to be dealt with that way, and those few can be forcefully dispatched through the pywin32 client.

I still have to find a single tool I wrote or revised that couldn't be made to run without the hack by simply adopting a clearer and more structured design that takes care of potential dispatching issues far upstream, it's only disadvantageous for minuscule scripts where the added verbosity might be annoying.

05 May 2008, 12:27 AM

Thanks for the info. Is there any downside to the hack? Meaning, once done is there any reason why you would want to "reactivate" the WrapDispatch function?

05 May 2008, 12:49 AM
In the past it happened that we had some problems coming from that hack, especially under Linux, and more recently I had some of the weirdest shit happening at a windows based studio that only had one difference from my test setup at home, which was the hack (they had it, I didn't), which leads me to think it's not always and entirely harmless.
We had no time to revise their codebase to remove it though, so I went the long way around in some regards and made sure things were working in both environments.

It targets libraries that, most likely, you will only be running for xsi as not many people or apps use pyWin in this industry as activeX isn't that prominent in it, but if by chance you needed pywin for something else it might also interfer with that. That's a pretty remote chance though outside of the network/IT/office automation business.

The above is largely conjecture and based on a too small sample base to make it relevant statistics, but I've hardly ever seen the hacked platforms behaving EXACTLY as expected all the time, so I'm diffident of forcing off a particular type of wrapping that might be needed somewhere.

05 May 2008, 01:31 AM
Nice. Definitely makes sense. I'll try and set the file back to its original state and test your new script... see what happens. Especially considering I'm on an XP x64 machine running XSI 64bit
Thanks again for all the insights.

CGTalk Moderation
05 May 2008, 01:31 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.