View Full Version : Get Index of NeighborEdges
Hey all,
I'm working through making a python scripted op applied to a weightmap. I've got no problems passing data to the weightmap vertices, but I'm having a problem with getting the properties I need to get the values I need.
I'm using Reinhard's Tension Map (http://www.claus-figuren.de/addons/tensionmap.php) (vB) as a guide.
Reinhard gets the Neighboring Edges of each vertex in a cluster and then loops through those Edges and then uses the Edge index to get the Neighboring Vertices to obtain those verts position vectors.
Set oNeighEdges = oGeo.Vertices(oWMCLSElems(i)).NeighborEdges(1)
For Each oEdge in oNeighEdges
Set oNeighPts = oGeo.Edges(oEdge.Index).NeighborVertices(1)
Set V1 = oNeighPts.Item(0).Position
Set V2 = oNeighPts.Item(1).Position
I'm getting an error when I try getting the Edge Index...
oNeighEdges = oGeo.Vertices(oWMCLSElems(i)).NeighborEdges(1)
for oEdge in range(oNeighEdges):
oNeighPts = oGeo.Edges(oEdge.Index).NeighborVertices(1)
V1 = oNeighPts.Item(0).Position
V2 = oNeighPts.Item(1).Position
#ERROR : Traceback (most recent call last):
# File "<Script Block 114>", line 19, in Update
# for oEdge in range(oNeighEdges):
#TypeError: range() integer end argument expected, got instance.
Can anyone shed some light on how I can get the index of Neighboring Subcomponents?
StephenBlair
04-07-2008, 06:51 AM
Shouldn't it be
for oEdge in oNeighEdges :
Ah... that's what it was. Still getting a handle on Python syntax. Thanks Stephen!
So I'm sure it's something simple again, but I got a chance to play around with this again, and have run across another hiccup. I'm trying to out put values to each vertex of a weightmap (again using Reinhard's ScOp as reference).
Tension Map wraps up with:
oWM.Elements.Item(i) = aWeightWhich is basically Out.Value.Elements.Item(current in for-loop) = array.
I've done the same in Python (using lists).
for v in range(u.Count):
x = 1.01
y = []
y.append(x)
Out.Value.Elements.Item[v] = y
But errors:
#ERROR : 2012 - Traceback (most recent call last):
# File "<Script Block 24>", line 138, in Update
# Out.Value.Elements.Item[v] = y
# File "C:\Python24\lib\site-packages\win32com\client\__init__.py", line 455, in __getattr__
# return self._ApplyTypes_(*args)
# File "C:\Python24\lib\site-packages\win32com\client\__init__.py", line 446, in _ApplyTypes_
# return self._get_good_object_(
#COM Error: Type mismatch - [line 136 in update code]Can anyone throw me another line before I sink. :D
There's just not many examples/docs using python and scops involving weightmaps/vertexcolors (okay, none that I've found) :D
StephenBlair
04-20-2008, 07:25 AM
Try Elements(i).
Python: Calling the Item Method of a Collection (http://softimage.wiki.avid.com/index.php/Python_%28XSISDK%29#Calling_the_Item_Method_of_a_C ollection)
Try Elements(i).
Python: Calling the Item Method of a Collection (http://softimage.wiki.avid.com/index.php/Python_%28XSISDK%29#Calling_the_Item_Method_of_a_C ollection)
Awesome Stephen. Again thanks for the answer and the link.
One more question if I may.
If I wanted to pass this same value to the red channel of a Color At Vertices map instead of a weight map... how would the Out.Value read?
Julian Johnson
04-21-2008, 12:59 PM
I can't get Python to work in the same as VBScript in this case. The following simple code will let you set a weight value on a single point in map by writing directly to ClusterProperty.Elements in vbscript:
set oGrid = ActiveSceneRoot.AddGeometry("Grid", "MeshSurface")
set oCls = oGrid.ActivePrimitive.Geometry.AddCluster(siVertex Cluster)
set oWm = oCls.AddProperty("Weight Map Property")
dim a
a=Array(1.0)
oWm.Elements.Item(0) = aHowever, in Python, the same code:
from win32com.client import constants as c
oGrid = Application.ActiveSceneRoot.AddGeometry("Grid", "MeshSurface")
oCls = oGrid.ActivePrimitive.Geometry.AddCluster(c.siVert exCluster)
oWm = oCls.AddProperty("Weight Map Property")
oWm.Elements(0) = (1.0,)Always produces a TypeError. In fact the only way I've been able to update the ClusterProperty data in Python is to get Elements.Array, update the array and then reassign it. At each stage, converting the data from tuples to lists!
Am I missing something really simple :-) ie. is it possible for Python to write directly to Elements? JDex - are you managing to do this?
I can't get Python to work in the same as VBScript in this case. The following simple code will let you set a weight value on a single point in map by writing directly to ClusterProperty.Elements in vbscript:
set oGrid = ActiveSceneRoot.AddGeometry("Grid", "MeshSurface")
set oCls = oGrid.ActivePrimitive.Geometry.AddCluster(siVertex Cluster)
set oWm = oCls.AddProperty("Weight Map Property")
dim a
a=Array(1.0)
oWm.Elements.Item(0) = aHowever, in Python, the same code:
from win32com.client import constants as c
oGrid = Application.ActiveSceneRoot.AddGeometry("Grid", "MeshSurface")
oCls = oGrid.ActivePrimitive.Geometry.AddCluster(c.siVert exCluster)
oWm = oCls.AddProperty("Weight Map Property")
oWm.Elements(0) = (1.0,)Always produces a TypeError. In fact the only way I've been able to update the ClusterProperty data in Python is to get Elements.Array, update the array and then reassign it. At each stage, converting the data from tuples to lists!
Am I missing something really simple :-) ie. is it possible for Python to write directly to Elements? JDex - are you managing to do this?
No. Last night (very late) I tried to get it working, but assumed I was doing something stupid... so I let it lie until I could look at it with fresh eyes. Thank you for confirming that it's not just me.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.