CATIA CAA 二次開發(fā) 詳細教程(5)添加一個點_第1頁
CATIA CAA 二次開發(fā) 詳細教程(5)添加一個點_第2頁
CATIA CAA 二次開發(fā) 詳細教程(5)添加一個點_第3頁
CATIA CAA 二次開發(fā) 詳細教程(5)添加一個點_第4頁
CATIA CAA 二次開發(fā) 詳細教程(5)添加一個點_第5頁
已閱讀5頁,還剩6頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

本文格式為Word版,下載可任意編輯——CATIACAA二次開發(fā)詳細教程(5)添加一個點CATIACAA二次開發(fā)詳細教程

CATIACAA二次開發(fā)詳細教程(5)添加一個點

在創(chuàng)立任何幾何對象之前,必需在激活的函數(shù)命令中添加以下代碼,:CATFrmEditor*pEditor=CATFrmEditor::GetCurrentEditor();if(pEditor==NULL){

printf(\}

CATDocument*pDoc=pEditor->GetDocument();CATIContainerOfDocument_varspConODocs=pDoc;CATIContainer*pSpecContainer=NULL;

HRESULThr=spConODocs->GetSpecContainer(pSpecContainer);if(spConODocs==NULL_var){

printf(\}

以上代碼的主要功能是獲取editor,thedocumentandthecontainer。CATIGSMFactory_varspGSMFactory=NULL_var;CATIPrtFactory_varspPrtFactory=NULL_var;CATICkeParmFactory_varspParmFactory=NULL_var;spGSMFactory=pSpecContainer;spPrtFactory=pSpecContainer;spParmFactory=pSpecContainer;

以上代碼設置工廠,在這基礎上你才可以造型,GSMFactory用于創(chuàng)立底層的幾何對象譬如點、線等。PrtFactory包含創(chuàng)立孔特征、拉伸特征實體等函數(shù)。ParmFactory包含設定參數(shù)的函數(shù)。

在以上的基礎上可以創(chuàng)立點了,步驟如下:(1)創(chuàng)立一個三維數(shù)組(x,y,z)定義點坐標。doubleCoords[3];Coords[0]=0;Coords[1]=0;Coords[2]=0;

(2)創(chuàng)立一個CATIGSMPoint并將其轉換為CATISpecObject

CATIGSMPoint_varspPoint1=spGSMFactory->CreatePoint(Coords);//Createsapoint

30

CATIACAA二次開發(fā)詳細教程

CATISpecObject_varspSpecPoint1=spPoint1;//CaststhepointasaCATISpecObject

(3)為了在CATIA顯示你創(chuàng)立的點,必需將其添加到視圖中。spSpecPoint1->Update();

CATIGSMProceduralView_varspPntObj=spSpecPoint1;spPntObj->InsertInProceduralView();所有的源代碼如下://.

//

CATStatusChangeRCMyCommand::Activate(CATCommand*iFromClient,CATNotification*iEvtDat)

{

CATFrmEditor*pEditor=CATFrmEditor::GetCurrentEditor();

if(pEditor==NULL){

printf(\r\

}

CATDocument*pDoc=pEditor->GetDocument();CATIContainerOfDocument_varspConODocs=pDoc;CATIContainer*pSpecContainer=NULL;

HRESULThr=spConODocs->GetSpecContainer(pSpecContainer);

if(spConODocs==NULL_var){

printf(\ofdocuments\

}

CATIGSMFactory_varspGSMFactory=NULL_var;CATIPrtFactory_varspPrtFactory=NULL_var;CATICkeParmFactory_varspParmFactory=NULL_var;spGSMFactory=pSpecContainer;spPrtFactory=pSpecContainer;spParmFactory=pSpecContainer;

31

CATIACAA二次開發(fā)詳細教程

doubleCoords[3];Coords[0]=0;Coords[1]=0;Coords[2]=0;

CATIGSMPoint_varspPoint1=spGSMFactory->CreatePoint(Coords);//Createsapoint

CATISpecObject_varspSpecPoint1=spPoint1;//CaststhepointasaCATISpecObject

spSpecPoint1->Update();

CATIGSMProceduralView_varspPntObj=spSpecPoint1;

spPntObj->InsertInProceduralView();

return(CATStatusChangeRCCompleted);}

CATIACAA二次開發(fā)詳細教程(6)創(chuàng)立一條線

初始的設定請參考上一講《CATIACAA二次開發(fā)詳細教程(5)添加一個點》。在此基礎上,創(chuàng)立線的步驟如下:

1)創(chuàng)立兩個點并將其轉換為CATISpecObjects。doubleCoords[3];Coords[0]=0;Coords[1]=0;Coords[2]=0;

CATIGSMPoint_varspPoint1=spGSMFactory->CreatePoint(Coords);CATISpecObject_varspSpecPoint1=

spPoint1;

Coords[0]=8;Coords[1]=6;Coords[2]=7;

CATIGSMPoint_varspPoint2=spGSMFactory->CreatePoint(Coords);CATISpecObject_varspSpecPoint2=spPoint2;

32

CATIACAA二次開發(fā)詳細教程

2)利用創(chuàng)立的點創(chuàng)立一條線,并將其轉換為CATISpecObjectCATISpecObject_varspSupport=NULL_var;

CATIGSMLinePtPt_varspLine1=spGSMFactory->CreateLine(spSpecPoint1,spSpecPoint2,spSupport);

CATISpecObject_varspSpecLine1=spLine1;3)更新創(chuàng)立的線,并將其添加到視圖中。spSpecLine1->Update();

CATIGSMProceduralView_varspCurObj=spLine1;spCurObj->InsertInProceduralView();

CATIACAA二次開發(fā)詳細教程(7)創(chuàng)立草圖Sketch

有兩種方式可以創(chuàng)立草圖:1)通過參考平面創(chuàng)立

