Hi Jules,

Fear not, for when you're reading built-in attributes (like NodeToVertex)
it's very reliable to go this way. :)

Also, your duplicate-free version can be made even simpler, shorter and
maybe a teensy bit faster:

sel = app.Selection(0)
oGeo = sel.SubComponent.Parent3DObject.ActivePrimitive.Geometry
da = oGeo.GetICEAttributeFromName("NodeToVertex").DataArray
outIndexArray = set([ da[i] for i in sel.SubComponent.ElementArray ])

It will return a Python "set", which is an iterable object, list-like, but
enforces uniqueness automatically. If you truly need an actual list back,
you can wrap the result in a list() function to convert it, but I don't see
why you'd need it for this case.


Cheers,

   -- Alan


On Wed, Sep 12, 2012 at 5:16 PM, piotrek marczak
<piotrek.marc...@gmail.com>wrote:

>   this is 100000x times faster but Im not sure its safe getting the data
> from ice attributes?
>
> from win32com.client import constants as c
> app = Application
> # select samples
> sel = app.Selection(0)
> oGeo =
> sel.SubComponent.Parent3DObject.ActivePrimitive.GetGeometry3(0,c.siConstructionModeSecondaryShape)
> # arguments needed otherwise crash
> vton = oGeo.GetICEAttributeFromName("NodeToVertex");
> outArray = []
> da = vton.DataArray
> for sampleInd in sel.SubComponent.ElementArray:
>     outArray.append( da[ sampleInd ]  )
>
> without duplicates:
> from win32com.client import constants as c
> app = Application
> sel = app.Selection(0)
> oGeo =
> sel.SubComponent.Parent3DObject.ActivePrimitive.GetGeometry3(0,c.siConstructionModeSecondaryShape)
> # arguments needed otherwise crash
> vton = oGeo.GetICEAttributeFromName("NodeToVertex");
> da = vton.DataArray
>
> cmparray = [0] * oGeo.Points.Count
> outIndexArray = []
> for sampleInd in sel.SubComponent.ElementArray:
>     i = da[ sampleInd ]
>     if not cmparray[ i ]:
>         outIndexArray.append( i  )
>         cmparray[ i ] = 1
>
>  *From:* Jules Stevenson <droolz...@googlemail.com>
> *Sent:* Wednesday, September 12, 2012 10:51 PM
> *To:* softimage@listproc.autodesk.com
> *Subject:* Re: Python, Returning the vertex index from a sample cluster
>
> Hey Piotrek,
>
> Played around with your code and it is a lot faster than the script that I
> was digging about with. FWIW you can use a set to speed up the lookup stage:
>
>  def vertices_from_samples(samples):
> '''Selects the vertices marked by the current selection of UV samples.'''
> geo = samples.SubComponent.Parent3DObject.ActivePrimitive.Geometry
> index_array = [0] * geo.Samples.Count
>
> for point in geo.Points:
> for ptsample in point.Samples:
> index_array[ptsample.Index] = point.Index
>
> outIndexSet = Set()
> for sample in samples.SubComponent.ElementArray:
> outIndexSet.add(index_array[sample])
>
> You could probably also pickle the index_array so it only needs
> calculating once (since it takes a long time on a big mesh), but that opens
> a whole can of worms in terms of storage and keeping it updated when the
> mesh changes.
>
> Thanks for re-engaging my brain!
>
> Jules
>
> On Wed, Sep 12, 2012 at 9:35 PM, Jules Stevenson <droolz...@googlemail.com
> > wrote:
>
>> Hi Piotrek,
>>
>> Thanks a lot for your reply, but this is exactly what I'm trying to avoid
>> - I'm actually re-writing a script that does something very similar, as it
>> is damn slow. Matt Lind mentioned in a previous thread that it is possible
>> to go from sample > vert (are you around Matt ;)), but I'm really
>> struggling to ifnd the 'magic' to make this happen.
>>
>> Cheers,
>>
>> Jules
>>
>>  On Wed, Sep 12, 2012 at 9:28 PM, piotrek marczak <
>> piotrek.marc...@gmail.com> wrote:
>>
>>>   i think you need to go bruteforce...
>>> pretty slow code but i dont know python
>>>
>>> from win32com.client import constants as c
>>> app = Application
>>> oGeo =
>>> app.Selection(0).SubComponent.Parent3DObject.ActivePrimitive.GetGeometry3(0,c.siConstructionModeSecondaryShape)
>>> # arguments needed otherwise crash
>>> indarray = [0] * oGeo.Samples.Count
>>> for point in oGeo.Points:
>>>     for ptsample in point.Samples:
>>>         indarray[ ptsample.Index ] = point.Index
>>> cmparray = [0] * oGeo.Points.Count
>>> outIndexArray = []
>>> for sample in app.Selection(0).SubComponent.ElementArray:
>>>     if not cmparray[ indarray[ sample ] ]:
>>>         outIndexArray.append( indarray[ sample ] )
>>>         cmparray[ indarray[ sample ] ] = 1
>>>
>>> for i in outIndexArray:
>>>     Application.LogMessage ( i )
>>>
>>>  *From:* Jules Stevenson <droolz...@googlemail.com>
>>> *Sent:* Wednesday, September 12, 2012 7:58 PM
>>> *To:* softimage@listproc.autodesk.com
>>> *Subject:* Re: Python, Returning the vertex index from a sample cluster
>>>
>>>  Apologies, hit send a little early there....
>>>
>>>  for sample in samples.SubComponent.ComponentCollection:
>>> log(uvs.FindIndices([sample.Index]))
>>>                 log (sample.Index)
>>>                 log(elements.FindIndex(sample.Index)
>>>
>>> The 'elements' clusterElementCollection seems to contain the indices to
>>> the samples, not the mapping to the geometry, which goes against what is
>>> syas in the docs:
>>>
>>> "The ClusterElementCollection returned by 
>>> Cluster.Elements<http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/si_om/Cluster.Elements.html>(and
>>> Envelope.Elements<http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/si_om/Envelope.Elements.html>)
>>> provides the mapping between an index of a component in a cluster with the
>>> index of the component on the 
>>> Geometry<http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/si_om/Geometry.html>.
>>> For example index 10 on a polygon Cluster might refer to Polygon 45 on the
>>> geometry, in which case ClusterElementCollection.Item(10) has the value 45.
>>> This data is read-only."
>>>
>>> This is not what I get at all, for a start the cluster.Elements.Count
>>> returns approximatly 80k, which makes no sense as a geometry index since
>>> there are only about 20k points. Clearly this is an array of the sample
>>> indices (4 per vert). Soooooooo, how do I get the point / facet / polygon
>>> ID from a sample?
>>>
>>> Any help much appreciated, this is driving me nuts.
>>>
>>> Cheers,
>>>
>>> Jules
>>>
>>
>>
>
>

Reply via email to