로드하려는 도면에 레이어 선 종류를 설정할 수 있도록 활성 문서에 선 종류를로드하려고합니다. 이제 문제는 내가 그것을로드하려고 할 때, autocad는 나를 예외로 준다 : eWasOpenForRead. 그래서 나는 커맨드 라인을 통해 그것을 보내려고 노력했지만 그것은 효과가 있었지만, 지금 쓰고있는 애플리케이션은 ... 왜 이런 일이 일어 났는지 아무도 모른다.C# AutoCAD 도면에 선 종류로드
코드 :
private void defaultLayerFix() {
// Open a transaction for fixing layers that have the correct name
// but not the correct color or linetype.
using(curTrans = db.TransactionManager.StartOpenCloseTransaction()) {
// Open the layerTable and lineType table for read.
dwgLyrTbl = curTrans.GetObject(
db.LayerTableId,OpenMode.ForRead) as LayerTable;
acLinTbl = curTrans.GetObject(
db.LinetypeTableId,OpenMode.ForRead) as LinetypeTable;
// Check each layer against the standard layers DataSet.
foreach (ObjectId layID in dwgLyrTbl) {
LayerTableRecord curLayer = curTrans.GetObject(
layID,OpenMode.ForRead) as LayerTableRecord;
var layerFound = _LayerDataTable.Rows.Find(curLayer.Name.ToUpper());
if(layerFound != null){
// Upgrade the layerTable and LayerRecord for write.
dwgLyrTbl.UpgradeOpen();
curLayer.UpgradeOpen();
// modify the color of the layer
curLayer.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(
Autodesk.AutoCAD.Colors.ColorMethod.ByAci, (short)layerFound[2]);
// I tried to put it in its own transaction in hopes that it would help.. but it didnt
using(Transaction tempTrans = db.TransactionManager.StartOpenCloseTransaction()){
// if the layer is not loaded in the current dwg
if(!acLinTbl.Has((string)layerFound[3]))
try {
db.LoadLineTypeFile((string)layerFound[3], "acad.lin");
} catch (Autodesk.AutoCAD.Runtime.Exception e) {
Editor ed = acDoc.Editor;
ed.WriteMessage(e.Message);
}
tempTrans.Commit();
}
// Change current layer linetype to...
curLayer.LinetypeObjectId = acLinTbl[(string)layerFound[3]];
// Downgrade the layerTable, lineTable and the LayerRecord for read.
curLayer.DowngradeOpen();
dwgLyrTbl.DowngradeOpen();
// Remove the layer from the standards list
// so we do not attempt to have redundant layers.
for(int i = _LayerDataTable.Rows.Count-1; i >= 0; i--) {
System.Data.DataRow dr = _LayerDataTable.Rows[i];
if (dr["NAME"] == layerFound[0]){
dr.Delete();
break;
}
}
} else {
// if the layer is not in within standard add it to a data set
// to fix manually.
if(curLayer.Name == "0")
continue;
var newRow = LayersToFix.NewRow();
newRow["NAME"] = curLayer.Name;
// TODO get color name..
newRow["COLOR"] = curLayer.Color.ColorName;
newRow["COLOR_ID"] = 0;
LinetypeTableRecord Ltype = (LinetypeTableRecord)curTrans.GetObject(
curLayer.LinetypeObjectId,OpenMode.ForRead
);
newRow["LINETYPE"] = Ltype.Name;
LayersToFix.Rows.Add(newRow);
}
}
// accept the changes made in this transaction
curTrans.Commit();
}
}
당신이 '를 보면 curLayer.UpgradeOpen();'. 이렇게하면 열어 놓은 상태로 DBObject를 열어서 이미 읽었을 때 쓸 수 있습니다. 'curLayer.DownGradeOpen();'그것을 다시 읽기 위해 되돌립니다. –