首先獲取一個CATIPrtPart變量:

CATIPrtPart_varspPart(pIPrtContOnDocument->GetPart());pIPrtContOnDocument->Release();

有了CATIPrtPart變量就可以利用其方法GetReferencePlanes(),獲取參考平面

CATLISTV(CATISpecObject_var)spRefPlanes=spPart->GetReferencePlanes();

然后創(chuàng)立XYplane(spRefPlanes[1])

CATISketchFactory_varspSketchFactory(pSpecContainer);if(NULL_var==spSketchFactory)return(CATStatusChangeRCCompleted);

CATISketch_var

spSketch(spSketchFactory->CreateSketch(spRefPlanes[1]));

if(NULL_var==spSketch)return(CATStatusChangeRCCompleted);spSketch->OpenEdition();2)通過原點和兩個矢量方向

該方法是通過定義一個原點和兩個方向pH、pV進行創(chuàng)立。定義原點和方向:

doubleorigin[3]={0.0,0.0,10.0};doublex_dir[3]={1.0,0.0,0.0};

33

CATIACAA二次開發(fā)詳細教程

doubley_dir[3]={0.0,1.0,0.0};

CATISketchFactory_varspSketchFactory(pSpecContainer);if(NULL_var==spSketchFactory)return(CATStatusChangeRCCompleted);

CATISketch_var

spSketch(spSketchFactory->CreateSketch(origin,x_dir,y_dir));

if(NULL_var==spSketch)return(CATStatusChangeRCCompleted);spSketch->OpenEdition();

到這里,你已經創(chuàng)立了一個Sketch,你可以在上面創(chuàng)立任意的草圖了。創(chuàng)立好記住要將其關閉:spSketch->CloseEdition();

CATIACAA二次開發(fā)詳細教程(8)草圖上創(chuàng)立幾何圖形

在上一節(jié)的基礎上,開始創(chuàng)立草圖。首先創(chuàng)立草圖工廠:CATI2DWFFactory_varsketch2DFactory(spSketch);下面創(chuàng)立點:

CATI2DPoint_varspPt_bottom_left,spPt_bottom_right,spPt_top_right,spPt_top_left;

doublept_bottom_left[2]={10.,10.};doublept_bottom_right[2]={50.,10.};doublept_top_right[2]={50.,50.};doublept_top_left[2]={10.,50.};

spPt_bottom_left=sketch2DFactory->CreatePoint(pt_bottom_left);spPt_bottom_right=sketch2DFactory->CreatePoint(pt_bottom_right);spPt_top_right=sketch2DFactory->CreatePoint(pt_top_right);spPt_top_left=sketch2DFactory->CreatePoint(pt_top_left);開始創(chuàng)立線:

CATI2DLine_varspLine1,spLine2,spLine3,spLine4;spLine1=

sketch2DFactory->CreateLine(pt_bottom_left,pt_bottom_right);

spLine2=

sketch2DFactory->CreateLine(pt_bottom_right,pt_top_right);

spLine3=sketch2DFactory->CreateLine(pt_top_right,pt_top_left);spLine4=sketch2DFactory->CreateLine(pt_top_left,pt_bottom_left);將線連接起來:

CATI2DCurve_varspCurve1(spLine1);

34

CreateAssemble(joincurves,Mergedist,FALSE);

CATISpecObject_varspCurveAssy=CurveAssy;

spCurveAssy->Update();

CATIGSMProceduralView_varspCurObj=Curveassembly;

36

CATIACAA二次開發(fā)詳細教程

spCurObj->InsertInProceduralView();

CATIACAA二次開發(fā)詳細教程(10)文檔操作方法創(chuàng)立加載保存

一、創(chuàng)立(Createthenewdocument)

CATDocument*pDoc=NULL;

rc=CATDocumentServices::New(\if(NULL!=pDoc){

coutGetDocument();if(NULL!=pDoc){

coutQueryInterface(IID_CATInit,(void**)if(FAILED(rc)){

coutGetRootContainer(idCATIContainer);

if(NULL==piRootContainer){

coutCATIACAA二次開發(fā)詳細教程

edasasecondparameter.Inthisusecase,wepassthestoragepathnameanddocumentnameasanargumenttotheprogram.

5.2保存

rc=CATDocumentServices::Save(*pDoc);if(SUCCEEDED(rc)){

cout〞所有程序〞–>“CATIAP3〞–>“Tools〞–>〞EnvironmentEditorV5R18〞

1.點擊“確定〞。

42

CATIACAA二次開發(fā)詳細教程

1.選擇〞

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論