[求助]指定图层颜色的问题
红色的这一句是用了“配色系统”中的颜色,应该是黄色的,那么第三个图层"ColorBookYellow"应该是黄色,为什么程序运行之后是白色的呢?
代码来自“AutoCAD .NET 开发人员手册”的“指定图层颜色”
public static void SetLayerColor(){// Get the current document and databaseDocument acDoc = Application.DocumentManager.MdiActiveDocument;Database acCurDb = acDoc.Database; // Start a transactionusing (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()){ // Open the Layer table for read LayerTable acLyrTbl; acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable; // Define an array of layer names string[] sLayerNames = new string; sLayerNames = "ACIRed"; sLayerNames = "TrueBlue"; sLayerNames = "ColorBookYellow"; // Define an array of colors for the layers Color[] acColors = new Color; acColors = Color.FromColorIndex(ColorMethod.ByAci, 1); acColors = Color.FromRgb(23, 54, 232); acColors = Color.FromNames("PANTONE Yellow 0131 C", "PANTONE(R) pastel coated"); int nCnt = 0; // Add or change each layer in the drawing foreach (string sLayerName in sLayerNames) { LayerTableRecord acLyrTblRec; if (acLyrTbl.Has(sLayerName) == false) { acLyrTblRec = new LayerTableRecord(); // Assign the layer a name acLyrTblRec.Name = sLayerName; // Upgrade the Layer table for write if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen(); // Append the new layer to the Layer table and the transaction acLyrTbl.Add(acLyrTblRec); acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true); } else { // Open the layer if it already exists for write acLyrTblRec = acTrans.GetObject(acLyrTbl, OpenMode.ForWrite) as LayerTableRecord; } // Set the color of the layer acLyrTblRec.Color = acColors; nCnt = nCnt + 1; } // Save the changes and dispose of the transaction acTrans.Commit();}}
<p>代码在Cad2010正常,2008失败</p>
<p>应该是2008的类库的问题吧</p>
回复:(lzh741206)代码在Cad2010正常,2008失败应...
老大,我的CAD2007也不行,算了,跳过这地方了
页:
[1]