Insert Method

Insert Method

Anonymous
Not applicable
651 Views
2 Replies
Message 1 of 3

Insert Method

Anonymous
Not applicable
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
0 Likes
652 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
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
0 Likes
Message 3 of 3

Anonymous
Not applicable
Never mind...

I guess you can't. I had missed the other posts on the acedCommand topic.

-Carlos

"Carlos" wrote in message
news:4906567@discussion.autodesk.com...
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
0 Likes