public static void Colorize(MyDB2 mydb, List <System.Drawing.Color> cl, FaceColorizeType type) { TEDictionary ted = mydb.TEDicList[mydb.Resolution]; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); try { ObjectId[] faceIDs = Selection.getFaceIds(mydb.getFaceLayerName()); List <Triangle> triList = Conversions.ToCeometricAcDbTriangleList(faceIDs); Global.SuspendEpsilon(0.0, 0.0); //List<Triangle> triList = ted.TriangleList; Global.ResumeEpsilon(); double num = 1.7976931348623157E+308; double num2 = -1.7976931348623157E+308; string formatFromLUPREC = DBManager.GetFormatFromLUPREC(); string a; double range; if (type == FaceColorizeType.CenterZ) { range = ted.maxCZ - ted.minCZ; } else if (type == FaceColorizeType.MaxZ) { range = ted.maxMaxZ - ted.minMaxZ; } else { throw new System.Exception("无效的颜色类型"); } double sec = range / cl.Count; progressMeter.SetLimit(triList.Count); progressMeter.Start("Colorizing property"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord arg_3D7_0 = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); int i = 0; while (i < triList.Count) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } int colorIndex; if (type == FaceColorizeType.CenterZ) { colorIndex = (int)Math.Floor((triList[i].Center.Z - ted.minCZ) / sec); } else if (type == FaceColorizeType.MaxZ) { colorIndex = (int)Math.Floor((Math.Max(Math.Max(triList[i].Vertex1.Z, triList[i].Vertex2.Z), triList[i].Vertex3.Z) - ted.minMaxZ) / sec); } else { throw new System.Exception("无效的类型"); } if (colorIndex >= cl.Count) { colorIndex = cl.Count - 1; } Face face = (Face)transaction.GetObject(triList[i].AcDbFace.ObjectId, (OpenMode)1); face.Color = Autodesk.AutoCAD.Colors.Color.FromColor(cl[colorIndex]); i++; continue; } transaction.Commit(); } progressMeter.Stop(); return; throw new System.Exception("Invalid target property"); } catch (System.Exception ex) { progressMeter.Stop(); editor.WriteMessage("\n" + ex.Message); } }
public static void Colorize(MyDB2 mydb, List <System.Drawing.Color> cl) { TEDictionary ted = mydb.TEDicList[mydb.Resolution]; AssistContourDic assistContourDic = mydb.assistContourDics[mydb.Resolution]; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); try { double num = 1.7976931348623157E+308; double num2 = -1.7976931348623157E+308; string formatFromLUPREC = DBManager.GetFormatFromLUPREC(); string a; double range = ted.maxMaxZ - ted.minCZ; double sec = range / cl.Count; progressMeter.SetLimit(assistContourDic.elevations.Count); progressMeter.Start("Colorizing property"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord arg_3D7_0 = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); int i = 0; while (i < assistContourDic.elevations.Count) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } int colorIndex; double elevation = assistContourDic.elevations[i]; List <BASE.PLine> pls = assistContourDic.plines[i]; colorIndex = (int)Math.Floor((elevation - ted.minCZ) / sec); if (colorIndex >= cl.Count) { colorIndex = cl.Count - 1; } //Face face = (Face)transaction.GetObject(triList[i].AcDbFace.ObjectId, (OpenMode)1); for (int j = 0; j < pls.Count; j++) { PointSet ps = pls[j].GetVertices(); if (ps.Count <= 2) { continue; } Region h = MyRegion.NewRegion(ps[1]); if (h != null) { h.Color = Autodesk.AutoCAD.Colors.Color.FromColor(cl[colorIndex]); } } i++; continue; } transaction.Commit(); } progressMeter.Stop(); return; throw new System.Exception("Invalid target property"); } catch (System.Exception ex) { progressMeter.Stop(); editor.WriteMessage("\n" + ex.Message); } }
public static Color getColorIndex(MyDB2 mydb, double elevation) { TEDictionary ted = mydb.TEDicList[mydb.Resolution]; return(getColorIndex(elevation, ted.maxMaxZ, ted.minMinZ, mydb.tcSetting.FaceColorList2.colorList)); }