Reputation: 4240
I'm trying to write a method that prompts the user to select all the entities they want to combine into a block and then joins them together into a block and returns the block reference. Right now it looks like this.
/// <summary>
/// Returns all entities in an AutoCAD drawing in a list
/// </summary>
public static List<Entity> GetEntitiesInDrawing()
{
List<Entity> entitiesToReturn = new List<Entity>(); //Blocks that will be returned
Transaction tr = _database.TransactionManager.StartTransaction();
DocumentLock docLock = _activeDocument.LockDocument();
using (tr)
using (docLock)
{
BlockTableRecord blockTableRecord = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(_database), OpenMode.ForRead);
foreach (ObjectId id in blockTableRecord)
{
try
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
entitiesToReturn.Add(ent);
}
catch (InvalidCastException)
{
continue;
}
}
}
return entitiesToReturn;
}
/// <summary>
/// Prompts the user for a number of entities and then joins them into a block
/// </summary>
public static BlockReference JoinEntities()
{
BlockReference blkToReturn = null;
List<Entity> entitiesToJoin = PromptUserForEntities();
foreach (Entity ent in entitiesToJoin)
{
// ToDo: Join entities into blkToReturn
}
return blkToReturn;
}
My problem is that I have no idea how or if it is possible to take a list of entities and join them into a blockreference.
Upvotes: 3
Views: 2825
Reputation: 8574
In summary:
The post mentioned can help, but it creates new entities (and doesn't move from model to the block definition (step #3)
Upvotes: 3