AutoCAD Civil 3D Help: Creating a GridSurface with GridSurface.Create()
通过GridSurface.Create()创建一个网格曲面
你可以用GridSurface.Create()方法创建一个空的网格曲面。该方法有2个重载方法:一个采用缺省的曲面样式,另外一个可以指定曲面样式。两者共通的参数有新网格曲面的名字、x和y间隔和朝向/方位。xy间隔和朝向的单位通过曲面创建环境设置来制定(SettingsCmdCreateSurface Distance和Area属性)
网格曲面对象创建在一个规律间隔的网格上,网格上的每个位置(由GridLocation结构来表示)都有一个x索引和y索引。网格位置(0,0)位于网格左下角。
下面的例子创建了一个新的空网格曲面,间隔为25’ x 25’,重复于一个10 x 10的网格上,然后给每个位置加上一个随机的高程。
[CommandMethod("CreateGridSurface")]
public void CreateGridSurface()
{
using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
string surfaceName = "ExGridSurface";
// Select a surface style to use
ObjectId surfaceStyleId = doc.Styles.SurfaceStyles["Slope Banding (2D)"];
// Create the surface with grid spacing of 25' x 25', orientation 0 degrees:
ObjectId surfaceId = GridSurface.Create(surfaceName, 25, 25, 0.0, surfaceStyleId);
GridSurface surface = surfaceId.GetObject(OpenMode.ForWrite) as GridSurface;
// Add some random elevations
Random m_Generator = new Random();
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
double z = m_Generator.NextDouble() * 10;
GridLocation loc = new GridLocation(i, j);
surface.AddPoint(loc, z);
}
}
// commit the create action
ts.Commit();
}
}
父主题: