Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If you're willing, please offer advice on how to make this routine better. Thanks!
//get position of two blocks
namespace BlockPosition
{
public class DraftingTools
{
[CommandMethod("BP")]
public void BPosition()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
try
{
while (true)
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect first block:");
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 second block:");
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("You Failed Horribly :P\n{0}", e.Message)); }
}
}
}
"Very funny, Scotty. Now beam down my clothes.
Solved! Go to Solution.