.NET

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

open file error,help

78 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 (78 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();
}
}
}
}

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community