.NET

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

Inserting blocks with .net managed code

84 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 (84 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
Posts: 16
Registered: ‎02-14-2006
Message 3 of 3 (84 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,

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community