CAA 建立批处理生成有序零件
初学CAA,C++,在VS2012下建立程序,主程序传入需要生成part文件的地址值。注:头文件是CAA partinterface框架示例中的,不需要这么多。
本程序灵感源于CATIA机械设计下的文件管理与命名问题。
#include"CATSession.h"//needed to manage Session
#include"CATDocument.h" // needed to manage documents
#include "CATDocumentServices.h" // needed to create/save documents
#include "CATSessionServices.h" // needed to create/delete session
#include "CATInit.h" // needed to retrieve root container from document
#include "CATMathPlane.h" // needed to manage planes
#include "CATMathDirection.h" // needed to manage directions
#include "CATMathPoint.h" // needed to manage points
#include "CATISketchFactory.h" // needed to create sketchs
#include "CATI2DWFFactory.h" // needed to create 2D elements
#include "CATISketch.h" // needed to edit/modify sketch
#include "CATI2DCurve.h" // needed to define the start and end point
// of a sketch
#include "CATI2DPoint.h" // needed to define the start and end point
// of a sketch
#include "CATIPrtFactory.h" // needed to create pad feature
#include "CATIPad.h" // needed to manage pad
#include "CATLimitDefs.h" // needed to access limit type of the pad feature
#include "CATIPrtContainer.h" // needed to retrieve factories
#include "CATIPrtPart.h" // needed to access reference planes
#include<stdio.h>
#include<stdlib.h>
#include<string>
using std::string;
string Transferaddress(int name,string baseadress)
{
string Finaladdress;
string s("\\");
char tempname[50];
string nametemp=itoa(name,tempname,10);
Finaladdress=baseadress+s+nametemp;
return Finaladdress;
}
int main(int iArgc,char*iArgv[])
{
int rc=0;
if(2!=iArgc)
return 1;
string base=iArgv[1];
int i=0;
for(i=0;i<10;i++)
{
CATSession * pSampleSession = NULL;
Create_Session("SampleSession",pSampleSession);
CATDocument * pDoc= NULL;
CATDocumentServices::New("CATPart",pDoc);
HRESULT boolSave = E_FAIL;
string nomPart2=Transferaddress(i,base);
char *Finaladdress=(char*)nomPart2.c_str();
boolSave = CATDocumentServices::SaveAs(*pDoc,Finaladdress);
// Closes the session
::Delete_Session("SampleSession");
}
return rc;
};
下图为生成结果。
Vs2012下不支持C++11新特性to_string转换整型至字符型,这里采用
C语言方法itoa。
初次学习,请多指教。