iCAx开思网

标题: 新人求助-大家帮忙看看代码哪儿出错了啊? [打印本页]

作者: lucian123    时间: 2012-12-31 14:53
标题: 新人求助-大家帮忙看看代码哪儿出错了啊?
求大神指点。。。刚接触二次开发,照例子做,生成一个NURBS曲面,代码贴进去后,调试没错误,但CATIA显示“单击确定终止”,看不出错误啊
代码如下:
CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
CATDocument*pDoc = pEditor->GetDocument();
CATIContainerOfDocument_var spConODocs = pDoc;
CATIContainer* spCGMContainer= NULL;
HRESULT hr = spConODocs->GetResultContainer(spCGMContainer);
CATGeoFactory_var piGeomFactory = spCGMContainer;
int nbPoleU = 5;
int nbPoleV = 5;
CATMathGridOfPoints gridOfPoints(nbPoleU,nbPoleV);
   
// Row 0
gridOfPoints.SetPoint(CATMathPoint( 0., 0., 0.),0,0);
gridOfPoints.SetPoint(CATMathPoint(10., 0., 0.),0,1);
gridOfPoints.SetPoint(CATMathPoint(20., 0., 0.),0,2);
gridOfPoints.SetPoint(CATMathPoint(30., 0., 0.),0,3);
gridOfPoints.SetPoint(CATMathPoint(40., 0., 0.),0,4);
   
// Row 1
gridOfPoints.SetPoint(CATMathPoint( 0.,10., 0.),1,0);
gridOfPoints.SetPoint(CATMathPoint(10.,10.,-10.),1,1);
gridOfPoints.SetPoint(CATMathPoint(20.,10.,-10.),1,2);
gridOfPoints.SetPoint(CATMathPoint(30.,10.,-10.),1,3);
gridOfPoints.SetPoint(CATMathPoint(40.,10., 0.),1,4);
   
// Row 2
gridOfPoints.SetPoint(CATMathPoint( 0.,20., 0.),2,0);
gridOfPoints.SetPoint(CATMathPoint(10.,20.,-40.),2,1);
gridOfPoints.SetPoint(CATMathPoint(20.,20.,-40.),2,2);
gridOfPoints.SetPoint(CATMathPoint(30.,20., -40.),2,3);
gridOfPoints.SetPoint(CATMathPoint(40.,20., 0.),2,4);
   
// Row 4
gridOfPoints.SetPoint(CATMathPoint( 0.,30., 0.),3,0);
gridOfPoints.SetPoint(CATMathPoint(10.,30., -10.),3,1);
gridOfPoints.SetPoint(CATMathPoint(20.,30., -10.),3,2);
gridOfPoints.SetPoint(CATMathPoint(30.,30., -10.),3,3);
gridOfPoints.SetPoint(CATMathPoint(40.,30., 0.),3,4);
   
// Row 5
gridOfPoints.SetPoint(CATMathPoint( 0.,40., 0.),4,0);
gridOfPoints.SetPoint(CATMathPoint(10.,40., 0.),4,1);
gridOfPoints.SetPoint(CATMathPoint(20.,40., 0.),4,2);
gridOfPoints.SetPoint(CATMathPoint(30.,40., 0.),4,3);
gridOfPoints.SetPoint(CATMathPoint(40.,40., 0.),4,4);
//This code creates the knot vectors:
CATLONG32 IsPeriodic= 0;
CATLONG32 Degree= 4;
CATLONG32 KnotsCount= 2;
double Knots[]= {0.,10.};
CATLONG32 Multiplicities[]= {5,5};
CATLONG32 IndexOffset= 1;
   
CATKnotVector NonUniformU(Degree,IsPeriodic,KnotsCount,Knots,
Multiplicities,IndexOffset);
CATKnotVector NonUniformV(Degree,IsPeriodic,KnotsCount,Knots,
Multiplicities,IndexOffset);

CATLONG32 isRational=1;
double * aWeights=new double[nbPoleU*nbPoleV];
for (int i = 0; i < nbPoleU*nbPoleV; i++)
{
aWeights[i] = 1.;
}
CATNurbsSurface * piSurf1 = piGeomFactory->CATCreateNurbsSurface(NonUniformU, NonUniformV,isRational,gridOfPoints,aWeights);

delete [] aWeights;
aWeights = NULL;

CATSurLimits surMaxLimits ;
piSurf1->GetMaxLimits(surMaxLimits) ;
   
CATSoftwareConfiguration * pConfig = new CATSoftwareConfiguration();
CATTopData topdata(pConfig);
   
CATTopSkin * pSkinOpe =::CATCreateTopSkin(piGeomFactory,&topdata,piSurf1,&surMaxLimits);
pSkinOpe->Run();

CATBody * piSkinBody = pSkinOpe->GetResult();

delete pSkinOpe;
pSkinOpe=NULL;
//Next you will instanciate the datum from the CATBody:
CATIDatumFactory_var spDatumFactory= NULL_var;
spDatumFactory = spCGMContainer;
CATISpecObject* oDatumFeature;
spDatumFactory->InstanciateDatum(piSkinBody, oDatumFeature);
CATISpecObject_var spCurObj = oDatumFeature;
oDatumFeature->Update();
CATIPrtProceduralView_var aa=spCurObj;
aa->InsertInProceduralView();
pConfig->Release();
}


作者: xieqling    时间: 2013-3-22 09:56
检查一下有没有空指针
作者: cww1234    时间: 2023-12-22 11:09
问题出在这一句:
spDatumFactory = spCGMContainer;
得到的
spDatumFactory为空,spCGMContainer是CATIContainer,改用:CATIPrtContainer




欢迎光临 iCAx开思网 (https://www.icax.org/) Powered by Discuz! X3.3