马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
大家好,第一次发帖子,请多多指教
现在我在做的程序是快速生成工程图图框,我的方法是直接用程序后台复制模板中的图框和文字 其中参考了这篇帖子,起了很大作用
https://www.icax.org/thread-209734-1-1.html
但是现在遇到的问题是目前只能拷贝源CATDrawing文件中的线框,但是不能将里面的文字粘贴进去,这个问题已经困扰了我好久,要交任务了这个问题还是没有解决,希望论坛里的大神伸伸援助之手啊,以下是我的主要代码
CATISheet_var spSorSheet=NULL_var;//被复制的sheet
spSorSheet = piDrawing->GetCurrentSheet();
CATIView_var spBgView = spSorSheet->GetBackgroundView();
CATIDescendants_var spDesc = spBgView;
CATListValCATISpecObject_var lineList;
int a=spDesc->GetNumberOfChildren();
spDesc->GetDirectChildren ("CATBaseUnknown",lineList);//CATIDrwText IDMLine2D CATBaseUnknown CATIDftText CATIDrwDressUp
//CATListValCATISpecObject_var TextList;
//spDesc->GetDirectChildren ("CATIDrwText",TextList);//CATIDrwText
ListOfVarBaseUnknown listFromCopy;
IDMLine2D_var xian = NULL_var;
CATIDrwDressUp_var zi=NULL_var;
CATIDrwDressUp_var zi1=NULL_var;
for (int ii=1; ii<=lineList.Size(); ii++)
{
if (SUCCEEDED(lineList[ii]->QueryInterface(IID_IDMLine2D, (void **)&xian)))
{
listFromCopy.Append((CATISpecObject *)lineList[ii]);
}
if (SUCCEEDED(lineList[ii]->QueryInterface(IID_CATIDrwDressUp, (void **)&zi)))
{
zi1=zi;
listFromCopy.Append((CATISpecObject *)lineList[ii]);
}
}
CATListValCATBaseUnknown_var* oTextList =NULL;
if (zi1!=NULL_var)
{
if (SUCCEEDED(zi1->GetTextList(&oTextList)))
{
cout<<"文字个数"<<oTextList->Size()<<endl;
}
}
for (int ii=1; ii<=oTextList->Size(); ii++)
{
CATISpecObject_var zier=(*oTextList)[ii];
listFromCopy.Append((CATISpecObject *)zier);
CATUnicodeString bu1=CATIAlias_var((CATISpecObject *)zier)->GetAlias();
cout<<bu1<<endl;
}
CATUnicodeString p="";
CATUnicodeString o="";
for (int ii=1; ii<=lineList.Size(); ii++)
{
CATUnicodeString b=lineList[ii]->GetType();
//CATUnicodeString b=CATIAlias_var((CATISpecObject *)lineList[ii])->GetAlias();
if (o!=b)
{
o=b;
cout<<"TYPE:"<<o<<endl;
}
CATUnicodeString bu=CATIAlias_var((CATISpecObject *)lineList[ii])->GetAlias();
if (p!=bu)
{
p=bu;
cout<<p<<endl;
}
}
//for (int ii=1; ii<=TextList.Size(); ii++)
//{
//
// listFromCopy.Append((CATISpecObject *)TextList[ii]);
//
//}
cout<<listFromCopy.Size()<<"个被复制对象"<<endl;
//CATISpecObject *piLine1 = lineList[1];
//listFromCopy.Append(piLine1);
//piLine1 -> Release();
//piLine1 = NULL;
CATICutAndPastable *piCutAndPastableOnSourceCont = NULL;
CATIContainer_var spSocCon=CATISpecObject_var(spSorSheet)->GetFeatContainer();
HRESULT rc = spSocCon -> QueryInterface(IID_CATICutAndPastable,
(void**) &piCutAndPastableOnSourceCont);
CATLISTP(CATFormat) listFmt = piCutAndPastableOnSourceCont->ListPasteFormats();
int cFmt = listFmt.Size();
for (int i = 1; i <= cFmt; i++){
cout << listFmt->Name() << endl;
}
if (FAILED(rc))
{
cout << "ERROR in QueryInterface on CATICutAndPastable on Source Container" << endl << flush;
return;
}
ListOfVarBaseUnknown newListToCopy;
int result = NULL;
if (piCutAndPastableOnSourceCont == NULL)
{
cout<<"piCutAndPastableOnSourceCont == NULL"<<endl;
}
IdFormat MyFmy = "CATDrwCont";
const CATFormat* pFmt = CATFormat::GetRegisteredFormat(MyFmy);
cout<<listFromCopy.Size()<<"要复制之前"<<endl;
result = piCutAndPastableOnSourceCont -> BoundaryExtract (newListToCopy,
&listFromCopy,
pFmt);//跟踪到这里 newListToCopy里面还包含有文字的内容
if (result==0)
{
cout<<"no thing to extract"<<endl;
}
if (NULL != result)
{
cout << "BoundaryExtract from Source Container succeeded0" << endl << flush;
cout << "Number of objects extracted = " << newListToCopy.Size() << endl << flush;
cout << CATIAlias_var(newListToCopy[730])->GetAlias() << endl;
cout << CATIAlias_var(newListToCopy[731])->GetAlias() << endl;
}
else
{
cout << "BoundaryExtract failed" << endl << flush;
piCutAndPastableOnSourceCont -> Release();
return;
}
VarBaseUnknown pExtractedList;
pExtractedList = piCutAndPastableOnSourceCont -> Extract (newListToCopy,
pFmt);
piCutAndPastableOnSourceCont -> Release();
piCutAndPastableOnSourceCont = NULL;
CATICutAndPastable *piCutAndPastableOnExtractedList = NULL;
rc = pExtractedList -> QueryInterface(IID_CATICutAndPastable,
(void**) &piCutAndPastableOnExtractedList);
if (FAILED(rc))
{
cout << "ERROR in QueryInterface on CATICutAndPastable on Target Container" << endl << flush;
return;
}
ListOfVarBaseUnknown extractedListToCopy;
result = NULL;
result = piCutAndPastableOnExtractedList -> BoundaryExtract (extractedListToCopy,
NULL,
pFmt);//从这一步就取出来里面的线框而没有文字了
cout << "2" << endl << flush;
if (NULL != result)
{
cout << "BoundaryExtract from Clipboard succeeded" << endl << flush;
cout << "Number of objects extracted = " << extractedListToCopy.Size() << endl << flush;
cout << CATIAlias_var(extractedListToCopy[1])->GetAlias() << endl;
cout << CATIAlias_var(extractedListToCopy[2])->GetAlias() << endl;
}
else
{
cout << "BoundaryExtract failed" << endl << flush;
return;
}
CATICutAndPastable *piCutAndPastableOnTargetCont = NULL;
CATIContainer_var spSocConTar=CATISpecObject_var(spSheet)->GetFeatContainer();
rc = spSocConTar -> QueryInterface(IID_CATICutAndPastable,
(void**) &piCutAndPastableOnTargetCont);
if (FAILED(rc))
{
cout << "ERROR in QueryInterface on CATICutAndPastable on Source Container" << endl << flush;
return;
}
ListOfVarBaseUnknown listTargetObjects ;
listTargetObjects.Append(spSheet);
ListOfVarBaseUnknown listPastedObjects = piCutAndPastableOnTargetCont -> Paste (extractedListToCopy,
&listTargetObjects,
pFmt);
这是源图纸的内容
这是程序复制粘贴后的效果 文字没有被粘贴过来
|