CAD註記層轉到SDE Annotation Features(ArcEngine,C++實現)

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.