查看: 3853|回复: 1

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

[复制链接]

4

主题

3

回帖

44

积分

管理员

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

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

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

×
, t! e4 S9 o( u
CATIA二次开发入门教程---18 创建一个点/ b8 m. t. t0 Z  Y

5 s/ p- U' n8 p& [% U8 r QQ截图20171220225607.png + m! @% s1 o! q$ j- |+ \# ^0 z& g

" I1 L; F/ Y/ R9 |. b" p  o9 R& q2 m4 A3 I
[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory
- ^/ L5 ]/ p; T! x        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();' n9 Y) r* w4 b) [" @" `
        CATDocument *pDoc = pEditor->GetDocument();9 w7 t5 k$ Z3 \
        CATIContainerOfDocument_var spConODocs = pDoc;
1 ?; j3 n& a3 ~" D5 `" Y) o
. a$ b; q, c4 i, y        CATIContainer*            _pContainer;                //Container
' x$ }: J% m: z( u9 o+ }! a: f1 @( B        CATIGSMFactory_var        spGSMFactory;                //GSM工厂1 }' [+ ^# ~$ l7 ?
9 Z- |3 D7 _- T
        _pContainer = NULL;
( Y0 w6 [5 y/ t2 M' e8 F        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);2 x4 \/ B/ h5 L- G6 t# w7 V
        spGSMFactory = NULL_var;
* O5 k2 T  D/ R+ f        spGSMFactory = _pContainer;
. `4 I% c0 J6 A/ B: t: [) I4 z" h) I        //设置点的坐标
: {3 T  I0 n7 ?& a! u        CATMathPoint _Point;9 X: L3 f" K( }, w
        _Point.SetCoord(10,10,10 );; P7 \/ I8 C& J0 J* N; }9 V
        /////////////////////用以上得到的Point3D画点, h5 j) Q/ r/ X$ f4 H/ M! C/ L' N
        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点
4 [' e* _+ w" s8 }- u! T        CATISpecObject_var                spSpecPoint1;
" M9 \+ M* l' @/ L0 z* Z4 [        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject6 a( M' y& T$ T- N
        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;
) y. |% ^9 B) m9 g8 G7 Q1 v8 Y        spSndPntObj->InsertInProceduralView();
3 w& k- U' v  C' H; ^    spSpecPoint1->Update();
" E$ L$ v! g: |! j" [        // Add your code here[/mw_shl_code]: l4 n7 ^" p8 u9 z7 C
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

4

主题

3

回帖

44

积分

管理员

积分
44
 楼主| 发表于 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
5 Z( B0 n% D- r
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
: K3 y; k& G) O+ _9 r9 V7 Y4 Y
spPntObj->InsertInProceduralView();
5 \! C  |# E# W
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 1 反对 0

使用道具 举报

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

本版积分规则

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