Message 1 of 2
I want to Open Block Editor, Select all Lines ,and Join them to Create Polyline, and then save and Close Block Editor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to join all the lines inside the blocks to Create Polyline, like we do manually by editing a block Definition , type JOIN command select all lines, and then save Block Definition
I am currently using following code but getting error at JoinEntities Line
i cannot use start and endpoints of Lines as Irregular Polyline may get Generated, as i have 100s of Lines to Join
[CommandMethod("cb")]
public void JoinLinesInBlocks()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
foreach (ObjectId btrId in bt)
{
BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
if (!btr.IsLayout)
{
BlockTableRecord blockDef = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
Entity[] entityCollection;
// Collect line entities in the block reference
int i = 0;
foreach (ObjectId entId in blockDef)
{
Entity entity = tr.GetObject(entId, OpenMode.ForRead) as Entity;
if (entity is Line || entity is Arc || entity is Polyline)
{
entityCollection[i] = entity; i++;
}
}
// Check if there are at least two entities to create a polyline
if (entityCollection.Count() > 1)
{
// Create a new polyline
Polyline polyline = new Polyline();
blockDef.UpgradeOpen();
// Join entities to create a polyline
polyline.JoinEntities(entityCollection);
// Save the modified block
blockDef.AppendEntity(polyline);
tr.AddNewlyCreatedDBObject(polyline, true);
}
}
}
// Commit the transaction
tr.Commit();
}
}