PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2017-12-20 22:57:06

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

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

x

) m4 \0 {+ {8 @ CATIA二次开发入门教程---18 创建一个点" w6 B% z1 A  F$ @" B! B" w
4 Q5 Z2 J; P  w0 K: r6 j
QQ截图20171220225607.png
) t- H0 U  X) J/ P1 N
/ n7 G$ k  h) l  _! J% [! k! h# H0 |6 p- h  f8 e7 W1 E" z6 o, R
[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory
( m/ i# Y1 K3 A        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();" v, x2 D7 t& A& h8 V! i0 d+ a' ~
        CATDocument *pDoc = pEditor->GetDocument();
, v- W9 L# r4 y$ n        CATIContainerOfDocument_var spConODocs = pDoc;
4 M2 A/ S$ C4 ?+ l8 g; k/ L# D% f6 [; w; \2 S2 U# A6 v; A8 c
        CATIContainer*            _pContainer;                //Container8 b/ m2 r, ]6 c1 Y; t
        CATIGSMFactory_var        spGSMFactory;                //GSM工厂
  P7 Q; x; i7 D, T
# {8 ~! U. L2 B2 `( Y2 ~7 e3 _        _pContainer = NULL;' ^# M3 v9 B3 B6 j; A4 s- E, Y; {
        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);  Y  k& o0 y- I( R
        spGSMFactory = NULL_var;5 ~. S9 a- P3 Y6 ?6 ], H
        spGSMFactory = _pContainer;
& z5 g+ d: x7 J. u1 S. h        //设置点的坐标0 s) y: C$ b% p' s  |8 x
        CATMathPoint _Point;; P; Z4 _6 f6 i& ~; a  J
        _Point.SetCoord(10,10,10 );
1 _( }+ [" a1 e9 ?& a0 ~: ?4 b        /////////////////////用以上得到的Point3D画点$ {9 W2 a' B2 X  n3 p
        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点
2 }7 ^& p* h  O* t$ r- F        CATISpecObject_var                spSpecPoint1;
1 E1 Q8 C8 A; ]8 N, T3 F        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject
; D" Q/ i2 `8 d6 @  \        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;; H$ j, \) O# B, M% B
        spSndPntObj->InsertInProceduralView();2 v3 ~$ n+ R3 B7 D- r
    spSpecPoint1->Update();
1 G4 U$ G1 ~" b0 {, o7 U8 R        // Add your code here[/mw_shl_code]/ D  S4 S! V& c0 A( m9 a* v, J. P
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 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
" O2 b: }) U. G9 a) O
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
2 X' y7 |) q+ H6 S" V
spPntObj->InsertInProceduralView();
7 @" c; r  L+ `  Y2 Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了