Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to insert a block that will not initially exist in the current drawing, but once inserted may be inserted multiple times. I have code that determines the name of the block and the insertion point I need to insert from a directory and returns the block name to the routine that will insert the block. It appears to work, except that the block never shows up. I don't know what I am missing and could some suggestions.
class BlockInsert
{
public void InsertBlock(AcGeo.Point3d InsPt, string BlkName)
{
AppSvc.Document cDoc = App.DocumentManager.MdiActiveDocument;
DBSvc.Database cDB = cDoc.Database;
AcEdIn.Editor cEd = cDoc.Editor;
using (DBSvc.Transaction Trans1 = cDB.TransactionManager.StartTransaction())
{
DBSvc.BlockTable blkTable;
blkTable = Trans1.GetObject(cDB.BlockTableId, DBSvc.OpenMode.ForWrite) as DBSvc.BlockTable;
DBSvc.BlockTableRecord blkTableRec = new DBSvc.BlockTableRecord();
if (!blkTable.Has(BlkName))
{
blkTable.Add(blkTableRec);
Trans1.AddNewlyCreatedDBObject(blkTableRec, true);
blkTableRec.Name = BlkName;
}
// Insert support block at insertion point InsPt
DBSvc.BlockTableRecord space = (DBSvc.BlockTableRecord)Trans1.GetObject(cDB.CurrentSpaceId, DBSvc.OpenMode.ForWrite);
DBSvc.BlockReference rfml = new DBSvc.BlockReference(InsPt, blkTableRec.ObjectId);
space.AppendEntity(rfml);
Trans1.AddNewlyCreatedDBObject(rfml, true);
Trans1.Commit();
}
MessageBox.Show("\nThe block name is: " + BlkName, "BlockName", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
Scott G. Sawdy
scott.sawdy@bluecoyotecad.com
scott.sawdy@bluecoyotecad.com
Solved! Go to Solution.