.NET

Reply
Contributor
JohnB-HKS
Posts: 16
Registered: ‎02-14-2006
Message 1 of 3 (87 Views)

Inserting blocks with .net managed code

87 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.
*Tilz
Message 2 of 3 (87 Views)

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
JohnB-HKS
Posts: 16
Registered: ‎02-14-2006
Message 3 of 3 (87 Views)

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,
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.