CATIA CAA 二次开发详细教程(10) 文档操作方法 创建 加载 保存 下载本文

内容发布更新时间 : 2024/5/2 14:25:47星期一 下面是文章的全部内容请认真阅读。

CATIA CAA 二次开发详细教程(10) 文档操作方法 创建 加载 保存

一、创建(Create the new document)

CATDocument* pDoc = NULL;

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

cout << \ } else {

cout << \ return 2; }

Now that the session is opened, you can create a new document using the New static method of CATDocumentServices. This method creates a document and initializes it, allowing it to be loaded and stored and making it editable. In this use case, a pre-defined document type, \the name that appears when performing a File/New operation. It is not the file extension, which, in this case, is \

二、打开(Load the document)

CATDocument *pDoc = NULL;

rc = CATDocumentServices::Open(argv[1], pDoc);

if (SUCCEEDED(rc) && (NULL != pDoc)) {

cout << \ } else {

cout << \ return 2; }

Now that the session is opened, you can load an existing document using the Open static method of CATDocumentServices. This method needs, as a first parameter, the entire storage path name and document name of the existing document that we want to load into the session. In this use case, we enter this information as an argument to the program. The second parameter of the Open method returns a CATDocument pointer to the document it has loaded.

Once the document exists in the session, you can work with objects within it, using specific interfaces external to the ObjectModelerBase framework.

三、获取当前文档

CATFrmEditor * pEditor = GetEditor(); if (NULL != pEditor )

{

} else {

cout << \ return 1; }

CATDocument *pDoc = pEditor->GetDocument(); if (NULL != pDoc) {

cout << \ } else {

cout << \ return 2; }

cout << \

四、提取根容器(Retrieving the Document Root Container)

CATInit *piInitOnDoc = NULL;

rc = pDoc -> QueryInterface (IID_CATInit, (void**) &piInitOnDoc); if (FAILED(rc)) {

cout << \ return 3; }

const CATIdent idCATIContainer = \ CATIContainer *piRootContainer = NULL;

piRootContainer = (CATIContainer*) piInitOnDoc -> GetRootContainer(idCATIContainer); if (NULL == piRootContainer) {

cout << \ return 4; }

The document root container is retrieved using the CATInit::GetRootContainer method. The CATIContainer handle retrieved through GetRootContainer will be necessary whenever you want to create or manipulate objects in the document.

五、保存文档(Save the Document) 5.1 另存

rc = CATDocumentServices::SaveAs (*pDoc, argv[1]); if (SUCCEEDED(rc)) {

cout << \ } else

{

cout << \ return 5; }

To save the new document, use the SaveAs static method of CATDocumentServices. This method takes the pointer to the document created by New as a first parameter, and the storage path name and document name under which the document is to be stored as a second parameter. In this use case, we pass the storage path name and document name as an argument to the program.

5.2 保存

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

cout << \ } else {

cout << \ return 3; }

To save the new document under the same name, use the Save static method of

CATDocumentServices. This method takes the CATDocument pointer to the document

as the only parameter.

六、删除(Remove the document)

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

cout << \ } else {

cout << \ return 6; }

If you ever needed to re-open the document during this same session, it would then be necessary to also remove it from the session after having saved it. Otherwise, you need not worry about it since deleting the session will automatically remove the document as well. To remove the document, you should use the Remove static method of CATDocumentServices.

七、按指定文档格式保存(Exporting a Document Format Type)

7.1 Defining the New Document Format Type