.NET

.NET

Reply
Contributor
16 Posts
0 Kudos
Registered: ‎02-14-2006
Post 1 of 3

Inserting blocks with .net managed code

89 Views, 2 Replies
02-17-2006 11:53 AM
I’m writing an application that connects to an SQL database and displays information much like design Center. One I get the records I need in a list view I need to in insert a block related to that record. Can anybody help me in inserting a block in to a drawing using managed DotNet code.

Re: Inserting blocks with .net managed code

02-17-2006 11:36 PM in reply to: JohnB-HKS
Hi John,

Here is a sample code that inserts a blockreference :


using AcadDB = Autodesk.AutoCAD.DatabaseServices;
using AcadRun = Autodesk.AutoCAD.Runtime;
using AcadGeom = Autodesk.AutoCAD.Geometry;

public void test()
{
string blockName = "MyBlock";
AcadDB.ObjectId blockId;

AcadDB.Database db = AcadDB.HostApplicationServices.WorkingDatabase;

AcadDB.Transaction trans = db.TransactionManager.StartTransaction();

AcadDB.BlockTable BT =
(AcadDB.BlockTable)trans.GetObject(db.BlockTableId,
AcadDB.OpenMode.ForRead);
foreach (AcadDB.ObjectId btrID in BT)
{
AcadDB.BlockTableRecord BTR =
(AcadDB.BlockTableRecord)trans.GetObject(btrID, AcadDB.OpenMode.ForRead);
if (BTR.Name.ToUpper() == blockName.ToUpper())
{
blockId = BTR.ObjectId;
AcadDB.BlockTableRecord modelSpaceRecord =
(AcadDB.BlockTableRecord)trans.GetObject(BT[AcadDB.BlockTableRecord.ModelSpace],
AcadDB.OpenMode.ForWrite);
AcadGeom.Point3d pt = new Autodesk.AutoCAD.Geometry.Point3d(4,4,0);
AcadDB.BlockReference blockRef = new
Autodesk.AutoCAD.DatabaseServices.BlockReference(pt, blockId);
modelSpaceRecord.AppendEntity(blockRef);
trans.AddNewlyCreatedDBObject(blockRef, true);
}
}

trans.Commit();
}


Cheers,
Tilz


wrote in message news:5090035@discussion.autodesk.com...
I'm writing an application that connects to an SQL database and displays
information much like design Center. One I get the records I need in a list
view I need to in insert a block related to that record. Can anybody help
me in inserting a block in to a drawing using managed DotNet code.
Contributor
16 Posts
0 Kudos
Registered: ‎02-14-2006
Post 3 of 3

Re: Inserting blocks with .net managed code

02-20-2006 06:16 AM in reply to: JohnB-HKS
Thanks for replay!!!!!! this looks great! Could you help in converting to VB. I'm not up on C# quite yet,
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post