设置曲面样式之流域
Posted david96007
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了设置曲面样式之流域相关的知识,希望对你有一定的参考价值。
QQ网友1109743151求助,
在设置流域后不显示。
代码中貌似没有什么问题,
经过测试,
发现使用手工设置曲面样式过程中,
如果显示流域,
会有一个曲面分析的过程发生,
于是在代码中添加了曲面分析的代码,
之后即可正常显示流域。
测试代码如下:
没有得到网友的允许就将他的代码贴出来,
希望不会造成误会!
// (C) Copyright 2018 by Microsoft // using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; using Autodesk.Civil.DatabaseServices; using Autodesk.Civil.ApplicationServices; using Autodesk.Civil.DatabaseServices.Styles; // This line is not mandatory, but improves loading performances [assembly: CommandClass(typeof(AutoCAD_CSharp_plug_in3.MyCommands))] namespace AutoCAD_CSharp_plug_in3 { public class MyCommands { public static void ModifyTheFurface(bool T1, bool T2, bool T3, bool T4, bool T5, bool T6, bool T7, bool T8, bool T9, bool T10) { //在非模态下打开模型空间前要解锁 //DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ///////////////////// PromptEntityOptions peo = new PromptEntityOptions("\n选择三角网曲面"); peo.SetRejectMessage("\n请选择三角网曲面"); peo.AddAllowedClass(typeof(TinSurface), true); PromptEntityResult per= ed.GetEntity(peo); if (per.Status != PromptStatus.OK) return; ObjectId objectid =per.ObjectId; ///////////////////// //ObjectId objectid = promptForEntity(typeof(TinSurface)); using (Transaction trans = doc.TransactionManager.StartTransaction()) { CivilDocument civilDoc = CivilApplication.ActiveDocument; TinSurface surface = trans.GetObject(objectid, OpenMode.ForWrite) as TinSurface; //change the style, 下面开始更改样式了 ObjectId styleId = new ObjectId(); if (civilDoc.Styles.SurfaceStyles.Contains("Standard")) styleId = civilDoc.Styles.SurfaceStyles["Standard"]; else if (!civilDoc.Styles.SurfaceStyles.Contains("Standard")) { civilDoc.Styles.SurfaceStyles.Add("Standard"); styleId = civilDoc.Styles.SurfaceStyles["Standard"]; } SurfaceStyle surfaceStyle = styleId.GetObject(OpenMode.ForWrite) as SurfaceStyle; //平滑系数 surfaceStyle.ContourStyle.SmoothContours = true; surfaceStyle.ContourStyle.SmoothingType = ContourSmoothingType.AddVertices; surfaceStyle.ContourStyle.SmoothingFactor = 10; surfaceStyle.ContourStyle.MajorContourColorScheme = ColorSchemeType.Rainbow; //等高线 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour).Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 191, 0); //加组主等高线红色 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour).Layer = "0"; //加组主等高线零层 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour).LinetypeScale = 0.4;//加组主等高线比例 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MinorContour).Color = Autodesk.AutoCAD.Colors.Color.FromRgb(165, 145, 82);//次等高线红色 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MinorContour).Layer = "0";//次等高线零层 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour).LinetypeScale = 0.1;//加组主等高线比例 DisplayStyle majorContours = surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour); majorContours.Visible = true; // majorContours.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 255, 0); surfaceStyle.ContourStyle.BaseElevationInterval = 0.0;//基地海拔间隔 surfaceStyle.ContourStyle.MajorContourInterval = 10;//主要等高线间距 surfaceStyle.ContourStyle.MinorContourInterval = 2;//次要等高线间距 DisplayStyle minorContours = surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MinorContour); minorContours.Visible = true; // minorContours.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 255, 0); // 显示等高线 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour).Visible = T1;//是否显示等高线 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.MinorContour).Visible = T1;//细等高线 // display boundaries: surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Boundary).Visible = true; surfaceStyle.BoundaryStyle.DisplayExteriorBoundaries = true; surfaceStyle.BoundaryStyle.DisplayInteriorBoundaries = false; // 关闭显示的其他显示 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.UserContours).Visible = T2;//用户轮廓 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Directions).Visible = T3;//方向 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Elevations).Visible = T4;//海拔高度 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Slopes).Visible = T5;//山坡上 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.SlopeArrows).Visible = T6;//斜率的箭 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Watersheds).Visible = T7;//分水岭 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Gridded).Visible = T8;//网格 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Points).Visible = T9;//点 surfaceStyle.GetDisplayStylePlan(SurfaceDisplayStyleType.Triangles).Visible = T10;//点 surface.StyleId = styleId;//指定文档中第一表面的风格 //surface.UpgradeOpen(); surface.Rebuild();//重建曲面 ///////////////////////////// if (T7) { SurfaceAnalysis sa = surface.Analysis; SurfaceAnalysisWatershedDataCollection swdc = sa.GetWatershedData(); sa.SetWatershedData(swdc); } //////////////////////////// trans.Commit();//提交事务 ed.UpdateScreen(); ed.UpdateTiledViewportsFromDatabase(); ed.UpdateTiledViewportsInDatabase(); } //ZoomExtents(); //在用完后要锁定 //docLock.Dispose(); } [CommandMethod("MyGroup", "MyCommand", "MyCommandLocal", CommandFlags.Modal)] public void MyCommand() // This method can have any name { ModifyTheFurface(false, false, false, false, false, false, true, false, false, false); } } }
以上是关于设置曲面样式之流域的主要内容,如果未能解决你的问题,请参考以下文章