I'm hoping this is a good place to come to get help with C#, no matter what API it's used with. I am trying to learn C# for personal use with Autodesk's Autocad. There are forums for Autocad specific questions, but only a very few who know the API are helpful...the rest are total pricks. I'm really hoping C# programmers in this forum would be willing to offer better input. I've written the following code. Please offer any advice you are willing to give. If not, thank you anyway.
Code:
namespace BCCSLOPETAG
{
public class DraftingTools
{
[CommandMethod("BCC:GRS")]
public void BCCGRS()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
SelectionFilter sf = new SelectionFilter(new TypedValue[1] { new TypedValue((int)DxfCode.Start, "INSERT") });//<<<--- a selection filter to get only block references
try
{
while (true)
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect grade:");
peo.SetRejectMessage("\nMust be a block.");
peo.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult psr = ed.GetEntity(peo);
if (psr.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId brId = psr.ObjectId;
// Open the block reference
BlockReference br = (BlockReference)tr.GetObject(brId, OpenMode.ForRead);
var att1 = br.Position;
ed.WriteMessage("\n{0}, Position: {1}", br.Name, att1);
}
PromptEntityOptions peo2 = new PromptEntityOptions("\nSelect grade:");
peo2.SetRejectMessage("\nMust be a block.");
peo2.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult psr2 = ed.GetEntity(peo2);
if (psr2.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId brId2 = psr2.ObjectId;
// Open the block reference
BlockReference br2 = (BlockReference)tr.GetObject(brId2, OpenMode.ForRead);
var att2 = br2.Position;
ed.WriteMessage("\n{0}, Position: {1}", br2.Name, att2);
}
}
}
catch (System.Exception e)
{ Application.ShowAlertDialog(String.Format("Brian Says You Failed Horribly :P\n{0}", e.Message)); } //<<<----- This function will return if the user presses escape: this code is only reached on catastrophic failure
}
}
}