- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'd like to put in a value after inserting block with attribute.
Attribute is Number.
Insert 5 block, each number is automatically increasing.
Below is my code.
Inserted block is success, I'dont know how to put in a value to attribute.
[CommandMethod("uuu", CommandFlags.NoHistory)]
public void BlockSimple()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDocDb = acDoc.Database;
Editor acDocEd = acDoc.Editor;
Database workingDB = HostApplicationServices.WorkingDatabase;
string fpFile = @"C:\LIBRARY\FP_TEST.dwg";
string fpBlock = @"FP_TEST";
using (DocumentLock acLckDoc = acDoc.LockDocument())
{
using (Transaction acTrans = acDocDb.TransactionManager.StartTransaction())
{
Database db = null;
db = new Database(false, false);
db.ReadDwgFile(fpFile, System.IO.FileShare.Read, true, null);
ObjectId NewBlkId = new ObjectId();
NewBlkId = acDocDb.Insert(fpBlock, db, false);
BlockTable bt = (BlockTable)acTrans.GetObject(acDocDb.BlockTableId, OpenMode.ForWrite, true);
BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockReference blkRef = new BlockReference(new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0), NewBlkId);
btr.AppendEntity(blkRef);
acTrans.AddNewlyCreatedDBObject(blkRef, true);
AcadApplication acadApp = (AcadApplication)acApplication.Application.AcadApplication;
acadApp.ActiveDocument.SendCommand("_.ATTSYNC N " + fpBlock + "\n");
acDocEd.Regen();
db.Dispose();
acTrans.Commit();
}
}
}
Solved! Go to Solution.