利用Civil 3D API更改曲面的样式
2014-12-30 11:09
549 查看
如果你需要更改曲面的样式,比如更改等高线的颜色等等,在Civil 3D中,你可以通过在toolspace中选中曲面,然后点右键选择“Edit surface style…”然后切换到“Display” tab 来更改,:
下面的通过代码的方式使用API来实现同样的效果:
改之前的样子:
运行之后,等高线的颜色已经改变了.
Hope this helps.
下面的通过代码的方式使用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.
相关文章推荐
- Civil 3D 2013利用API把三角网曲面提取为栅格网
- Civil 3D 2012基于.net 的曲面API Webcast 7月8号下午进行
- 7月9号周五Civil 3D 2011 API免费网络培训预告
- 利用J2ME开发移动3D游戏之3D图形API
- 利用J2ME开发移动3D游戏之3D图形API
- 利用J2ME开发移动3D游戏之3D图形API
- 获取Civil 3D 三角网曲面TinSurface中每个小三角形的法向量
- 利用HTML5的classList API优化对样式名className的操作
- Civil 3D API二次开发学习指南
- 利用J2ME开发移动3D游戏之3D图形API
- Civil 3D 2013新API -- 创建空间几何点(COGO Point)
- 利用J2ME开发移动3D游戏之3D图形API
- 利用css3制作3D样式按钮
- 利用JavaScript更改input中radio和checkbox样式
- AutoCAD® Civil 3D API需求意愿调查
- Civil 3D 中使用COM API导入DEM数据创建曲面
- VRC 3D chat uses IRC, the OpenGL API and OpenGL Shading Language
- 利用未公布API获取CPU使用率
- 利用Yahoo! Search API开发自已的搜索引擎-javascript版
- 利用Directsound 3D实现游戏中3D音效