版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
CATIACAA二次开发详细教程PAGEPAGE44CATIACAA二次开发详细教程(5)添加一个点在创建任何几何对象之前,必须在激活的函数命令中添加以下代码,:CATFrmEditor*pEditor=CATFrmEditor::GetCurrentEditor();if(pEditor==NULL){
printf("errorgettingtheFRMeditor");}CATDocument*pDoc=pEditor->GetDocument();CATIContainerOfDocument_varspConODocs=pDoc;CATIContainer*pSpecContainer=NULL;HRESULThr=spConODocs->GetSpecContainer(pSpecContainer);if(spConODocs==NULL_var){
printf("errorgettingthecontainerofdocuments");}以上代码的主要功能是获取editor,thedocumentandthecontainer。CATIGSMFactory_varspGSMFactory=NULL_var;CATIPrtFactory_varspPrtFactory=NULL_var;CATICkeParmFactory_varspParmFactory=NULL_var;spGSMFactory=pSpecContainer;spPrtFactory=pSpecContainer;spParmFactory=pSpecContainer;以上代码设置工厂,在这基础上你才可以造型,GSMFactory用于创建底层的几何对象比如点、线等。PrtFactory包含创建孔特征、拉伸特征实体等函数。ParmFactory
包含设定参数的函数。在以上的基础上可以创建点了,步骤如下:(1)创建一个三维数组(x,y,z)定义点坐标。doubleCoords[3];Coords[0]=0;Coords[1]=0;Coords[2]=0;(2)创建一个CATIGSMPoint并将其转换为CATISpecObjectCATIGSMPoint_varspPoint1=spGSMFactory->CreatePoint(Coords);//CreatesapointCATISpecObject_varspSpecPoint1=spPoint1;//CaststhepointasaCATISpecObject(3)为了在CATIA显示你创建的点,必须将其添加到视图中。spSpecPoint1->Update();CATIGSMProceduralView_varspPntObj=spSpecPoint1;spPntObj->InsertInProceduralView();所有的源代码如下://
//CATStatusChangeRCMyCommand::Activate(CATCommand*iFromClient,CATNotification*iEvtDat){
CATFrmEditor*pEditor=CATFrmEditor::GetCurrentEditor();
if(pEditor==NULL)
{
printf("errorgettingtheFRMeditor");
}
CATDocument*pDoc=pEditor->GetDocument();
CATIContainerOfDocument_varspConODocs=pDoc;
CATIContainer*pSpecContainer=NULL;
HRESULThr=spConODocs->GetSpecContainer(pSpecContainer);
if(spConODocs==NULL_var)
{
printf("errorgettingthecontainerofdocuments");
}
CATIGSMFactory_varspGSMFactory=NULL_var;
CATIPrtFactory_varspPrtFactory=NULL_var;
CATICkeParmFactory_varspParmFactory=NULL_var;
spGSMFactory=pSpecContainer;
spPrtFactory=pSpecContainer;
spParmFactory=pSpecContainer;
doubleCoords[3];
Coords[0]=0;
Coords[1]=0;
Coords[2]=0;
CATIGSMPoint_varspPoint1=spGSMFactory->CreatePoint(Coords);//Createsapoint
CATISpecObject_varspSpecPoint1=spPoint1;//CaststhepointasaCATISpecObject
spSpecPoint1->Update();
CATIGSMProceduralView_varspPntObj=spSpecPoint1;
spPntObj->InsertInProceduralView();
return(CATStatusChangeRCCompleted);}CATIACAA二次开发详细教程(6)创建一条线初始的设定请参考上一讲《CATIACAA
二次开发详细教程(5)添加一个点》。在此基础上,创建线的步骤如下:1)创建两个点并将其转换为CATISpecObjects。doubleCoords[3];Coords[0]=0;Coords[1]=0;Coords[2]=0;CATIGSMPoint_varspPoint1=spGSMFactory->CreatePoint(Coords);CATISpecObject_varspSpecPoint1=spPoint1;
Coords[0]=8;Coords[1]=6;Coords[2]=7;CATIGSMPoint_varspPoint2=spGSMFactory->CreatePoint(Coords);CATISpecObject_varspSpecPoint2=spPoint2;2)
利用创建的点创建一条线,并将其转换为CATISpecObjectCATISpecObject_var
spSupport=NULL_var;CATIGSMLinePtPt_varspLine1=spGSMFactory->CreateLine(spSpecPoint1,spSpecPoint2,spSupport);CATISpecObject_varspSpecLine1=spLine1;3)
更新创建的线,并将其添加到视图中。spSpecLine1->Update();CATIGSMProceduralView_varspCurObj=spLine1;spCurObj->InsertInProceduralView();CATIACAA二次开发详细教程(7)创建草图Sketch有两种方式可以创建草图:1)通过参考平面创建首先获取一个CATIPrtPart变量:CATIPrtPart_varspPart(pIPrtContOnDocument->GetPart());pIPrtContOnDocument->Release();有了CATIPrtPart变量就可以利用其方法GetReferencePlanes(),获取参考平面CATLISTV(CATISpecObject_var)spRefPlanes=spPart->GetReferencePlanes();然后创建XYplane(spRefPlanes[1])CATISketchFactory_varspSketchFactory(pSpecContainer);if(NULL_var==spSketchFactory)return(CATStatusChangeRCCompleted);CATISketch_varspSketch(spSketchFactory->CreateSketch(spRefPlanes[1]));if(NULL_var==spSketch)return(CATStatusChangeRCCompleted);spSketch->OpenEdition();2)
通过原点和两个矢量方向该方法是通过定义一个原点和两个方向pH、pV
进行创建。定义原点和方向:doubleorigin[3]={0.0,0.0,10.0};doublex_dir[3]={1.0,0.0,0.0};doubley_dir[3]={0.0,1.0,0.0};CATISketchFactory_varspSketchFactory(pSpecContainer);if(NULL_var==spSketchFactory)return(CATStatusChangeRCCompleted);CATISketch_varspSketch(spSketchFactory->CreateSketch(origin,x_dir,y_dir));if(NULL_var==spSketch)return(CATStatusChangeRCCompleted);spSketch->OpenEdition();到这里,你已经创建了一个Sketch,你可以在上面创建任意的草图了。创建好记住要将其关闭:spSketch->CloseEdition();CATIACAA二次开发详细教程(8)草图上创建几何图形在上一节的基础上,开始创建草图。首先创建草图工厂:CATI2DWFFactory_varsketch2DFactory(spSketch);下面创建点:CATI2DPoint_varspPt_bottom_left,spPt_bottom_right,spPt_top_right,spPt_top_left;doublept_bottom_left[2]
={10.,10.};doublept_bottom_right[2]={50.,10.};doublept_top_right[2]
={50.,50.};doublept_top_left[2]
={10.,50.};spPt_bottom_left
=sketch2DFactory->CreatePoint(pt_bottom_left);spPt_bottom_right=sketch2DFactory->CreatePoint(pt_bottom_right);spPt_top_right
=sketch2DFactory->CreatePoint(pt_top_right);spPt_top_left
=sketch2DFactory->CreatePoint(pt_top_left);开始创建线:CATI2DLine_varspLine1,spLine2,spLine3,spLine4;spLine1=sketch2DFactory->CreateLine(pt_bottom_left,pt_bottom_right);spLine2=sketch2DFactory->CreateLine(pt_bottom_right,pt_top_right);spLine3=sketch2DFactory->CreateLine(pt_top_right,pt_top_left);spLine4=sketch2DFactory->CreateLine(pt_top_left,pt_bottom_left);将线连接起来:CATI2DCurve_varspCurve1(spLine1);CATI2DCurve_varspCurve2(spLine2);CATI2DCurve_varspCurve3(spLine3);CATI2DCurve_varspCurve4(spLine4);spCurve1->SetStartPoint(spPt_bottom_left);spCurve1->SetEndPoint(spPt_bottom_right);spCurve2->SetStartPoint(spPt_bottom_right);spCurve2->SetEndPoint(spPt_top_right);spCurve3->SetStartPoint(spPt_top_right);spCurve3->SetEndPoint(spPt_top_left);spCurve4->SetStartPoint(spPt_top_left);spCurve4->SetEndPoint(spPt_bottom_left);然后退出草图:spSketch->CloseEdition();CATIACAA二次开发详细教程(9)创建圆角三角形1)创建三个点(参见教程5)
2)将点连成线(参见教程6)
3)通过三点创建一个参考平面,后面进行圆弧倒角时要用到该平面。
CATIGSMPlane3Points_varSupportplane=spGSMFactory->CreatePlane(spPoint1,spPoint2,spPoint3);
CATISpecObject_varspSupportplane=Supportplane;
4)创建倒角半径的参数:
CATICkeParm_varRadius1=NULL_var;
CATICkeMagnitude_varspRadMag=spParamDictionary->FindMagnitude("LENGTH");
CATUnicodeStringname("Radius1");
Radius1=spParmFactory->CreateDimension(spRadMag,name,.01);
5)创建倒角::
CATIGSMCorner_varCorner1=spGSMFactory->CreateCorner(spLine1,
spLine2,
spSupportplane,
Radius1,
CATGSMSameOrientation,
CATGSMSameOrientation,
FALSE);
CATISpecObject_varspCorner1=Corner1;
6)裁剪去多余的线和点:
CATIGSMSplit_varSplit1=spGSMFactory->CreateSplit(spLine1,
spRadius1,
CATGSMSameOrientation);
CATISpecObject_varspSplit1=Split1;CATIGSMSplit_varSplit1a=spGSMFactory->CreateSplit(spSplit1,
spRadius3,
CATGSMInvertOrientation);
CATISpecObject_varspSplit1a=Split1a;
7)将线和圆弧依次连接起来,创建一个序列:
CATLISTV(CATISpecObject_var)joincurves;
joincurves.Append(spSplit1a);
joincurves.Append(spSplit2a);
joincurves.Append(spSplit3a);
joincurves.Append(spRadius1);
joincurves.Append(spRadius2);
joincurves.Append(spRadius3);
8)在讲序列连接起来之前,需要创建一个最小的结合距离:
CATICkeParm_varMergedist=NULL_var;
CATICkeMagnitude_varspMergedist=spParamDictionary->FindMagnitude("LENGTH");
CATUnicodeStringmergename("MergeDistance");
Mergedist=spParmFactory->CreateDimension(spMergedist,
mergename,
.0001);
9)连接起来并插入到视图中:
Nowwecanjointhislistofobjectsintoasingleshapeandinsertitintothepart.
CATIGSMAssemble_varCurveAssy=spGSMFactory->CreateAssemble(joincurves,
Mergedist,
FALSE);
CATISpecObject_varspCurveAssy=CurveAssy;spCurveAssy->Update();
CATIGSMProceduralView_varspCurObj=Curveassembly;
spCurObj->InsertInProceduralView();
CATIACAA二次开发详细教程(10)文档操作方法创建加载保存一、创建(Createthenewdocument)CATDocument*pDoc=NULL;rc=
CATDocumentServices::New("Part",pDoc);if(NULL!=pDoc){
cout<<"NewdocumentcreatedOK"<<endl<<flush;}else{
cout<<"ERRORincreatingNewdocument"<<endl<<flush;
return
2;}Nowthatthesessionisopened,youcancreateanewdocumentusingthe
New
staticmethodof
CATDocumentServices.Thismethodcreatesadocumentandinitializesit,allowingittobeloadedandstoredandmakingiteditable.Inthisusecase,apre-defineddocumenttype,"Part",isusedasadocumenttype.Ininteractivemode,thisisthenamethatappearswhenperforminga
File/New
operation.Itisnotthefileextension,which,inthiscase,is"CATPart".二、打开(Loadthedocument)CATDocument*pDoc=NULL;rc=
CATDocumentServices::Open(argv[1],
pDoc);if(SUCCEEDED(rc)&&(NULL!=pDoc)){
cout<<"DocumentopenedOK"<<endl<<flush;}else{
cout<<"ERRORinopeninganexistingdocument"<<endl<<flush;
return
2;}Nowthatthesessionisopened,youcanloadanexistingdocumentusingthe
Open
staticmethodof
CATDocumentServices.Thismethodneeds,asafirstparameter,theentirestoragepathnameanddocumentnameoftheexistingdocumentthatwewanttoloadintothesession.Inthisusecase,weenterthisinformationasanargumenttotheprogram.Thesecondparameterofthe
Open
methodreturnsa
CATDocumentpointertothedocumentithasloaded.Oncethedocumentexistsinthesession,youcanworkwithobjectswithinit,usingspecificinterfacesexternaltotheObjectModelerBaseframework.三、获取当前文档CATFrmEditor
*pEditor
=GetEditor();if(NULL!=
pEditor
){
cout<<"EditorgotOK"<<endl<<flush;}else{
cout<<"ERRORingettingthecurrenteditor"<<endl<<flush;
return
1;}CATDocument*pDoc=
pEditor->GetDocument();if(NULL!=pDoc){
cout<<"DocumentopenedOK"<<endl<<flush;}else{
cout<<"ERRORinopeninganexistingdocument"<<endl<<flush;
return
2;}
四、提取根容器(RetrievingtheDocumentRootContainer)CATInit*piInitOnDoc=NULL;rc=pDoc->
QueryInterface
(IID_CATInit,(void**)&piInitOnDoc);if(FAILED(rc)){
cout<<"ERRORinQueryInterfaceonCATInitfordoc"<<endl<<flush;
return
3;}
constCATIdentidCATIContainer="CATIContainer";CATIContainer*piRootContainer=NULL;piRootContainer=(CATIContainer*)piInitOnDoc->
GetRootContainer(idCATIContainer);if(NULL==piRootContainer){
cout<<"ERRORinGetRootContainer"<<endl<<flush;
return
4;}Thedocumentrootcontainerisretrievedusingthe
CATInit::GetRootContainer
method.The
CATIContainer
handleretrievedthrough
GetRootContainer
willbenecessarywheneveryouwanttocreateormanipulateobjectsinthedocument.五、保存文档(SavetheDocument)5.1
另存rc=
CATDocumentServices::SaveAs
(*pDoc,argv[1]);if(SUCCEEDED(rc)){
cout<<"DocumentsavedOK"<<endl<<flush;}else{
cout<<"ERRORinsavingdocument"<<endl<<flush;
return
5;}Tosavethenewdocument,usethe
SaveAs
staticmethodof
CATDocumentServices.Thismethodtakesthepointertothedocumentcreatedby
New
asafirstparameter,andthestoragepathnameanddocumentnameunderwhichthedocumentistobestoredasasecondparameter.Inthisusecase,wepassthestoragepathnameanddocumentnameasanargumenttotheprogram.5.2
保存rc=
CATDocumentServices::Save
(*pDoc);if(SUCCEEDED(rc)){
cout<<"DocumentsavedOK"<<endl<<flush;}else{
cout<<"ERRORinsavingdocument"<<endl<<flush;
return
3;}Tosavethenewdocumentunderthesamename,usethe
Save
staticmethodof
CATDocumentServices.Thismethodtakesthe
CATDocument
pointertothedocumentastheonlyparameter.
六、删除(Removethedocument)rc=
CATDocumentServices::Remove
(*pDoc);if(SUCCEEDED(rc)){
cout<<"DocumentremovedOK"<<endl<<flush;}else{
cout<<"ERRORinremovingdocument"<<endl<<flush;
return
6;}Ifyoueverneededtore-openthedocumentduringthissamesession,itwouldthenbenecessarytoalsoremoveitfromthesessionafterhavingsavedit.Otherwise,youneednotworryaboutitsincedeletingthesessionwillautomaticallyremovethedocumentaswell.Toremovethedocument,youshouldusetheRemovestaticmethodof
CATDocumentServices.七、按指定文档格式保存(ExportingaDocumentFormatType)7.1DefiningtheNewDocumentFormatTypeCATProduct_OmbExportType
CATIExportTypeManager
libCAAOmbExportTypeAnewdocumentformattypeissimplydefinedbyaddinganewentryinthecurrentframework'sdictionary.Thisnewentrywillcausethe
File/SaveAs
dialogboxtolistthenewformattypeamongthetypesdefinedtothesaveoperation.Thefirstparameter,
CATProduct_OmbExportType,indicatesthatthe
exporting
documentisaProduct-typedocument(i.e.,adocumenthavinga.CATProductsuffix)andthatthe
exported
documentformattypeis"OmbExportType",whichwillalsobethesuffixofthesaveddocument.Thesecondparameterindicatesthatthisnewdocumenttypewillimplementthe
CATIExportTypeManager
interfaceinordertodefinethespecificsaveoperationsnecessarytoexportthenewdocument.Thelastparameteristhenameofthelibraryinwhichtheimplementationmoduleistobefound.7.2ImplementingCATIExportTypeManager
SeetheObjectModelerarticles[2]foradetailedexplanationaboutinterfaceimplementations.Theimplementationof
CATIExportTypeManager
isfoundintheCAAOmbExportType.mmoduledefiningthe
CAAEOmbExportTypeData
implementationclass.CATImplementClass(CAAEOmbEExportTypeData,
CodeExtension,
CATBaseUnknown,
CATProduct_OmbExportType);The
CATImplementClass
macrodefinestheimplementationclass
CAAEOmbExportTypeData
asacodeextensionimplementingthe
CATProduct_OmbExportType
latetype.#include"TIE_CATIExportTypeManager.h"TIE_CATIExportTypeManager(CAAEOmbExp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 山东省菏泽市鲁西新区2023-2024学年六年级下学期期末考试英语试卷
- 【名校高考】2024年最后十套:文科数学(8)考前提分仿真卷含答案
- 24.1.1 圆 人教版数学九年级上册堂堂练(含答案)
- 2024届江苏省镇江市高三第三次模拟考试语文试卷(解析版)
- 电商行业的消费者满意度影响因素培训师资队伍建设
- 股权结构对公司财务适应性的影响分析
- 雕塑艺术行业发展方向及匹配能力建设研究报告
- 健身营养咨询与指导行业相关项目现状分析及对策
- 2023年浙江高信技术股份有限公司招聘笔试真题
- 2023年深圳市坪山区招聘事业单位人员笔试真题
- 初中生物理实验比赛评分表
- 《总也倒不了的老屋》 第二课时公开课一等奖创新教学设计
- 新能源汽车充电设施安全检查记录表
- 在灿烂阳光下合唱钢琴伴奏谱
- 《养老护理员》-课件:职业道德
- 物业公共区域环保知识培训
- 2024年PCB感光油墨相关项目营销计划书
- 工作周报WK38==谢汝君课件
- 班级管理经验交流课件
- 口腔卫生健康宣教
- 脑卒中专科护士核心能力现状及影响因素
评论
0/150
提交评论