CAD annotation layer to SDE annotation features this article will mention two methods, but all are to add an element, so first, give a function to create an 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;
}
The first method is to add elements through ifdographicslayer. The implementation method is as follows:
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;
HR = Ipdataset -> Get_name ( & BSTR );
HR = Ipfdoglfactory -> Opengraphicslayer (ipfeatws, ipfeatdataset, BSTR, & IPlayer );
If (Failed (HR ))
ReturnFalse;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;
}
The second method is implemented through iannotationfeature.CodeAs follows:
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;
}
The two methods can be successfully tested. During the import, you must pay attention to the space reference system problem. In this case, pay special attention to the correct data in DWG, if the coordinates of the annotation are not within the reference system, the import may fail. I am entangled for two days due to this low-level error.
References: http://www.cnblogs.com/iswszheng/archive/2009/03/18/1415496.html
Http://blog.sina.com.cn/s/blog_5432e0220100kzui.html