Re: passing tagged points through a C++ command
| Date : Thu, 30 Aug 2007 19:59:06 +0200 |
| To : XSI(at)Softimage.COM |
| From : "Christopher Crouzet" <christopher.crouzet(at)gmail.com> |
| Subject : Re: passing tagged points through a C++ command |
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;
}
{
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"
- Follow-Ups:
- RE: passing tagged points through a C++ command
- From: "Mathieu Leclaire" <mleclair(at)hybride.com>
- RE: passing tagged points through a C++ command
- References:
- passing tagged points through a C++ command
- From: "Mathieu Leclaire" <mleclair(at)hybride.com>
- passing tagged points through a C++ command
| DATE: | << | >> | THREAD: | << | >> | INDEX: | Main | Thread |
|---|
- Previous by Date: Re: Scripting book (was: Industry needs more xsi artists!)
- Next by Date: Re: Scripting book (was: Industry needs more xsi artists!)
- Previous by Thread: Re: Scripting book (was: Industry needs more xsi artists!)
- Next by Thread: Re: Scripting book (was: Industry needs more xsi artists!)
- Index(es):
| Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available. |