如果你需要更改曲面的样式,比如更改等高线的颜色等等,在Civil 3D中,你可以通过在toolspace中选中曲面,然后点右键选择“Edit surface style…”然后切换到“Display” tab 来更改,:
下面的通过代码的方式使用API来实现同样的效果:
[CommandMethod("MyGroup", "SurfaceStyleExample", "SurfaceStyleExample", CommandFlags.Modal)]public void MyCommand() // This method can have any name{ Document doc = Application.DocumentManager.MdiActiveDocument; if (doc != null) { Editor ed = Application.DocumentManager .MdiActiveDocument.Editor; // select a tin surface PromptEntityOptions peo = new PromptEntityOptions( "\nSelect a tin surface: "); peo.SetRejectMessage("\nOnly Tin surface is accepted"); peo.AddAllowedClass(typeof(TinSurface), true); PromptEntityResult per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) return; CivilDocument civilDoc = CivilApplication.ActiveDocument; using (Transaction trans = doc.TransactionManager .StartTransaction()) { TinSurface surface = trans.GetObject(per.ObjectId, OpenMode.ForRead) as TinSurface; //exclude invalid points, 附赠功能,排除异常点 surface.BuildOptions.ExecludeMaximumElevation = true; surface.BuildOptions.MaximumElevation = 5000; surface.BuildOptions.ExecludeMinimumElevation = true; surface.BuildOptions.MinimumElevation = 200; //set the Maximum Triangle Length,设置三角形最大边长 surface.BuildOptions.MaximumTriangleLength = 200; //change the style, 下面开始更改样式了 ObjectId styleId; if (civilDoc.Styles.SurfaceStyles.Contains("Standard")) { styleId = civilDoc.Styles.SurfaceStyles["Standard"]; } else { // create a new style called ‘example style‘: styleId = civilDoc.Styles.SurfaceStyles .Add("example style"); } // modify the style SurfaceStyle surfaceStyle = styleId.GetObject( OpenMode.ForWrite) as SurfaceStyle; //countours smoothing surfaceStyle.ContourStyle.SmoothContours = true; surfaceStyle.ContourStyle.SmoothingType = ContourSmoothingType.AddVertices; surfaceStyle.ContourStyle.SmoothingFactor = 10; surfaceStyle.ContourStyle.MajorContourColorScheme = ColorSchemeType.Rainbow; //Major contour, red surfaceStyle.GetDisplayStylePlan( SurfaceDisplayStyleType.MajorContour).Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0); //Major contour, layer 0 surfaceStyle.GetDisplayStylePlan( SurfaceDisplayStyleType.MajorContour).Layer = "0"; //Mainor contour, gree surfaceStyle.GetDisplayStylePlan( SurfaceDisplayStyleType.MinorContour).Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 255, 0); //Mainor contour, layer 0, 如果你要放在其他图层,要确保该图层存在 surfaceStyle.GetDisplayStylePlan( SurfaceDisplayStyleType.MajorContour).Layer = "0"; // display major contours: surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType .MajorContour).Visible = true; surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType .MinorContour).Visible = true; // turn off display of other items: 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; //TODO: do the same for all model display settings as well // // assign the style to the first surface in the document: surface.StyleId = styleId; // commit the transaction trans.Commit(); //rebuild the surface surface.Rebuild(); } } }
改之前的样子:
运行之后,等高线的颜色已经改变了.
Hope this helps.
时间: 2024-10-09 03:34:23