查看: 4012|回复: 1

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

[复制链接]

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

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

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

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

×
8 V# F' L9 x3 P( v, H9 G8 m: F0 c% n# p
CATIA二次开发入门教程---18 创建一个点
: d% q, g) C$ q
# X" N) g4 t- Q6 q( S; t+ X QQ截图20171220225607.png
/ T- f$ G6 d- }' u) U" \$ b
% l% f$ D9 N6 }, f6 w
! m; Y4 w0 h: W) y4 Y[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory% ~2 G4 h1 y$ h" x5 h/ G
        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();
( @1 F7 p8 k  F; T# _# G        CATDocument *pDoc = pEditor->GetDocument();% E$ T. f2 i5 {7 M3 [" U
        CATIContainerOfDocument_var spConODocs = pDoc;
# J8 ^" {1 g5 c% K/ i! N& d7 @0 O0 ?  W7 C  I
        CATIContainer*            _pContainer;                //Container
. q3 k% m' d+ ]7 J% z! ]! ~        CATIGSMFactory_var        spGSMFactory;                //GSM工厂
; N1 |" g9 A$ s8 y/ W4 W, S2 Q
        _pContainer = NULL;' ?" }9 U1 j) ^3 p8 Q( s
        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);
, V& \7 ]9 l5 X5 L- F! Y$ A: I8 b5 Q        spGSMFactory = NULL_var;0 J  h. i. L) _6 V
        spGSMFactory = _pContainer;
3 n0 c! d3 h4 K. d. S7 Y) h        //设置点的坐标! ]* y) [0 D: c. `9 `2 l% K; x
        CATMathPoint _Point;2 G1 r. U$ W4 t; ]
        _Point.SetCoord(10,10,10 );
' B: E6 t/ X5 G        /////////////////////用以上得到的Point3D画点
" e1 Z3 F, h4 l+ E        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点9 c. w- ~! L# k9 c& y+ R
        CATISpecObject_var                spSpecPoint1;3 _: _) Y6 |  X- d7 z2 E0 a1 n
        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject8 Q. m+ g+ R  P9 ?
        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;9 E, g7 D. E8 w; y- ^
        spSndPntObj->InsertInProceduralView();
) Z3 k, p- k5 G& L8 j0 W1 w) ~! J    spSpecPoint1->Update();
% B+ S' ^: S, [* Z3 j) y        // Add your code here[/mw_shl_code]5 `5 J" E! J0 \% F, L8 b" z
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

积分
82278
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
0 F' V8 s/ J' b! S
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
(3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
% v" b0 X9 P! Z$ ?
spPntObj->InsertInProceduralView();

; k: v$ ?7 [2 m! p! d% [$ [( @% m+ k
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复 支持 1 反对 0

使用道具 举报

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

本版积分规则

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