Access data in DWG by code

Access data in DWG by code

Anonymous
Not applicable
605 Views
2 Replies
Message 1 of 3

Access data in DWG by code

Anonymous
Not applicable
1 I have reviewed the webcasts courses. Most of the samples need to run in AutoCAD command line. However, I need to code a stand-alone application by C/C++ to read the coordinates of points/aligenmetns in Civil 3D, or use the command in AutoCAD to start a c\c++ program I code to access and process the data. Anyone can give me some advices?

2 The second question is if the API support C/C++. In the webcasts courses, instructor said it can, but none of the samples present how to code in C/C++. AutoLISP/Visual LISP, ActiveX, Object ARX and .NET, four kinds of api are listed. Which one them or COM API is the best choice if I only know C\C++?

Thanks for reading this thread and offering advices.
0 Likes
606 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
You may find C#.net to be good transition for working with AutoCad and doing what you need to with point data. But if you want to stick with c++ i think you'll have to go with objectARX, and that would be out of my territory.
0 Likes
Message 3 of 3

Anonymous
Not applicable
Try this then go to http://through-the-interface.typepad.com/ and use the blog search to find lots of materials.
The code below can be modified to find not only blocks but any kind of entity you need -
look the line - BlockReference br = ent as BlockReference; // you can change this to match your type of entity.
{code}
private int UpdateBlock(Database db, ObjectId btrId, string blockName, string blockNewName)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
int changedCount = 0;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForWrite);
// Test each entity in the container...
foreach (ObjectId entId in btr)
{
Entity ent = tr.GetObject(entId, OpenMode.ForWrite) as Entity;
if (ent != null)
{
BlockReference br = ent as BlockReference;
if (br != null)
{
BlockTableRecord bd = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForWrite);
// ... to see whether it's a block with
// the name we're after
if (bd.Name.ToUpper() == blockName)
{
ed.WriteMessage("\nModifying block : " + bd.Name);
bd.Name = blockNewName;
ed.WriteMessage("\nBlock is changed to : " + bd.Name);
changedCount++;
}
}
}
}
tr.Commit();
}
return changedCount;
}
{code}
0 Likes