by Daniel Du
In map 3D, you can use the Create from Geometry command to convert AutoCAD entities into FDO features in map 3D, such as converting AutoCAD polyline to FDO linear features.
For AutoCAD polyline that contain only lines, after the FDO feature is turned, it is a Mgcurvestring object and contains only one linearsegment.
If an arc arc is included in AutoCAD Polyine, the converted Fdo feature object will be a Mgcurvestring object that contains multiple segment. There are arc segment and linear segment.
Here is the code that reads the coordinate points for such a linear feature:
usingSystem;
usingAutodesk.AutoCAD.Runtime;
usingAutodesk.AutoCAD.ApplicationServices;
usingAutodesk.AutoCAD.DatabaseServices;
usingAutodesk.AutoCAD.Geometry;
usingAutodesk.AutoCAD.EditorInput;
usingAutodesk.Gis.Map.Platform.Interop;
usingAutodesk.Gis.Map.Platform;
usingOsgeo.mapguide;
//This line isn't mandatory, but improves loading performances
[Assembly:Commandclass(typeof(Getfeaturetype.Mycommands))]
namespaceGetfeaturetype
{
PublicclassMycommands
{
//Modal Command with localized name
[Commandmethod("Getpolylinecoordinates")]
Public voidMyCommand ()//This method can has any name
{
Editored = Autodesk.AutoCAD.ApplicationServices.Application
. DocumentManager.MdiActiveDocument.Editor;
Transactiontrans = Autodesk.AutoCAD.ApplicationServices.Application
. DocumentManager.MdiActiveDocument.Database.TransactionManager
. StartTransaction ();
using(trans)
{
//Get the Map Object
AcmapmapCurrentmap =Acmapmap. Getcurrentmap ();
//Prompt user to Select Feature in Map
promptselectionoptionsPsop =Newpromptselectionoptions();
Psop. Messageforadding ="Select the FDO Feature in Map 3D to read Data:";
Psop. Singleonly =true;
PromptselectionresultPsresult = ed. GetSelection (PSOP);
if(Psresult.status = =Promptstatus. OK)
{
SelectionsetSelset = Psresult.value;
//Get Map selectionset from AutoCAD selectionset
MgselectionbaseMapselbase =Acmapfeatureentityservice
. GetSelection (Selset);
AcmaplayerMaplayer =Acmapfeatureentityservice
. Getlayer (Psresult.value[0]. OBJECTID);
//get the ID of the selected Parcel
MgfeaturereaderFtrrdr = Mapselbase.getselectedfeatures (
Maplayer, Maplayer.featureclassname,false);
while(Ftrrdr.readnext ())
{
mgclassdefinitioncd = Ftrrdr.getclassdefinition ();
//the Geomety Property name maybe different for your
//data Source
MgbytereaderByterdr = Ftrrdr.getgeometry ("Geometry");
MgagfreaderwriterWTR =NewMgagfreaderwriter();
MggeometryGeom = WTR. Read (BYTERDR);
if(Geom isOsgeo.mapguide.mgcurvestring)
{
varCS = Geom asmgcurvestring;
Ed. Writemessage ("\ n Geo is mgcurvestring.");
for(inti = 0, Segmentcount = cs. Count; i < Segmentcount; i++)
{
varSEG = cs. GetSegment (i);
if(SEG ismgarcsegment)
{
Ed. Writemessage ("\nthis is an ARC Segment.");
varARCSEG = seg asmgarcsegment;
stringmsg =string. Format (
"\nstart point:x= {0}, y={1}",
Arcseg.startcoordinate.x,
ARCSEG.STARTCOORDINATE.Y);
Ed. Writemessage (msg);
msg =string. Format (
"\ncontrol point x= {0}, y={1}",
Arcseg.controlcoordinate.x,
ARCSEG.CONTROLCOORDINATE.Y);
Ed. Writemessage (msg);
msg =string. Format (
"\nend point:x= {0}, y={1}",
Arcseg.endcoordinate.x,
ARCSEG.ENDCOORDINATE.Y);
Ed. Writemessage (msg);
}
if(SEG ismglinearsegment)
{
Ed. Writemessage ("\nthis is a linear Segment.");
varLINEARSEG = seg asmglinearsegment;
varInterator = Linearseg.getcoordinates ();
while(Interator. MoveNext ())
{
varx = Interator. GetCurrent (). X
vary = interator. GetCurrent (). Y
Ed. Writemessage (string. Format (
"\ n x = {0}, y={1}", x, y));
}
}
}
}
if(Geom isOsgeo.mapguide.mglinestring)
{
varls = Geom asmglinestring;
varInterator = ls. Getcoordinates ();
while(Interator. MoveNext ())
{
varx = Interator. GetCurrent (). X
vary = interator. GetCurrent (). Y
Ed. Writemessage (string. Format (
"\ n x = {0}, y={1}", x, y));
}
}
}
}
Trans.commit ();
}
}
}
}