Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone, I have an amazing ideaš¤£. Is it possible to define commands in batches based on a list of block names. Is this possible? Like the code example below, I know, it doesn't work correctly, so would like to try to get help to implement this idea, thanks in advance.
1.
[CommandMethod("SetCommands")]
public static void SetCommands()
{
List<string> commandList = new List<string>()
{
"CMD1",
"CMD2",
"CMD3",
"CMD4",
"CMD5",
"CMD6"
};
CommandMethods(commandList);
}
2.
public static void CommandMethods(List<string> commandList)
{
foreach (string globalName in commandList)
{
[CommandMethod(globalName)]
CreateInsertBlockrefence(globalName);
}
}
public static ObjectId CreateInsertBlockrefence(string blockName)
{
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed=acDoc.Editor;
Point3d postion = ed.GetPoint("\nSelect a point:").Value;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
if (!acBlkTbl.Has(blockName)) return ObjectId.Null;
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
BlockReference acBlk;
ObjectId btrId = acBlkTbl[blockName];
BlockTableRecord record = btrId.GetObject(OpenMode.ForRead) as BlockTableRecord;
acBlk = new BlockReference(postion, acBlkTbl[blockName]);
acBlkTblRec.AppendEntity(acBlk);
acCurDb.TransactionManager.AddNewlyCreatedDBObject(acBlk, true);
acTrans.Commit();
return acBlk.ObjectId;
}
}
Solved! Go to Solution.