您的位置:首页 > 其它

Civil 3D 2013利用API把三角网曲面提取为栅格网

2013-02-22 11:43 288 查看
Civil3D2013中对曲面的.netAPI做了增强,可以让我们从三角网曲面中提取栅格网。先看看效果:





下面的代码演示了从一个三角网曲面中提取三维栅格网,这些栅格网是由红色是三维多段线polyline构成的。

//
usingSystem;
usingAutodesk.AutoCAD.Runtime;
usingAutodesk.AutoCAD.ApplicationServices;
usingAutodesk.AutoCAD.DatabaseServices;
usingAutodesk.AutoCAD.Geometry;
usingAutodesk.AutoCAD.EditorInput;
usingAutodesk.Civil.DatabaseServices;
usingAutodesk.Civil;

//Thislineisnotmandatory,butimprovesloadingperformances
[assembly:CommandClass(typeof(SurfaceApiInCivil3D2013.MyCommands))]

namespaceSurfaceApiInCivil3D2013
{

//ThisclassisinstantiatedbyAutoCADforeachdocumentwhen
//acommandiscalledbytheuserthefirsttimeinthecontext
//ofagivendocument.Inotherwords,nonstaticdatainthisclass
//isimplicitlyper-document!
publicclassMyCommands
{
staticDocument_doc=Application.DocumentManager.MdiActiveDocument;
staticEditor_editor=_doc.Editor;
staticDatabasedb=_doc.Database;

privateObjectIdpromptForTinSurface()
{
PromptEntityOptionsoptions=newPromptEntityOptions(
"\nSelectaTINSurface:");
options.SetRejectMessage(
"\nTheselectedobjectisnotaTINSurface.");
options.AddAllowedClass(typeof(TinSurface),true);

PromptEntityResultresult=_editor.GetEntity(options);
if(result.Status==PromptStatus.OK)
{
//Everythingiscool;wereturntheselected
//surfaceObjectId.
returnresult.ObjectId;
}
returnObjectId.Null;//Indicatingerror.
}

[CommandMethod("CDS_ExtractGrid")]
publicvoidCDS_ExtractGrid()
{
ObjectIdsurfaceId=promptForTinSurface();
if(surfaceId==ObjectId.Null)
{
_editor.WriteMessage("\nNoTINSurfaceselected.");
return;
}

using(Transactiontr=db.TransactionManager.StartTransaction())
{
TinSurfacesurface=surfaceId.GetObject(OpenMode.ForRead)
asTinSurface;
ObjectIdCollectionids=surface.ExtractGridded(
SurfaceExtractionSettingsType.Model);

foreach(ObjectIdidinids)
{
Polyline3dpolyline=
id.GetObject(OpenMode.ForWrite)asPolyline3d;
if(polyline!=null)
{
using(polyline)
{
polyline.Color=
Autodesk.AutoCAD.Colors.Color.FromRgb(255,0,0);
}
}
}
tr.Commit();
}
}

}

}
想了解更多Civil3D2013API,请看CivilizedDevelopment博客中的21WOJP系列(21WeekOfJayPeak),JayPeak是Civil3D2013的代码名。

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: