PLM之家PLMHome-工业软件践行者

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

[复制链接]

2017-12-22 11:04:14 3750 1

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x

7 @9 i9 A. }2 O CATIA二次开发入门教程---18 创建一个点, v6 \$ t* ^. v+ i) i3 D
/ o) E# L2 Z7 @( o# w
QQ截图20171220225607.png   X3 W; i7 D0 j' X) |6 h8 P/ e
' y8 Z1 r; \5 E8 p: Y0 B6 [; |0 Z

! h' `% M- C6 d[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory% Z) z, B" ?* }- J9 s3 c
        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();, N8 j8 w) H+ \5 Z/ S$ _2 M
        CATDocument *pDoc = pEditor->GetDocument();5 e7 m* m! C6 m! n% p
        CATIContainerOfDocument_var spConODocs = pDoc;2 h( [' S3 X/ \1 h: e9 s
' A) D) A& u3 h( o
        CATIContainer*            _pContainer;                //Container: g" g( K/ L& q/ }8 H  D
        CATIGSMFactory_var        spGSMFactory;                //GSM工厂& z' M, }" d" v6 G9 C* b) u9 V
6 j' K2 s# q# Z# D* Q4 ]( \& g
        _pContainer = NULL;
5 v; \7 J7 p8 P+ u, K        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);7 O! V: r2 T2 Z
        spGSMFactory = NULL_var;* [5 c  ?3 _$ t$ W3 p7 ?* I
        spGSMFactory = _pContainer;; s' U0 u" D% A6 Z9 [8 X
        //设置点的坐标! f4 b4 `/ ~% _% }# j
        CATMathPoint _Point;
; b% Z* I1 b; S. Y  T- ~% g$ d        _Point.SetCoord(10,10,10 );& ?: h& H5 ^8 @
        /////////////////////用以上得到的Point3D画点8 N# T2 c  F/ |
        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点
$ h( c! [/ G" |) O% q8 z' J        CATISpecObject_var                spSpecPoint1;, m0 a6 `% U7 R. k  `* x
        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject
* v, T! t- A. D/ l6 n" a1 Z0 |        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;
( r8 q% g* }0 u        spSndPntObj->InsertInProceduralView();+ l" N/ W2 j! a9 Y/ N% @
    spSpecPoint1->Update();  P, [' P1 N/ J) R6 f/ ~
        // Add your code here[/mw_shl_code]. q+ I; b& C, Z
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复1

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82172
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

$ \; T  z2 `: e# x8 k. i' @5 x
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
3 a# l& `  [# L/ h) `$ }
spPntObj->InsertInProceduralView();

2 y7 H  d8 p- X- ~% E- a7 h$ Y2 U
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复 支持 反对

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了