码迷,mamicode.com
首页 > 其他好文 > 详细

设置曲面样式之流域

时间:2018-04-28 22:16:55      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:omr   upd   setw   services   copy   ret   result   method   factor   

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);
        }
    }
}

 

设置曲面样式之流域

标签:omr   upd   setw   services   copy   ret   result   method   factor   

原文地址:https://www.cnblogs.com/myzw/p/8969536.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!