查看: 3893|回复: 1

[原创] CATIA二次开发入门教程---18 创建一个点

[复制链接]

6

主题

4

回帖

60

积分

管理员

积分
60
发表于 2017-12-20 22:57:06 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

×

  X" e3 s2 |* N6 @ CATIA二次开发入门教程---18 创建一个点, P' C; s  S! J( L- O

5 A1 T- q$ I$ I$ m9 i) o, Q  I QQ截图20171220225607.png
; e5 m; H; d- ]+ U" L& n. V  [# o! r$ o- B7 G
: P& K. n; `, V5 c  u3 F
[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory( e# l% O8 l* F" d
        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();
/ }- e2 A% K# D; b7 B; u; e        CATDocument *pDoc = pEditor->GetDocument();3 {  J2 w: @( G- R# V: @
        CATIContainerOfDocument_var spConODocs = pDoc;
3 `  K' u/ p' @1 }; O; C+ u6 Q# P4 e3 g# w2 _
        CATIContainer*            _pContainer;                //Container7 M' L9 Q! d1 P9 n' }
        CATIGSMFactory_var        spGSMFactory;                //GSM工厂
" @6 @+ C2 s% [  Q. X4 w9 ?: H$ p8 \. @
        _pContainer = NULL;: z9 p' C# y# H/ d1 C
        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);
  g, S+ r5 `, d7 Y% Y+ ~        spGSMFactory = NULL_var;
' ^+ T: G1 A: O' z; c. \; Y        spGSMFactory = _pContainer;
, f! Z1 D; n4 ^( U# V0 \) C6 o6 I  F, l        //设置点的坐标! g) P+ |- L8 `1 }9 y
        CATMathPoint _Point;
: s, J& L, w* Y7 e, v! n        _Point.SetCoord(10,10,10 );  F6 v- @% K5 j5 F2 ~9 o
        /////////////////////用以上得到的Point3D画点
+ W' P  _2 Z4 y) [: i        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点
4 H' d% _* M4 ^0 {7 `5 m        CATISpecObject_var                spSpecPoint1;
8 N1 j) P+ W- j, v7 }. a        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject
% A. Z2 x* E! s& P) I! ]0 W        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;& \' U* U) ~/ w
        spSndPntObj->InsertInProceduralView();
* F  Y0 g; j8 Z# q2 u9 R6 L8 f    spSpecPoint1->Update();
% _9 F1 ~; @% h- l        // Add your code here[/mw_shl_code]! k" E+ o, N  H" ]- ?* B
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

6

主题

4

回帖

60

积分

管理员

积分
60
 楼主| 发表于 2017-12-22 11:04:14 | 显示全部楼层
在创建任何几何对象之前,必须在激活的函数命令中添加以下代码,:
CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
if(pEditor == NULL)
{
   printf("error getting the FRMeditor");
}
CATDocument *pDoc = pEditor->GetDocument();
CATIContainerOfDocument_var spConODocs = pDoc;
CATIContainer* pSpecContainer = NULL;
HRESULT hr =spConODocs->GetSpecContainer(pSpecContainer);
if(spConODocs == NULL_var)
{
   printf("error getting thecontainer of documents");
}
以上代码的主要功能是获取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

; g6 a& `  Q1 |6 u
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
(3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
$ s+ X: i8 Z1 [- h; E
spPntObj->InsertInProceduralView();

! F2 Z5 Z# j; O
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部