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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x
6 B' G! A& x" E& d3 \7 B
CATIA二次开发入门教程---18 创建一个点8 v1 {% y( C' F! j" l0 m  p9 y
6 x, p, Q# E4 e5 B6 x
QQ截图20171220225607.png ' e8 T2 y- a$ z  m

  @3 I1 Z* F3 t" C9 k  ]
# k. @( x3 `4 [7 p4 W5 ]# J[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory- c- v; n$ A8 E. x/ ]% p
        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();3 h/ P9 v/ X9 Y
        CATDocument *pDoc = pEditor->GetDocument();
5 I2 i  ^2 r# s% G& g        CATIContainerOfDocument_var spConODocs = pDoc;
9 F) z0 y9 g) D( D- p2 [! F9 {# ^& v3 k! ?4 a: o( T
        CATIContainer*            _pContainer;                //Container7 ]4 h4 M1 ?, N; O% H9 r
        CATIGSMFactory_var        spGSMFactory;                //GSM工厂
& k7 m2 ~9 e& U/ a* ]' r) V
, E' ~( L9 \$ t- s1 W+ a        _pContainer = NULL;
) ^9 t  v& x: H' @5 d( z        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);9 X3 S+ }" A8 S. W: h5 W6 M
        spGSMFactory = NULL_var;2 t/ l' p- g( V
        spGSMFactory = _pContainer;
3 m) r6 j. D0 p3 |& g0 ^        //设置点的坐标
2 Z' r0 e" W7 J; \' |8 I        CATMathPoint _Point;0 k4 h4 P8 M3 |6 E7 s7 {
        _Point.SetCoord(10,10,10 );  w  B* C6 F' F. q) M
        /////////////////////用以上得到的Point3D画点
! h1 A/ ^8 i; n% z        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点5 L# r) Z" k9 j3 B# H8 R
        CATISpecObject_var                spSpecPoint1;6 E$ Y# M+ N: n# `; z& i7 {
        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject, z# v' o  p  _+ D( f- g
        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;8 q( B. V0 n) n, C3 m' Y
        spSndPntObj->InsertInProceduralView();+ i! j7 x7 A7 W, i6 z
    spSpecPoint1->Update();
5 Z& B) _( V+ W7 I# V, w" |2 r% x        // Add your code here[/mw_shl_code]' J. B; e$ w1 L
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复1

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
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
' \- s8 u7 p- H: |5 Q# q% H  N# K
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
3 o! R8 ~2 w2 {% [7 h
spPntObj->InsertInProceduralView();
9 C$ [* f5 ?4 k
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了