.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

open file error,help

1 REPLY 1
Reply
Message 1 of 2
totu
216 Views, 1 Reply

open file error,help

hi folks:
i meet a new problem,this is code:
using System ;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.Windows;

[assembly: CommandClass(typeof(ClassLibrary.Class))]

namespace ClassLibrary {
///
/// Summary description for Class.
///

public class Class {
public Class() {
this.test();
}
// Define Command "tomato"
[CommandMethod("fileaction")]
// This method i want to open a dwg file and unload any layer;
public void test() {
Autodesk.AutoCAD.ApplicationServices.Document file=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open("c:\\1.dwg",false);//if 1.dwg hasn't any problem,it is ok and exist
Database db=file.Database;
Transaction trans=db.TransactionManager.StartTransaction();
Editor ed=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
try{
LayerTable lt=(LayerTable)trans.GetObject(db.LayerTableId,OpenMode.ForRead);
foreach (ObjectId ob in lt) {
LayerTableRecord ltr=(LayerTableRecord)trans.GetObject(ob,OpenMode.ForWrite);//when writing action ,occur exception error ,why?
if (ltr.IsLocked) {ltr.IsLocked=false;
}
if (ltr.IsFrozen) {ltr.IsFrozen=false;
}
}
trans.Commit();
}catch{
ed.WriteMessage("error!");
}finally{
trans.Dispose();
}
}
}
}
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: totu

What is the exception you are getting? When you get an exception please
always post the exact exception message and exception type.

Albert

wrote in message news:4885281@discussion.autodesk.com...
hi folks:
i meet a new problem,this is code:
using System ;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.Windows;

[assembly: CommandClass(typeof(ClassLibrary.Class))]

namespace ClassLibrary {
///
/// Summary description for Class.
///

public class Class {
public Class() {
this.test();
}
// Define Command "tomato"
[CommandMethod("fileaction")]
// This method i want to open a dwg file and unload any layer;
public void test() {
Autodesk.AutoCAD.ApplicationServices.Document
file=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open("c:\\1.dwg",false);//if
1.dwg hasn't any problem,it is ok and exist
Database db=file.Database;
Transaction trans=db.TransactionManager.StartTransaction();
Editor
ed=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
try{
LayerTable lt=(LayerTable)trans.GetObject(db.LayerTableId,OpenMode.ForRead);
foreach (ObjectId ob in lt) {
LayerTableRecord
ltr=(LayerTableRecord)trans.GetObject(ob,OpenMode.ForWrite);//when writing
action ,occur exception error ,why?
if (ltr.IsLocked) {ltr.IsLocked=false;
}
if (ltr.IsFrozen) {ltr.IsFrozen=false;
}
}
trans.Commit();
}catch{
ed.WriteMessage("error!");
}finally{
trans.Dispose();
}
}
}
}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost