Hello,
I use C# with VS 2003 and AutoCAD 2005. I haven't quite figured out how to
write attributes to it yet, but this is a start (the code is pasted at the
end).
Does anyone out there know of a way to call AutoCAD commands from C#? In
ObjectARX C++ there was the acedCommand method, so I could use:
acedCommand(RTSTR, "-INSERT", RTSTR, "My Block", ... etc etc)
It would be nice to have that again.
Hope this helps. I'm curious about the other responses too.
-Carlos
public void InsertIntoAutoCAD()
{
// Insert the block into the AutoCAD model
try
{
Document doc = Application.DocumentManager.MdiActiveDocument;
string fname = "C:\\Blocks\\My Block.dwg";
using (Database db = new Database(false, false))
{
//read block drawing
db.ReadDwgFile(fname, System.IO.FileShare.Read, true, null);
using (Transaction t = doc.TransactionManager.StartTransaction())
{
//insert the new block
Autodesk.AutoCAD.ApplicationServices.CommandLinePrompts.Message("\n
Inserting the block...");
ObjectId idBTR = doc.Database.Insert("My Block",db,false);
//create a ref to the block
BlockTable bt = (BlockTable)t.GetObject(doc.Database.BlockTableId,
OpenMode.ForRead);
BlockTableRecord btr =
(BlockTableRecord)t.GetObject(bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite);
Autodesk.AutoCAD.Geometry.Point3d location = new Point3d(0.0, 0.0, 0.0);
using (BlockReference bref = new BlockReference(location, idBTR))
{
btr.AppendEntity(bref);
t.TransactionManager.AddNewlyCreatedDBObject(bref, true);
t.Commit();
}
}
}
catch
{
}
}
wrote in message news:4906068@discussion.autodesk.com...
Can someone give me an example of how you would insert the modelspace
entities from an external drawing file into the active drawing with .net?
Thanks,
Steve