• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

CAD注记层转到SDEAnnotationFeatures(ArcEngine,C++实现)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#通过HTTP代理访问Socket来获取邮件发布时间:2022-07-13
下一篇:
【UE4C++】UGameplayStatics源代码发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap