CGTalk > Software Specific Forums > Autodesk Softimage
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-16-2008, 01:29 AM   #1
ExP
Frequenter
VFX Supervisor
Los Angeles, USA
 
Join Date: Jun 2005
Posts: 147
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.
 
Old 05-16-2008, 03:01 AM   #2
Strang
nullify
portfolio
Steven Caron
San Francisco, USA
 
Join Date: Jul 2003
Posts: 1,166
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.

Code:
#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-16-2008 at 03:06 AM. Reason: updated code block
 
Old 05-16-2008, 04:07 AM   #3
ExP
Frequenter
VFX Supervisor
Los Angeles, USA
 
Join Date: Jun 2005
Posts: 147
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
 
Old 05-20-2008, 09:30 PM   #4
Strang
nullify
portfolio
Steven Caron
San Francisco, USA
 
Join Date: Jul 2003
Posts: 1,166
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
 
Old 05-20-2008, 10:30 PM   #5
ExP
Frequenter
VFX Supervisor
Los Angeles, USA
 
Join Date: Jun 2005
Posts: 147
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.
 
Old 05-20-2008, 10:33 PM   #6
ThE_JacO
MOBerator-X
 
ThE_JacO's Avatar
CGSociety Member
portfolio
Raffaele Fragapane
That Creature Dude
Animal Logic
Sydney, Australia
 
Join Date: Jul 2002
Posts: 10,950
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.

Code:
#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)
__________________
"As an online CG discussion grows longer, the probability of the topic being shifted to subsidies approaches 1"

Free Maya Nodes

Last edited by ThE_JacO : 05-20-2008 at 10:56 PM.
 
Old 05-20-2008, 10:40 PM   #7
ThE_JacO
MOBerator-X
 
ThE_JacO's Avatar
CGSociety Member
portfolio
Raffaele Fragapane
That Creature Dude
Animal Logic
Sydney, Australia
 
Join Date: Jul 2002
Posts: 10,950
Quote:
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.
__________________
"As an online CG discussion grows longer, the probability of the topic being shifted to subsidies approaches 1"

Free Maya Nodes
 
Old 05-21-2008, 12:27 AM   #8
ExP
Frequenter
VFX Supervisor
Los Angeles, USA
 
Join Date: Jun 2005
Posts: 147
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?
 
Old 05-21-2008, 12:49 AM   #9
ThE_JacO
MOBerator-X
 
ThE_JacO's Avatar
CGSociety Member
portfolio
Raffaele Fragapane
That Creature Dude
Animal Logic
Sydney, Australia
 
Join Date: Jul 2002
Posts: 10,950
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.
__________________
"As an online CG discussion grows longer, the probability of the topic being shifted to subsidies approaches 1"

Free Maya Nodes
 
Old 05-21-2008, 01:31 AM   #10
ExP
Frequenter
VFX Supervisor
Los Angeles, USA
 
Join Date: Jun 2005
Posts: 147
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.
 
Old 05-21-2008, 01:31 AM   #11
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 07:57 AM.


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