Here's a piece I took out from one of my tools. It's a good example of
using locations in scripting:

xsi = Application
log = xsi.LogMessagefrom win32com.client import constants as C
def main():
    if xsi.Selection.Count == 0:
        log('Please select your objects to constrain.', C.siError)
        return False

    rtn = xsi.PickElement( C.siPolyMeshFilter,
    'Select geometry - for VERTEX cluster',
    'Select geometry - for POLY cluster' )
    option, picked = rtn.Value('ButtonPressed'), rtn.Value('PickedElement')
    clsType = [None, C.siVertexCluster, C.siPolygonCluster][option]

    if not clsType:  # cancelled
        return False

    geo = picked.ActivePrimitive.Geometry

    xsi.OpenUndo('constrain to closest point/poly')
    for null in xsi.Selection:

        pos = null.Kinematics.Global.Transform.GetTranslationValues2()
        locations = geo.GetClosestLocations(pos)
        # locations = geo.GetClosestLocationsWithinRadius(pos, 0.1, 1)

        clusterName = 'CLS_'+null.Name
        if clsType == C.siVertexCluster:
            component = geo.GetTriangleVertexIndexArray(locations)[-1]
        elif clsType == C.siPolygonCluster:
            component = geo.GetPolygonIndexArray(locations)[0]

        log( 'Making cluster for %s at #%s' % (null.Name, component),
C.siVerbose )
        newCluster = geo.AddCluster(clsType, clusterName, component)

        xsi.RemoveCnsType('ObjectToCluster', null)
        newCns = null.Kinematics.AddConstraint('ObjectToCluster', newCluster)
        if clsType == C.siPolygonCluster:
            newCns.Parameters('tangent').Value = True
            newCns.Parameters('upvct_active').Value = True

    xsi.CloseUndo()

main()



On Mon, Oct 28, 2013 at 6:11 PM, Sergio Mucino <sergio.muc...@modusfx.com>wrote:

>  Thanks Matt!
>
>
> On 28/10/2013 5:42 PM, Matt Lind wrote:
>
>  You can convert the null’s position to the local space of the polygon
> mesh, then do a PolygonMesh.GetClosestLocation() to return a PointLocator
> object, then select the polygon from the ID stored in the PointLocator
> object.****
>
> ** **
>
> Matt****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> *From:* softimage-boun...@listproc.autodesk.com [
> mailto:softimage-boun...@listproc.autodesk.com<softimage-boun...@listproc.autodesk.com>]
> *On Behalf Of *Sergio Mucino
> *Sent:* Monday, October 28, 2013 2:36 PM
> *To:* softimage@listproc.autodesk.com
> *Subject:* Finding polygons...****
>
> ** **
>
> Okay, this is going to be a real long shot...
> Lets say you have a null sitting squarely at the center of a polygon. Is
> there a way to select said polygon, based on the selected null? In other
> words, I want to select the null, and I want to be able to select the
> polygon that this null is positioned over. Maybe a raycasting function, or
> something similar? Any ideas? Thanks! (I know... definitely a long shot...)
> ****
>
> --
> ****
>
>

<<image/gif>>

<<Sergio Mucino_Signature_email.gif>>

Reply via email to