查看: 3931|回复: 1

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

[复制链接]

6

主题

4

回帖

60

积分

管理员

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

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

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

×

5 ~7 b+ |* r( r4 ] CATIA二次开发入门教程---18 创建一个点
6 C% j% D7 H# j9 W1 r2 H* j" G  F  {$ G
QQ截图20171220225607.png
7 S  w% @. f6 a# g$ B$ s! d3 e) G7 }! _& p5 l& V8 u

6 m3 ]4 U" k. H  W6 S[mw_shl_code=c,true]////////获得Editor、Document、Container、设置GSMFactory
# s4 i% _7 ^: z6 J: O        CATFrmEditor* pEditor = CATFrmEditor::GeTCurrentEditor();, M( A% x' {0 S, a, `
        CATDocument *pDoc = pEditor->GetDocument();
* r7 t! `4 [: l9 t( Q$ D        CATIContainerOfDocument_var spConODocs = pDoc;, k! M  n% o: J+ h' x: Y; U% l+ c

7 v1 _) g1 @" Y1 U        CATIContainer*            _pContainer;                //Container
5 F# C! ?4 J- Y, z+ G$ p& c        CATIGSMFactory_var        spGSMFactory;                //GSM工厂
3 n. f2 ]  b( I% V
; }4 w5 s( m) y  V) j1 H2 B        _pContainer = NULL;
/ a! M: Z# f& E        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);3 H+ \; Y- N/ {- p) {
        spGSMFactory = NULL_var;
9 B4 V* s" \! T! t8 r# f        spGSMFactory = _pContainer;
  n2 x% q0 b) `- B1 U7 ^- ^        //设置点的坐标
/ `/ E7 H/ p4 k8 {0 e6 v; J# y9 g4 o        CATMathPoint _Point;5 w' H4 c$ Z6 f5 n0 o! g/ j
        _Point.SetCoord(10,10,10 );: f6 B1 P3 G, R$ M4 r
        /////////////////////用以上得到的Point3D画点/ P* I$ l! U6 Z) b
        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点
0 b2 _5 t0 `4 f0 z& Q! V        CATISpecObject_var                spSpecPoint1;
2 ?% s8 D; r- ?5 b# F& [# }# U! F        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject! U2 X) [# }! I- V
        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;" z9 p. l: Y& g! D2 I
        spSndPntObj->InsertInProceduralView();
; m  v6 ~: o) y$ h5 x6 g% O6 |    spSpecPoint1->Update();
0 k8 b& |1 r  V: o/ j, Z        // Add your code here[/mw_shl_code]
' z: v; W6 i0 e/ j7 d$ `- t+ X$ _: Y
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

6

主题

4

回帖

60

积分

管理员

积分
60
 楼主| 发表于 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
+ o' `: J7 k' k
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject
(3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
7 h7 _. z2 i& y0 t- W8 O6 u4 f
spPntObj->InsertInProceduralView();

& G( a% t7 @3 I' }: E, m
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 1 反对 0

使用道具 举报

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

本版积分规则

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