CAD annotation layer to SDE annotation features (arcengine, C ++ implementation)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.