CAD注记层转到SDE Annotation Features(ArcEngine,C++实现)(转载)

CAD注记层转到SDE Annotation Features本文会提到两种方式,不过都是要添加一个element,所以,首先给出一个创建element的函数

复制代码
ITextElementPtr MakeTextElement(CString strText, double x, double y)
{
HRESULT hr;
ITextElementPtr ipTextElement(CLSID_TextElement);
hr = ipTextElement->put_ScaleText(VARIANT_TRUE);
hr = ipTextElement->put_Text(CComBSTR(strText));

IGroupSymbolElementPtr ipGroupSymEle = ipTextElement;
ipGroupSymEle->put_SymbolID(0);

IPointPtr ipPoint(CLSID_Point);
ipPoint->put_X(x);
ipPoint->put_Y(y);

IElementPtr ipElement = ipTextElement;
ipElement->put_Geometry(ipPoint);

return ipTextElement;
}
复制代码

第一种办法,通过IFDOGraphicsLayer添加Elements的方式实现,实现办法如下

复制代码
BOOL AddTextElementEx(CString strText, double x, double y)
{
HRESULT hr;
IFeatureWorkspacePtr ipFeatWorkspace = m_ipWorkspace;
if(ipFeatWorkspace == NULL)
return FALSE;
IFeatureClassPtr ipFeatureClass;
hr = ipFeatWorkspace->OpenFeatureClass(CComBSTR(_T("abc")),&ipFeatureClass);
IWorkspaceEditPtr ipWorkspaceEdit = m_ipWorkspace;
if(ipWorkspaceEdit==NULL)
return FALSE;

IDatasetPtr ipDataset(ipFeatureClass);
IFDOGraphicsLayerFactoryPtr ipFDOGLFactory(CLSID_FDOGraphicsLayerFactory);
IWorkspacePtr ipWs;
ipDataset->get_Workspace(&ipWs);
IFeatureWorkspacePtr ipFeatWs(ipWs);

IFeatureDatasetPtr ipFeatDataset;
ipFeatureClass->get_FeatureDataset(&ipFeatDataset);
ILayerPtr ipLayer;
BSTR bstr;
hr = ipDataset->get_Name(&bstr);
hr = ipFDOGLFactory->OpenGraphicsLayer(ipFeatWs,ipFeatDataset,bstr,&ipLayer);
 if(FAILED(hr))
        return FALSE;IFDOGraphicsLayerPtr ipFDOGLayer(ipLayer);        
    IElementCollectionPtr ipElementColl;
hr = ipElementColl.CreateInstance(CLSID_ElementCollection);
if(FAILED(hr)||ipElementColl==NULL)
return FALSE;

ITextElementPtr ipTextElement = MakeTextElement(strText,x,y);
hr = ipElementColl->Add((IElementPtr)ipTextElement,-1);
hr = ipFDOGLayer->BeginAddElements();
hr = ipFDOGLayer->DoAddElements(ipElementColl,0);
hr = ipFDOGLayer->EndAddElements();
return TRUE;
}
复制代码

 第二种方式,通过IAnnotationFeature来实现,实现代码如下

复制代码
BOOL AddTextElement(CString strText, double x, double y)
{
HRESULT hr;
IFeatureWorkspacePtr ipFeatWorkspace = m_ipWorkspace;
if(ipFeatWorkspace == NULL)
return FALSE;
IFeatureClassPtr ipFeatureClass;
hr = ipFeatWorkspace->OpenFeatureClass(CComBSTR(_T("abc")),&ipFeatureClass);
IWorkspaceEditPtr ipWorkspaceEdit = m_ipWorkspace;
if(ipWorkspaceEdit==NULL)
return FALSE;

hr = ipWorkspaceEdit->StartEditing(TRUE);
hr = ipWorkspaceEdit->StartEditOperation();
hr = ipWorkspaceEdit->EnableUndoRedo();

IElementPtr ipElement = MakeTextElement(strText,x , y);
IAnnotationFeaturePtr ipAnnotationFeature = ipFeature;
if(ipAnnotationFeature == NULL)
return FALSE;

hr=ipAnnotationFeature->put_Annotation(ipElement);

ipWorkspaceEdit->DisableUndoRedo();
ipWorkspaceEdit->StopEditOperation();
ipWorkspaceEdit->StopEditing(TRUE);

return TRUE;
}
复制代码

  这两种方法,经过实际测试都可以成功,在导入的时候还需要注意一下空间参考系的问题,需要对应上,特别要注意dwg中的数据是否正确,如果注记的坐标不在参考系范围内,会出现导入失败的现象,我就是因为这个低级的错误,纠结了两天。

  

参考资料:http://www.cnblogs.com/iswszheng/archive/2009/03/18/1415496.html

http://blog.sina.com.cn/s/blog_5432e0220100kzui.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值