RE: passing tagged points through a C++ command

Date : Thu, 30 Aug 2007 15:21:34 -0400
To : <XSI(at)Softimage.COM>
From : "Mathieu Leclaire" <mleclair(at)hybride.com>
Subject : RE: passing tagged points through a C++ command

Thanks. This is great but it only works on XSI 6. On 5.11 it doesn’t work. We are still working on 5.11 until the end of the current production (ending soon) but I’d need it for 5.11.  I might have an ugly workaround for the moment but if anyone have other suggestions, I’m all ears. But thanks Chris. This is definitely interesting and will be useful once we do the switch.

 

Mathieu Leclaire

R&D Programmer

Hybride Technologies

 

"Yesterday is history, tomorrow is a mystery, today is a gift and that is why it's called the present"

 

-----Original Message-----
From: Christopher Crouzet [mailto:christopher.crouzet(at)gmail.com]
Sent: Thursday, August 30, 2007 1:59 PM
To: XSI(at)Softimage.COM
Subject: Re: passing tagged points through a C++ command

 

Hello,
I was curious to see how to solve this problem, so I did few tests and I finally found the solution in the 'CComAPIHandler' class. It seems that the 'SubComponent' class is not fully implemented in the C++ SDK, so it's the only way. There is a great example under the 'Invoke' function from the doc to do what you want.
You just have to adjust a little the code from the example, and it's OK.

Here is the 'final' code wich works for both selected components and string input as "Object.pnt[....]" :

XSIPLUGINCALLBACK CStatus MyCommand_Init(CRef &in_ctxt)
{
    Context ctxt = in_ctxt;
    Command cmd = ctxt.GetSource();
    cmd.EnableReturnValue(false);


    // Add some arguments to the command.
    ArgumentArray args;
    args = cmd.GetArguments();
    args.AddWithHandler(L"in_objList", siArgHandlerCollection);


    return CStatus::OK;
}

XSIPLUGINCALLBACK CStatus MyCommand_Execute(CRef &in_ctxt)
{
    Application app;

    // Retrieve data from the argument list.
    CValueArray args = ctxt.GetAttribute(L"Arguments");
    CValueArray in_objList = args[0];


    // Iterate over the object list.
    for (LONG i = 0; i < in_objList.GetCount(); i++ ) {
        // The collection of selected components exists in the first member.
        CComAPIHandler comCollItem = (CRef)in_objList[i];
        CComAPIHandler comSubComp = comCollItem.GetProperty(L"SubComponent");
        CValue subCompType = comSubComp.GetProperty(L"Type");

        // Grab the component collection.
        CComAPIHandler comCompColl(comSubComp.GetProperty (L"ComponentCollection"));


        // Now we can iterate over the component collection's members.
        LONG lCollCount(comCompColl.GetProperty(L"Count"));

        for (LONG j = 0; j < lCollCount; j++) {
            CValue rtn;                             // output from the Item property.
            CValueArray idx; idx.Add(j);            // set the index to use.
            comCompColl.Invoke( L"Item", CComAPIHandler::PropertyGet, rtn, idx );

            // From the CRef class, we can convert it to the actual class.
            CRef itm(rtn);
            if (itm.GetClassID() == siVertexID) {
                Vertex vtx = Vertex(itm);
                app.LogMessage(L"Found a vertex at index " + CString(vtx.GetIndex()));
            }
            else if (itm.GetClassID() == siSampleID) {
                Sample smp = Sample(itm);
                app.LogMessage (L"Found a sample at index " + CString(smp.GetIndex()));
            }
            else if (itm.GetClassID() == siEdgeID)
            {
                Edge edg = Edge(itm);
                app.LogMessage (L"Found a edge at index " + CString(edg.GetIndex()));
            }
            else if (itm.GetClassID() == siControlPointID) {
                ControlPoint ctrl = ControlPoint(itm);
                app.LogMessage(L"Found a control point at index " + CString(ctrl.GetIndex()));
            }
        }
    }


    return CStatus::OK;
}



Hope it helps.


On 8/30/07, Mathieu Leclaire <mleclair(at)hybride.com> wrote:

I want to pass tagged points as an argument trough my custom command but I'm not sure how to extract them in C++ from the CValue…

 

Example: MyCommand("Object.pnt[2764,3281,3802,4156,4160,4167,4487]");

 

What are the steps to go through to get access to the points so I can then change the position of the tagged points?

 

 

Mathieu Leclaire

R&D Programmer

Hybride Technologies

 

"Yesterday is history, tomorrow is a mystery, today is a gift and that is why it's called the present"

 

 


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.