public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
W.OpenFileDialog dlg = new W.OpenFileDialog();
// select file to open
dlg.Filter = "LandXML files (*.xml)|*.xml";
dlg.Title = "Import LandXML and "
+ "Create TopographySurface";
if( dlg.ShowDialog() != W.DialogResult.OK )
{
return Result.Cancelled;
}
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load( dlg.FileName );
XmlNodeList pnts
= xmlDoc.GetElementsByTagName( "Pnts" );
char[] separator = new char[] { ' ' };
double x = 0, y = 0, z = 0;
List<XYZ> pts = new List<XYZ>();
for( int k = 0; k < pnts.Count; ++k )
{
for( int i = 0;
i < pnts[k].ChildNodes.Count; ++i )
{
int j = 1;
string text = pnts[k].ChildNodes[i].InnerText;
string[] coords = text.Split( separator );
foreach( string coord in coords )
{
switch( j )
{
case 1:
x = Double.Parse( coord );
break;
case 2:
y = Double.Parse( coord );
break;
case 3:
z = Double.Parse( coord );
break;
default:
break;
}
j++;
}
pts.Add( new XYZ( x, y, z ) );
}
}
using ( Transaction t = new Transaction( doc ) )
{
t.Start( "Create Topography Surface" );
//TopographySurface surface = doc.Create.NewTopographySurface( pntList );
//TopographySurface surface = doc.Create.NewTopographySurface( pts ); // 2013
TopographySurface surface = TopographySurface.Create( doc, pts ); // 2014
t.Commit();
}
return Result.Succeeded;
}