CATIA CAA 二次开发 详细教程(5)添加一个点
更新时间:2024-04-25 04:08:01 阅读量: 综合文库 文档下载
- catia软件推荐度:
- 相关推荐
CATIA CAA 二次开发 详细教程
CATIA CAA 二次开发 详细教程(5)添加一个点
在创建任何几何对象之前,必须在激活的函数命令中添加以下代码,: CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor(); if(pEditor == NULL) {
printf(\ }
CATDocument *pDoc = pEditor->GetDocument(); CATIContainerOfDocument_var spConODocs = pDoc; CATIContainer* pSpecContainer = NULL;
HRESULT hr = spConODocs->GetSpecContainer(pSpecContainer); if(spConODocs == NULL_var) {
printf(\ }
以上代码的主要功能是获取editor, the document and the container。 CATIGSMFactory_var spGSMFactory = NULL_var; CATIPrtFactory_var spPrtFactory = NULL_var; CATICkeParmFactory_var spParmFactory = NULL_var; spGSMFactory = pSpecContainer; spPrtFactory = pSpecContainer; spParmFactory = pSpecContainer;
以上代码设置工厂,在这基础上你才可以造型,GSMFactory用于创建底层的几何对象比如点、线等。PrtFactory包含创建孔特征、拉伸特征实体等函数。ParmFactory 包含设定参数的函数。
在以上的基础上可以创建点了,步骤如下: (1)创建一个三维数组(x,y,z)定义点坐标。 double Coords[3]; Coords[0] = 0; Coords[1] = 0; Coords[2] = 0;
(2)创建一个CATIGSMPoint并将其转换为CATISpecObject
CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(Coords); //Creates a point
30
CATIA CAA 二次开发 详细教程
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts the point as a CATISpecObject
(3)为了在CATIA显示你创建的点,必须将其添加到视图中。 spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1; spPntObj->InsertInProceduralView(); 所有的源代码如下: // www.mememama.cn
// ----------------------------------------------------
CATStatusChangeRC MyCommand::Activate( CATCommand * iFromClient, CATNotification * iEvtDat)
{
CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
if(pEditor == NULL) {
printf(\r\
}
CATDocument *pDoc = pEditor->GetDocument(); CATIContainerOfDocument_var spConODocs = pDoc; CATIContainer* pSpecContainer = NULL;
HRESULT hr = spConODocs->GetSpecContainer(pSpecContainer);
if(spConODocs == NULL_var) {
printf(\ of documents\
}
CATIGSMFactory_var spGSMFactory = NULL_var; CATIPrtFactory_var spPrtFactory = NULL_var; CATICkeParmFactory_var spParmFactory = NULL_var; spGSMFactory = pSpecContainer; spPrtFactory = pSpecContainer; spParmFactory = pSpecContainer;
31
CATIA CAA 二次开发 详细教程
double Coords[3]; Coords[0] = 0; Coords[1] = 0; Coords[2] = 0;
CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(Coords); //Creates a point
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts the point as a CATISpecObject
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
spPntObj->InsertInProceduralView();
return (CATStatusChangeRCCompleted); }
CATIA CAA 二次开发 详细教程(6)创建一条线
初始的设定请参考上一讲《CATIA CAA 二次开发 详细教程(5)添加一个点》。在此基础上,创建线的步骤如下:
1)创建两个点并将其转换为CATISpecObjects。 double Coords[3]; Coords[0] = 0; Coords[1] = 0; Coords[2] = 0;
CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(Coords); CATISpecObject_var spSpecPoint1 =
spPoint1;
Coords[0] = 8; Coords[1] = 6; Coords[2] = 7;
CATIGSMPoint_var spPoint2 = spGSMFactory->CreatePoint(Coords); CATISpecObject_var spSpecPoint2 = spPoint2;
32
CATIA CAA 二次开发 详细教程
2) 利用创建的点创建一条线,并将其转换为CATISpecObject CATISpecObject_var spSupport = NULL_var;
CATIGSMLinePtPt_var spLine1 = spGSMFactory->CreateLine(spSpecPoint1, spSpecPoint2, spSupport);
CATISpecObject_var spSpecLine1 = spLine1; 3) 更新创建的线,并将其添加到视图中。 spSpecLine1->Update();
CATIGSMProceduralView_var spCurObj = spLine1; spCurObj->InsertInProceduralView();
CATIA CAA 二次开发 详细教程(7)创建草图Sketch
有两种方式可以创建草图: 1)通过参考平面创建
首先获取一个CATIPrtPart变量:
CATIPrtPart_var spPart(pIPrtContOnDocument->GetPart()); pIPrtContOnDocument->Release();
有了CATIPrtPart变量就可以利用其方法GetReferencePlanes(),获取参考平面
CATLISTV(CATISpecObject_var) spRefPlanes = spPart->GetReferencePlanes();
然后创建XY plane (spRefPlanes[1])
CATISketchFactory_var spSketchFactory(pSpecContainer); if ( NULL_var == spSketchFactory ) return (CATStatusChangeRCCompleted);
CATISketch_var
spSketch(spSketchFactory->CreateSketch(spRefPlanes[1]));
if ( NULL_var == spSketch ) return (CATStatusChangeRCCompleted); spSketch->OpenEdition(); 2) 通过原点和两个矢量方向
该方法是通过定义一个原点和两个方向pH、pV 进行创建。 定义原点和方向:
double origin[3]={0.0,0.0,10.0}; double x_dir[3]={1.0,0.0,0.0};
33
CATIA CAA 二次开发 详细教程
double y_dir[3]={0.0,1.0,0.0};
CATISketchFactory_var spSketchFactory(pSpecContainer); if ( NULL_var == spSketchFactory ) return (CATStatusChangeRCCompleted);
CATISketch_var
spSketch(spSketchFactory->CreateSketch(origin,x_dir,y_dir));
if ( NULL_var == spSketch ) return (CATStatusChangeRCCompleted); spSketch->OpenEdition();
到这里,你已经创建了一个Sketch,你可以在上面创建任意的草图了。 创建好记住要将其关闭: spSketch->CloseEdition();
CATIA CAA 二次开发 详细教程(8)草图上创建几何图形
在上一节的基础上,开始创建草图。首先创建草图工厂: CATI2DWFFactory_var sketch2DFactory(spSketch); 下面创建点:
CATI2DPoint_var spPt_bottom_left, spPt_bottom_right, spPt_top_right, spPt_top_left;
double pt_bottom_left[2] = {10., 10.}; double pt_bottom_right[2] = {50., 10.}; double pt_top_right[2] = {50., 50.}; double pt_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_var spLine1, 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_var spCurve1 (spLine1);
34
CATIA CAA 二次开发 详细教程
CATI2DCurve_var spCurve2 (spLine2); CATI2DCurve_var spCurve3 (spLine3); CATI2DCurve_var spCurve4 (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();
CATIA CAA 二次开发 详细教程(9)创建圆角三角形
1)创建三个点(参见教程5) 2) 将点连成线(参见教程6)
3) 通过三点创建一个参考平面,后面进行圆弧倒角时要用到该平面。 CATIGSMPlane3Points_var Supportplane = spGSMFactory->CreatePlane(spPoint1, spPoint2,spPoint3);
CATISpecObject_var spSupportplane = Supportplane; 4) 创建倒角半径的参数:
CATICkeParm_var Radius1 = NULL_var;
CATICkeMagnitude_var spRadMag = spParamDictionary->FindMagnitude(\GTH\
CATUnicodeString name(\
Radius1 = spParmFactory->CreateDimension(spRadMag,name, .01); 5) 创建倒角::
CATIGSMCorner_var Corner1 = spGSMFactory->CreateCorner(spLine1, spLine2, spSupportplane, Radius1,
CATGSMSameOrientation, CATGSMSameOrientation, FALSE);
CATISpecObject_var spCorner1 = Corner1;
35
CATIA CAA 二次开发 详细教程
6) 裁剪去多余的线和点:
CATIGSMSplit_var Split1 = spGSMFactory->CreateSplit(spLine1, spRadius1,
CATGSMSameOrientation);
CATISpecObject_var spSplit1 = Split1;
CATIGSMSplit_var Split1a = spGSMFactory->CreateSplit(spSplit1, spRadius3,
CATGSMInvertOrientation);
CATISpecObject_var spSplit1a = 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_var Mergedist = NULL_var;
CATICkeMagnitude_var spMergedist = spParamDictionary->FindMagnitude(\LENGTH\
CATUnicodeString mergename(\
Mergedist = spParmFactory->CreateDimension(spMergedist, mergename, .0001);
9)连接起来并插入到视图中:
Now we can join this list of objects into a single shape and insert it into the part.
CATIGSMAssemble_var CurveAssy = spGSMFactory->CreateAssemble(joincurves, Mergedist, FALSE);
CATISpecObject_var spCurveAssy = CurveAssy;
spCurveAssy->Update();
CATIGSMProceduralView_var spCurObj = Curveassembly;
36
CATIA CAA 二次开发 详细教程
spCurObj->InsertInProceduralView();
CATIA CAA 二次开发详细教程(10) 文档操作方法 创建 加载 保存
一、创建(Create the new document)
CATDocument* pDoc = NULL;
rc = CATDocumentServices::New(\ if (NULL != pDoc) {
cout << \ } else {
cout << \ return 2; }
Now that the session is opened, you can create a new document using the New static method of CATDocumentServices. This method creates a document and initializes it, allowing it to be loaded and stored and making it editable. In this use case, a pre-defined document type, \is used as a document type. In interactive mode, this is the name that appears when performing a File/New operation. It is not the file extension, which, in this case, is \
二、打开(Load the document)
37
CATIA CAA 二次开发 详细教程
CATDocument *pDoc = NULL;
rc = CATDocumentServices::Open(argv[1], pDoc); if (SUCCEEDED(rc) && (NULL != pDoc)) {
cout << \ } else {
cout << \ return 2; }
Now that the session is opened, you can load an existing document using the Ope
n static method of CATDocumentServices. This method needs, as a first parameter, the
entire storage path name and document name of the existing document that we want to load into the session. In this use case, we enter this information as an argument to the program. The second parameter of the Open method returns a CATDocumentpointer to the document it has loaded.
Once the document exists in the session, you can work with objects within it, using specific interfaces external to the ObjectModelerBase framework.
三、获取当前文档
CATFrmEditor * pEditor = GetEditor(); if (NULL != pEditor ) {
cout << \ } else {
cout << \ return 1; }
CATDocument *pDoc = pEditor->GetDocument(); if (NULL != pDoc) {
cout << \ } else {
cout << \ return 2; }
38
CATIA CAA 二次开发 详细教程
四、提取根容器(Retrieving the Document Root
Container)
CATInit *piInitOnDoc = NULL;
rc = pDoc -> QueryInterface (IID_CATInit, (void**) &piInitOnDoc); if (FAILED(rc)) {
cout << \ return 3; }
const CATIdent idCATIContainer = \ CATIContainer *piRootContainer = NULL;
piRootContainer = (CATIContainer*) piInitOnDoc -> GetRootContainer(idCATIContainer);
if (NULL == piRootContainer) {
cout << \ return 4; }
The document root container is retrieved using the CATInit::GetRootContainer method. The CATIContainer handle retrieved through GetRootContainer will be necessary whenever you want to create or manipulate objects in the document.
五、保存文档(Save the Document)
5.1 另存
rc = CATDocumentServices::SaveAs (*pDoc, argv[1]); if (SUCCEEDED(rc)) {
cout << \ } else {
cout << \ return 5; }
To save the new document, use the SaveAs static method of CATDocumentServices. This method takes the pointer to the document created by New as a first parameter, and the storage path name and document name under which the document is to be stor
39
CATIA CAA 二次开发 详细教程
ed as a second parameter. In this use case, we pass the storage path name and document name as an argument to the program.
5.2 保存
rc = CATDocumentServices::Save (*pDoc); if (SUCCEEDED(rc)) {
cout << \ } else {
cout << \ return 3; }
To save the new document under the same name, use the Save static method of CATDocumentServices. This method takes the CATDocument pointer to the document as the only parameter.
六、删除(Remove the document)
rc = CATDocumentServices::Remove (*pDoc); if (SUCCEEDED(rc)) {
cout << \ } else {
cout << \ return 6; }
If you ever needed to re-open the document during this same session, it would then be necessary to also remove it from the session after having saved it. Otherwise, you need not worry about it since deleting the session will automatically remove the document as well. To remove the document, you should use the Remove static method of CATDocumentServices.
七、按指定文档格式保存(Exporting a Document
Format Type)
7.1 Defining the New Document Format Type
CATProduct_OmbExportType CATIExportTypeManager libCAAOmbExportType
40
CATIA CAA 二次开发 详细教程
A new document format type is simply defined by adding a new entry in the current framework's dictionary. This new entry will cause the File/SaveAs dialog box to list the new format type among the types defined to the save operation. The first parameter, CATProduct_OmbExportType, indicates that the exporting document is a Product-type document (i.e., a document having a .CATProduct suffix) and that the exported document format type is \the saved document. The second parameter indicates that this new document type will implement the CATIExportTypeManager interface in order to define the specific save operations necessary to export the new document. The last parameter is the name of the library in which the implementation module is to be found.
7.2 Implementing CATIExportTypeManager
See the Object Modeler articles [2] for a detailed explanation about interface implementations.
The implementation of CATIExportTypeManager is found in the CAAOmbExportType.m module defining the CAAEOmbExportTypeData implementation class.
CATImplementClass( CAAEOmbEExportTypeData,
CodeExtension, CATBaseUnknown,
CATProduct_OmbExportType );
The CATImplementClass macro defines the implementation class CAAEOmbExportType
Data as a code extension implementing the CATProduct_OmbExportType late type. #include \
TIE_CATIExportTypeManager( CAAEOmbExportTypeData );
The above statement indicates that this is an implementation of the CATIExportTypeManager interface.
HRESULT CAAEOmbExportTypeData::ExportData ( CATDocument *pDoc,
CATUnicodeString path ) {
cout << \ HRESULT rc = CATDocumentServices::SaveAs (*pDoc,
path);
return rc; }
In this case, the document is simply saved using the SaveAs method of CATDocumentServices. However, it is in this method that you must code any specific save o
perations necessary for your new document type.
41
CATIA CAA 二次开发 详细教程
CATIA CAA 二次开发详细教程(11) 程序的发布
1. 发布条件:
已安装了CATIA,版本不能低于开发使用的CAA版本。 CAA代码成果物“intel_a”文件中的所有文件。
1. 发布方法:
2. 将“intel_a”文件存放在要发布机器上,存放“intel_a”文件的路径最好不要有中文字符和空格。(例:E:\\VCINewFromExisting\\intel_a)
3. 点击 ”开始” –> ”所有程序” –> “CATIA P3” –> “Tools” –>” Environment Editor V5R18”
1. 点击 “确定”。
42
CATIA CAA 二次开发 详细教程
1. 选择”Environment” –> “New”
1. “Name” 栏为将要创建的桌面快捷方式的名称;在”Install Path” 栏中,CATIA的安装路径后输入”; E:\\VCINewFromExisting\\intel_a”,这是要发布的intel_a的存放路径;其他如图所选,采取默认设置。完成后点击”OK”。
1. 至此发布完成,在桌面上会生成一个名为”NewFromExisting”的CATIA类型图标。双击该图标,会启动CATIA,用户便可使用CATIA原所有功能和新发布的功能。
1. 与原CATIA图标集成发布方法: 设:
Catia的工作目录是 D:\\DS\\B18\\intel_a; 已开发插件的工作目录是D:\\MyAddin\\intel_a;
将D:\\MyAddin\\intel_a下这些文件复制到D:\\DS\\B18\\intel_a对应的位置,即可在运行Catia时候自动加载插件:
43
CATIA CAA 二次开发 详细教程
code \\ bin \\ *.dll; \\ code \\dictionary \\ *.dico; \\ code \\ productIC \\ *.script; \\ code \\ productIC \\ *.xml;
\\ resources \\ graphic \\ icons \\ normal \\ *.bmp; \\ resources \\ msgcatalog \\ *.CATNls; \\ resources \\ msgcatalog \\ *.CATRsc;
44
正在阅读:
CATIA CAA 二次开发 详细教程(5)添加一个点04-25
菏泽可行性分析报告婚恋交友网站案例,目录,范文,模板05-27
C语言程序设计试验八10-06
生命体征的评估习题及答案11-16
无机化学实验补充讲义(工科)03-29
无微不至的爱作文500字07-04
2012年感动重庆十大人物颁奖词及事迹之一Word 文档08-11
奇门遁甲八卦意向01-25
分析化学习题十01-24
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 添加
- 教程
- 开发
- 详细
- 一个
- CATIA
- CAA