.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
*Jon Prisbe
AutpCAD 2005 and .NET API
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
83 Views, 3 Replies
07-14-2005 07:13 AM
I have written a .NET app that does the following:
1. Get a folder name from the user
2. Get a list of DWG files in the folder
3. Open each DWG and check for and blocks references in the DWG
4. Repeat 1, 2 and 3 until all DWGs have been checked.
problem:
It only opens the first DWG, each subsequent call to ReadDwgFile throws an
exception. Code below:
string folder2d = ui.TwoDFolder;
Database db = new Database();
if (Directory.Exists(folder2d))
{
StreamWriter logFile = new StreamWriter("c:\\temp\\stc_hunt2d.log");
string[] files = Directory.GetFiles(folder2d, "*.dwg");
foreach (string filename in files)
{
bool hasBlock = false;
db.ReadDwgFile(filename, FileShare.Read, false, "");
using (Transaction t = db.TransactionManager.StartTransaction())
{
BlockTable bt =
(BlockTable)t.GetObject(db.BlockTableId,OpenMode.F orRead);
BlockTableRecord btr =
(BlockTableRecord)t.GetObject(bt[BlockTableRecord. ModelSpace],OpenMode.ForRead);
foreach(ObjectId objId in btr)
{
DBObject dbObj = t.GetObject(objId,OpenMode.ForRead);
BlockReference blkRef = dbObj as BlockReference;
if (blkRef!=null)
hasBlock = true;
}
t.Commit();
}
if (hasBlock)
logFile.WriteLine(Path.GetFileNameWithoutExtension (filename));
}
logFile.Close();
}
Any ideas what is happening?
Thanks,
Jon
1. Get a folder name from the user
2. Get a list of DWG files in the folder
3. Open each DWG and check for and blocks references in the DWG
4. Repeat 1, 2 and 3 until all DWGs have been checked.
problem:
It only opens the first DWG, each subsequent call to ReadDwgFile throws an
exception. Code below:
string folder2d = ui.TwoDFolder;
Database db = new Database();
if (Directory.Exists(folder2d))
{
StreamWriter logFile = new StreamWriter("c:\\temp\\stc_hunt2d.log");
string[] files = Directory.GetFiles(folder2d, "*.dwg");
foreach (string filename in files)
{
bool hasBlock = false;
db.ReadDwgFile(filename, FileShare.Read, false, "");
using (Transaction t = db.TransactionManager.StartTransaction())
{
BlockTable bt =
(BlockTable)t.GetObject(db.BlockTableId,OpenMode.F
BlockTableRecord btr =
(BlockTableRecord)t.GetObject(bt[BlockTableRecord.
foreach(ObjectId objId in btr)
{
DBObject dbObj = t.GetObject(objId,OpenMode.ForRead);
BlockReference blkRef = dbObj as BlockReference;
if (blkRef!=null)
hasBlock = true;
}
t.Commit();
}
if (hasBlock)
logFile.WriteLine(Path.GetFileNameWithoutExtension
}
logFile.Close();
}
Any ideas what is happening?
Thanks,
Jon
*Albert Szilvasy
Re: AutpCAD 2005 and .NET API
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-14-2005 08:32 AM in reply to:
*Jon Prisbe
What is the exception you are getting?
Albert
"Jon Prisbe" wrote in message
news:4901309@discussion.autodesk.com...
I have written a .NET app that does the following:
1. Get a folder name from the user
2. Get a list of DWG files in the folder
3. Open each DWG and check for and blocks references in the DWG
4. Repeat 1, 2 and 3 until all DWGs have been checked.
problem:
It only opens the first DWG, each subsequent call to ReadDwgFile throws an
exception. Code below:
string folder2d = ui.TwoDFolder;
Database db = new Database();
if (Directory.Exists(folder2d))
{
StreamWriter logFile = new StreamWriter("c:\\temp\\stc_hunt2d.log");
string[] files = Directory.GetFiles(folder2d, "*.dwg");
foreach (string filename in files)
{
bool hasBlock = false;
db.ReadDwgFile(filename, FileShare.Read, false, "");
using (Transaction t = db.TransactionManager.StartTransaction())
{
BlockTable bt =
(BlockTable)t.GetObject(db.BlockTableId,OpenMode.F orRead);
BlockTableRecord btr =
(BlockTableRecord)t.GetObject(bt[BlockTableRecord. ModelSpace],OpenMode.ForRead);
foreach(ObjectId objId in btr)
{
DBObject dbObj = t.GetObject(objId,OpenMode.ForRead);
BlockReference blkRef = dbObj as BlockReference;
if (blkRef!=null)
hasBlock = true;
}
t.Commit();
}
if (hasBlock)
logFile.WriteLine(Path.GetFileNameWithoutExtension (filename));
}
logFile.Close();
}
Any ideas what is happening?
Thanks,
Jon
Albert
"Jon Prisbe"
news:4901309@discussion.autodesk.com...
I have written a .NET app that does the following:
1. Get a folder name from the user
2. Get a list of DWG files in the folder
3. Open each DWG and check for and blocks references in the DWG
4. Repeat 1, 2 and 3 until all DWGs have been checked.
problem:
It only opens the first DWG, each subsequent call to ReadDwgFile throws an
exception. Code below:
string folder2d = ui.TwoDFolder;
Database db = new Database();
if (Directory.Exists(folder2d))
{
StreamWriter logFile = new StreamWriter("c:\\temp\\stc_hunt2d.log");
string[] files = Directory.GetFiles(folder2d, "*.dwg");
foreach (string filename in files)
{
bool hasBlock = false;
db.ReadDwgFile(filename, FileShare.Read, false, "");
using (Transaction t = db.TransactionManager.StartTransaction())
{
BlockTable bt =
(BlockTable)t.GetObject(db.BlockTableId,OpenMode.F
BlockTableRecord btr =
(BlockTableRecord)t.GetObject(bt[BlockTableRecord.
foreach(ObjectId objId in btr)
{
DBObject dbObj = t.GetObject(objId,OpenMode.ForRead);
BlockReference blkRef = dbObj as BlockReference;
if (blkRef!=null)
hasBlock = true;
}
t.Commit();
}
if (hasBlock)
logFile.WriteLine(Path.GetFileNameWithoutExtension
}
logFile.Close();
}
Any ideas what is happening?
Thanks,
Jon
Re: AutpCAD 2005 and .NET API
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-14-2005 09:03 AM in reply to:
*Jon Prisbe
The database should be empty when you call ReadDwgFile. Move
its creation into the foreach loop.
its creation into the foreach loop.
*Jon Prisbe
Re: AutpCAD 2005 and .NET API
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-15-2005 05:18 AM in reply to:
*Jon Prisbe
I moved the creation and it works.
Thanks,
wrote in message news:4901565@discussion.autodesk.com...
The database should be empty when you call ReadDwgFile. Move
its creation into the foreach loop.
Thanks,
The database should be empty when you call ReadDwgFile. Move
its creation into the foreach loop.
