Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, everyone. Hope you are doing well.
I have a small code for making block with existing several lines or polylines. but it does not work well. Could anyone help me?
my code is as followings.
var documentManager = Application.DocumentManager;
var currentDocument = documentManager.MdiActiveDocument;
var database = currentDocument.Database;
var ed = currentDocument.Editor;
using (DocumentLock docLock = currentDocument.LockDocument())
{
using (Transaction tr = database.TransactionManager.StartTransaction())
{
try
{
BlockTable acBlkTbl;
acBlkTbl = tr.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
//BlockTableRecord acBlkTblRec = new BlockTableRecord();
acBlkTblRec.Name = "Margin_PreVal" + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Millisecond.ToString() + System.DateTime.Now.Minute.ToString();
acBlkTbl.UpgradeOpen();
ObjectId btrId = acBlkTbl.Add(acBlkTblRec);
tr.AddNewlyCreatedDBObject(acBlkTblRec, true);
DBObjectCollection ents = new DBObjectCollection();
foreach (Line pl in Plugin.marginlinelist)
{
ents.Add((pl));
}
foreach (Entity ent in ents)
{
Entity clone = ent.Clone() as Entity;
ent.Erase();
acBlkTblRec.AppendEntity(clone);
tr.AddNewlyCreatedDBObject(clone, true);
}
BlockTableRecord ms = (BlockTableRecord)tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
var br = new BlockReference(Point3d.Origin, btrId);
ms.AppendEntity(br);
tr.AddNewlyCreatedDBObject(br, true);
tr.Commit();
Plugin.marginlinelist.Clear();
}
catch
{
throw;
}
}
}
In this code Plugin.marginPlinelist is a array of selected lines or already created lines.
Thank you.
Solved! Go to Solution.