.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inserting blocks with .net managed code

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
195 Views, 2 Replies

Inserting blocks with .net managed code

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.
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

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.
Message 3 of 3
Anonymous
in reply to: Anonymous

Thanks for replay!!!!!! this looks great! Could you help in converting to VB. I'm not up on C# quite yet,

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost