一段获得Part document下参数的代码,包括用户自己建的参数以及自动生成的参数
我写的一段批处理的程序。因为自己在做这一块,很多不懂的,在论坛上受到启发,做出一点成果来,希望和大家分享,共同讨论。
int main(int iArgc, // Number of arguments (1)
char **iArgv) // Path to an existing *.CATPart document
{
if( 2!=iArgc )
{
cout <<"CAAMmrPartBodyRequest FileName" << endl;
cout <<"Where FileName is the complete path of a Part document" <<endl;
cout <<"You can use the following Part: " ;
cout <<" $WSROOT/CAAMechanicalModeler.edu/InputData/CAAMmrPartBodyRequest.CATPart"<< endl;
return 1;
}
cout <<"The CAAMmrPartBodyRequest use case begins" << endl ;
// 2- Creates a session
char *pSessionName = "SampleSession";
CATSession *pSession = 0;
HRESULT rc = ::Create_Session(pSessionName, pSession) ;
if ( FAILED(rc) )
{
cout <<" Error in creating a session" << endl;
return 1 ;
}
//
// 3- Loads the document and initializes it
//
CATDocument *pDoc = 0;
rc = CATDocumentServices::OpenDocument(iArgv[1], pDoc) ;
if ( SUCCEEDED(rc) && ( NULL !=pDoc) )
{
cout <<" The document " << iArgv[1] << " is opened" << endl ;
}else
{
cout <<" Pb in opening the " << iArgv[1] <<" document" << endl;
return 1 ;
}
//
// 4- Queries on the document to get the root container
//
CATInit *pDocAsInit = NULL ;
rc = pDoc->QueryInterface(IID_CATInit, (void**)&pDocAsInit);
if ( FAILED(rc) )
{
cout <<" Error in retrieving a QI on CATInit" << endl;
return 1 ;
}
CATIPrtContainer *pSpecContainer = NULL ;
pSpecContainer = (CATIPrtContainer*)pDocAsInit->GetRootContainer("CATIPrtContainer");
if ( NULL == pSpecContainer )
{
cout <<" Error in retrieving the Root container" << endl;
return 1 ;
}
pDocAsInit->Release();
pDocAsInit = NULL ;
//
// 5- Retrieves on the root container (CATPrtCont) to get the Part feature
//
CATIPrtPart_var spPart = pSpecContainer->GetPart() ;
if ( NULL_var == spPart )
{
cout <<" Error in retrieving the Part feature" << endl;
return 1 ;
}
//Retrieves the reference plane
CATIPrtPart * pIPrtPart = NULL ;
rc=spPart->QueryInterface(IID_CATIPrtPart,(void**) & pIPrtPart ) ;
if (SUCCEEDED(rc)) cout<<"Getting Interface CATIPrtPart succeessful"<<endl;
CATListValCATISpecObject_var ListRefPlanes = pIPrtPart ->GetReferencePlanes();
cout<<ListRefPlanes.Size()<<endl;
pIPrtPart->Release();
pIPrtPart = NULL;
if (NULL_var != spPart)
{
CATIParmPublisher * pIParmPublisher = NULL;
rc = spPart->QueryInterface(IID_CATIParmPublisher,(void**)&pIParmPublisher);
if (FAILED(rc)) cout<<"Getting interface CATIParmPublisher failed"<<endl;
if (SUCCEEDED(rc)) cout<<"Getting interface CATIParmPublisher succeeded"<<endl;
CATLISTV (CATISpecObject_var) ParaList ;
pIParmPublisher->GetAllChildren("CATICkeParm",ParaList);
int Nb = ParaList.Size();
cout<<"ara number is:"<<Nb<<endl;
CATICkeParm *pICkeParm = NULL;
// CATISpecObject_var specObj = ParaList[1] ;
// rc = specObj->QueryInterface(IID_CATICkeParm,(void**) &pICkeParm);
// if (SUCCEEDED(rc))
// cout<<"Getting interface CATICkeParm from CATISpecObject successful"<<endl;
// else
// cout<<"Getting interface CATICkeParm from CATISpecObject failed"<<endl;
// cout<<pICkeParm->Name()<<endl;
int i;
for(i=1;i<Nb;i++)
{
CATISpecObject_var specObj = ParaList[i] ;
rc = specObj->QueryInterface(IID_CATICkeParm,(void**) &pICkeParm);
cout<<pICkeParm->Name()<<endl;
}
pIParmPublisher->Release();
pIParmPublisher = NULL;
}
pSpecContainer->Release();
pSpecContainer = NULL ;
//
// 8- Ends session and drops document
//
rc = :elete_Session(pSessionName);
if (FAILED(rc) )
{
cout << "ERROR in deleting session" << endl ;
return 1;
}
cout <<"The CAAMmrPartBodyRequest use case is ended" << endl ;
return 0;
}
|