サーフェスにスタイルを割り当てるには、サーフェス オブジェクトの StyleId プロパティを、有効な SurfaceStyle オブジェクトの ObjectId に設定します。
この例では、新しいスタイルを作成し、その設定を変更し、それをドキュメントの最初のサーフェスに割り当てる方法を示します。通常はモデルの表示設定も変更しますが、ここでは簡潔に平面表示設定のみを変更します。
[CommandMethod("SurfaceStyle")]
public void SurfaceStyle()
{
using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
// create a new style called 'example style':
ObjectId styleId = doc.Styles.SurfaceStyles.Add("example style");
// modify the style:
SurfaceStyle surfaceStyle = styleId.GetObject(OpenMode.ForWrite) as SurfaceStyle;
// display surface triangles
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Triangles).Visible = true;
surfaceStyle.GetDisplayStyleModel(SurfaceDisplayStyleType.Triangles).Visible = true;
// display boundaries, exterior only:
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Boundary).Visible = true;
surfaceStyle.BoundaryStyle.DisplayExteriorBoundaries = true;
surfaceStyle.BoundaryStyle.DisplayInteriorBoundaries = false;
// display major contours:
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour).Visible = true;
// turn off display of other items:
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MinorContour).Visible = false;
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.UserContours).Visible = false;
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Directions).Visible = false;
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Elevations).Visible = false;
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Slopes).Visible = false;
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.SlopeArrows).Visible = false;
surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Watersheds).Visible = false;
// do the same for all model display settings as well
// assign the style to the first surface in the document:
CivSurface surf = doc.GetSurfaceIds()[0].GetObject(OpenMode.ForWrite) as CivSurface;
surf.StyleId = styleId;
// commit the transaction
ts.Commit();
}
}