.NET

Reply
Active Member
totu
Posts: 6
Registered: ‎06-24-2005
Message 1 of 2 (82 Views)

open file error,help

82 Views, 1 Replies
06-24-2005 08:22 PM
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();
}
}
}
}
*Albert Szilvasy
Message 2 of 2 (82 Views)

Re: open file error,help

06-25-2005 08:34 PM 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();
}
}
}
}
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.