Quick Weight Maps question

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  05 May 2008
Quick Weight Maps question

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.

Thanks.
 
  05 May 2008
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.

#python
#imports
import win32com.client
	
#globals
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 cls.properties:
				if prop.type == "wtmap":
					weightmap = prop
					break
	
		elements = weightmap.elements
		comps = []
		for i in range(elements.count):
			if elements[i][0] > threshold:
				comps.append(i)

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

sel = xsi.selection(0)

SelectCompsFromWeightMap(sel,0.9)
__________________
doer of things somewhat technical

Last edited by Strang : 05 May 2008 at 03:06 AM. Reason: updated code block
 
  05 May 2008
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.

Quote:
# 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\__init__.py", 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?

Cheers
 
  05 May 2008
i think you need to use this python hack...

http://www.xsi-blog.com/archives/24

let me know how it goes
__________________
doer of things somewhat technical
 
  05 May 2008
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
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 , 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.


#python
#imports
import win32com
from win32com.client import dynamic as D
DD = D.Dispatch
	
#globals
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 eachCls.properties:
				if eachProp.Type == "wtmap":
					weightmap = eachProp
	
		aElements = weightmap.Elements.Array
		aComponents = []
		i = 0
		for eachValue in aElements[0]:
			if eachValue > threshold:
				aComponents.append(i)
			i += 1
		
		if len(aComponents):
			xsi.selectgeometrycomponents(oMesh.Name + ".pnt" + str(aComponents))
	else:
		xsiPrint("select a mesh!")

sel = xsi.selection(0)
SelectCompsFromWeightMap(sel,0.0)
__________________
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles

Last edited by ThE_JacO : 05 May 2008 at 10:56 PM.
 
  05 May 2008
Originally Posted by ExP: 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.
__________________
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles
 
  05 May 2008
JacO,

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
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.
__________________
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles
 
  05 May 2008
Nice. Definitely makes sense. I'll try and set the init.py 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.
 
  05 May 2008
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:59 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.