PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

admin 发表于 2017-12-20 22:57:06 |阅读模式

admin 楼主

2017-12-20 22:57:06

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

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

x

8 x9 _8 H3 x5 w CATIA二次开发入门教程---18 创建一个点4 s$ w6 j6 N, ^/ N8 |$ J' R
4 O- ~4 Z* d& m# ?) z
QQ截图20171220225607.png # S1 i  ~# F1 l, {

% J$ o$ @- y% z: Y" O8 x! b) U% @& s3 W
[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory) u- j1 [" s. |- m" S; r2 r7 s
        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();
9 [: D- Q3 N5 U        CATDocument *pDoc = pEditor->GetDocument();
) ^$ q0 B) m5 }" J, p/ L! g/ ^9 m  I        CATIContainerOfDocument_var spConODocs = pDoc;" |! Y0 K# B8 ?/ p. u. M9 z( N
% j- d: _# F- V* G1 f4 J4 l: v
        CATIContainer*            _pContainer;                //Container
; m/ g2 L3 c% l& B5 t! ^        CATIGSMFactory_var        spGSMFactory;                //GSM工厂
1 l; `6 y% c4 s. r' c7 @7 p( t& H6 f$ u: j7 j3 [% j, V
        _pContainer = NULL;( F* G9 m: s% d! e8 T$ F
        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);
3 |! R2 E6 y, T        spGSMFactory = NULL_var;" e) H1 s) k8 {
        spGSMFactory = _pContainer;
& D/ q) d, W4 f  e        //设置点的坐标, h  f# B2 `9 x0 P: @4 a% K
        CATMathPoint _Point;
" Q/ Y9 y1 H% t( Z( |        _Point.SetCoord(10,10,10 );: n* E6 d& s, J/ B! E" X
        /////////////////////用以上得到的Point3D画点
  e- n5 J" W1 z/ a5 M* u        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点
3 h+ R9 G# T9 S! O5 u8 A5 @+ q        CATISpecObject_var                spSpecPoint1;
0 ?& z' s) k7 [* q; L! I; ]        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject7 A/ w0 ~2 r* w/ B
        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;) \4 |' }! q6 X% B+ m
        spSndPntObj->InsertInProceduralView();
$ v, G; x2 f% C2 \! |" L1 m6 p+ Y& l    spSpecPoint1->Update();! b  e) z; }* ]% q. K  r0 Y
        // Add your code here[/mw_shl_code]+ A; i2 L- N4 Z; A4 i) L7 c# e4 ^
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复1

admin 发表于 2017-12-22 11:04:14

admin 沙发

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
. N# v- w- W5 s4 O2 ~# F4 R+ e
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;

0 W* ?% g8 x( i# }' }
spPntObj->InsertInProceduralView();
3 d# O8 B1 a! c( T: q
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了