dchabaud
Computer
- Jun 11, 2013
- 5
Hello,
I am trying to use Catia V5 Automation from a C++ program. I already succeeded in creating a Pad and a Sweep from an existing sketch. I am now trying to create a spline in an empty sketch.
After getting the sketch, I create 5 control points with success (they appear in the Catia tree). But I failed with the call to CreateSpline because it takes a SAFEARRAY but I don't know what data type to put inside...
I tried with VBA and there is no problem, the control points are stored in a Dim array then the array is directly pass to CreateSpline.
Any idea?
Thanks
I am trying to use Catia V5 Automation from a C++ program. I already succeeded in creating a Pad and a Sweep from an existing sketch. I am now trying to create a spline in an empty sketch.
After getting the sketch, I create 5 control points with success (they appear in the Catia tree). But I failed with the call to CreateSpline because it takes a SAFEARRAY but I don't know what data type to put inside...
Code:
// Get Sketch
BSTR MySketchName = SysAllocString(L"Sketch.1");
INFITF::CATBaseDispatchPtr pCatiaSketchDispatchPtr;
pCatiaSketchesPtr->GetItem(&MySketchName, &pCatiaSketchDispatchPtr);
MECMOD::SketchPtr pCatiaSketchPtr = pCatiaSketchDispatchPtr;
// Get the 2D factory
MECMOD::Factory2DPtr pCatiaFactory2DPtr;
pCatiaSketchPtr->get_Factory2D(&pCatiaFactory2DPtr);
// Create control points
const long nb = 5;
MECMOD::ControlPoint2DPtr pControlPoint2DPtr[nb];
hrResult = pCatiaFactory2DPtr->CreateControlPoint( 0.0, 100.0, &(pControlPoint2DPtr[0]));
hrResult = pCatiaFactory2DPtr->CreateControlPoint(-50.0, 50.0, &(pControlPoint2DPtr[1]));
hrResult = pCatiaFactory2DPtr->CreateControlPoint(-60.0, 0.0, &(pControlPoint2DPtr[2]));
hrResult = pCatiaFactory2DPtr->CreateControlPoint(-50.0, -50.0, &(pControlPoint2DPtr[3]));
hrResult = pCatiaFactory2DPtr->CreateControlPoint( 0.0, -100.0, &(pControlPoint2DPtr[4]));
for (long i = 0; i < nb; i++)
pControlPoint2DPtr[i]->put_ReportName(i + 20);
// Store control points in a COM safearray
SAFEARRAY* saPoints;
SAFEARRAYBOUND Bound;
Bound.lLbound = 0;
Bound.cElements = nb;
saPoints = SafeArrayCreate(VT_UINT_PTR, 1, &Bound);
for (LONG i = 0; i < (LONG)nb; i++)
{
hrResult = SafeArrayPutElement(saPoints, &i, &(pControlPoint2DPtr[i]));
}
// Create a spline with the control points
MECMOD::Spline2DPtr pSpline2DPtr;
hrResult = pCatiaFactory2DPtr->CreateSpline(saPoints, &pSpline2DPtr);
I tried with VBA and there is no problem, the control points are stored in a Dim array then the array is directly pass to CreateSpline.
Any idea?
Thanks