查看: 4055|回复: 1

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

[复制链接]

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

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

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

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

×
+ L7 H0 a! G; }
CATIA二次开发入门教程---18 创建一个点
( w' J5 a2 b3 N- V7 O' h" k2 ]4 u$ R
QQ截图20171220225607.png
' q. B. T5 Y5 O! a- Q, s
& {7 H" o# i+ K! @2 ~  k% C; X! v7 ~- p- w( U
[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory0 E% t8 r, w) ~7 K
        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();
; l8 n3 K0 N% A5 w" M. [2 k% y        CATDocument *pDoc = pEditor->GetDocument();
# t) G+ W+ d. i        CATIContainerOfDocument_var spConODocs = pDoc;  Y8 v1 w; d/ s4 J1 }

5 ]# f4 y% E! o# z. f7 |: _+ C0 E        CATIContainer*            _pContainer;                //Container) b  E6 _& n" p3 H3 w
        CATIGSMFactory_var        spGSMFactory;                //GSM工厂
, f' E+ v5 |! Q5 Q9 }+ F
& I! g0 D- ~! ]2 l1 p3 @        _pContainer = NULL;/ o) u( I) ^% U& O# O
        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);
5 J5 V) h2 n5 f( i7 N0 X        spGSMFactory = NULL_var;; D  Y: ]# T- U' U
        spGSMFactory = _pContainer;
6 @$ b$ m1 c' G# B7 v0 t; P' a% Y        //设置点的坐标
  h6 }% o( ^% ]* Y, C7 G' h        CATMathPoint _Point;: q3 \: j8 ~! q' ]
        _Point.SetCoord(10,10,10 );
) _- U; m+ g' I# e7 R6 Y        /////////////////////用以上得到的Point3D画点
+ U; ~8 P& P( \- |5 Q* {2 L; p) u        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点
" R* r  o8 q  J0 i" B$ J        CATISpecObject_var                spSpecPoint1;6 n' }& c9 z1 L4 a( f
        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject1 q* ]  P! r3 t+ X' M7 G) f
        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;
1 c: X" x1 ~* h3 u, x        spSndPntObj->InsertInProceduralView();
+ L4 r/ R4 \! \% J9 F    spSpecPoint1->Update();
/ T8 I5 I( B& ]" y        // Add your code here[/mw_shl_code]7 ~" D- ]/ K0 Z0 I& r  e# m
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

积分
82278
QQ
 楼主| 发表于 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

6 \8 |7 a# E/ U& W: g- I- X7 P
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
(3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
' e/ h0 j1 p. W4 G- x
spPntObj->InsertInProceduralView();
' m$ Y+ |% ]/ x4 L- k
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复 支持 1 反对 0

使用道具 举报

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

本版积分规则

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