c# 4.0 - C# AutoCAD load linetype to drawing -
i'm trying load linetype active document can set layers linetype 1 i'm trying load. problem when try load it, autocad giving me exception of: ewasopenforread. tried send via command line , worked, application im writing ended... have idea why happening?
code:
private void defaultlayerfix() { // open transaction fixing layers have correct name // not correct color or linetype. using(curtrans = db.transactionmanager.startopenclosetransaction()) { // open layertable , linetype table read. dwglyrtbl = curtrans.getobject( db.layertableid,openmode.forread) layertable; aclintbl = curtrans.getobject( db.linetypetableid,openmode.forread) linetypetable; // check each layer against standard layers dataset. foreach (objectid layid in dwglyrtbl) { layertablerecord curlayer = curtrans.getobject( layid,openmode.forread) layertablerecord; var layerfound = _layerdatatable.rows.find(curlayer.name.toupper()); if(layerfound != null){ // upgrade layertable , layerrecord write. dwglyrtbl.upgradeopen(); curlayer.upgradeopen(); // modify color of layer curlayer.color = autodesk.autocad.colors.color.fromcolorindex( autodesk.autocad.colors.colormethod.byaci, (short)layerfound[2]); // tried put in own transaction in hopes help.. didnt using(transaction temptrans = db.transactionmanager.startopenclosetransaction()){ // if layer not loaded in 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 layertable, linetable , layerrecord read. curlayer.downgradeopen(); dwglyrtbl.downgradeopen(); // remove layer standards list // not attempt have redundant layers. for(int = _layerdatatable.rows.count-1; >= 0; i--) { system.data.datarow dr = _layerdatatable.rows[i]; if (dr["name"] == layerfound[0]){ dr.delete(); break; } } } else { // if layer not in within standard add data set // fix manually. if(curlayer.name == "0") continue; var newrow = layerstofix.newrow(); newrow["name"] = curlayer.name; // todo 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 changes made in transaction curtrans.commit(); } }
all openmode
s forread
.
if you're trying change in drawing, should use forwrite
in part you're trying change drawing. (i'm not sure if exact word that, idea that).
Comments
Post a Comment