CATIA CAA API Help – 3

// GOAL: COPY A BODY AND PASTE IT AS RESULT

// lock the doc
CATLockDocument((*pDoc));

// get the mechtool to copy
CATISpecObject_var MechToolToCopy = …

// get the target for copy
CATISpecObject_var TargetBody = …

// append in a list the path element of the target
CATLISTV(CATBaseUnknown_var) listTargets;
CATPathElement *pathTarget = new CATPathElement(TargetBody);
pathTarget->AddFatherElement (TargetBody->GetFather());
listTargets.Append(pathTarget);
pathTarget->Release();

// append in a list the feature(s?) to be copied
CATLISTV(CATBaseUnknown_var) listObjectsToCopy;
listObjectsToCopy.Append(MechToolToCopy);

CATLISTV(CATBaseUnknown_var) listObjectsAlreadyInBoundary;
CATFormat* asResultprt = NULL;
CATICutAndPastable_var prtcontasccpable((CATIPrtContainer*) spInitOnDoc->GetRootContainer(“CATIPrtContainer”));
CATLISTP(CATFormat) formatsprt = prtcontasccpable->ListExtractFormats();
for(int q=1; q<=formatsprt.Size(); q++)
{
if(0 == strcmp(“CATPrtResult”, formatsprt[q]->Name())) // there is also “CATPrtResultWithOutLink” and lots of other formats – you can copy containers etc.
asResultprt = formatsprt[q];
}
int resultat = prtcontasccpable->BoundaryExtract(listObjectsAlreadyInBoundary,
&listObjectsToCopy,
asResultprt);
// create a structure to receive the boundary object in the requested format.
CATBaseUnknown_var spEltCopy = prtcontasccpable->Extract(listObjectsAlreadyInBoundary,
asResultprt);

// interpret this new structure as a ccpable
CATICutAndPastable_var spCAPOnEltCopy(spEltCopy);

CATLISTV(CATBaseUnknown_var) listObjects;
CATFormat* asResult0 = NULL;
CATLISTP(CATFormat) formats0 = spCAPOnEltCopy->ListExtractFormats();
for(int p=1; p<=formats0.Size(); p++)
{
if(0 == strcmp(“CATPrtResult”, formats0[p]->Name())) // there is also “CATPrtResult” and lots of other formats – you can copy containers etc.
asResult0 = formats0[p];
}
int resultat2 = spCAPOnEltCopy->BoundaryExtract(listObjects,NULL,asResult0);
// Perfoms the paste operation
CATICutAndPastable_var spEndCAPOnPrtCont(piPrtCont);

// get the CATFormat which says that paste should be as result
CATFormat* asResult = NULL;
CATLISTP(CATFormat) formats = spEndCAPOnPrtCont->ListExtractFormats();
for(int o=1; o<=formats.Size(); o++)
{
if(0 == strcmp(“CATPrtResult”, formats[o]->Name())) // there is also “CATPrtResult” and lots of other formats – you can copy containers etc.
asResult = formats[o];
}
// We instantiate the feature in the destination container.
// It consists in creating the feature, aggregating it at the appropriate position
// according to the specified target and updating it in its new context
CATLISTV(CATBaseUnknown_var) spFinalObject = spEndCAPOnPrtCont->Paste(listObjects,
&listTargets,
asResult);
CATISpecObject_var spSpecOnPart(spPart);
if(NULL_var != spSpecOnPart)
spSpecOnPart->Update();

// unlock doc
CATUnLockDocument((*pDoc));

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s