I am proud to say I have written my second addin. Will you pro's please give me your input? Constructive criticism is a good thing Thanks!
namespace BCCGETSTAOFF
{
public class BCCGETSTAOFF
{
[CommandMethod("BCC:GETSTAOFF")]
public static void BCCSTAOFF()
{
Document Doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = Doc.Editor;
PromptEntityOptions BCCGETALIGNMENT = new PromptEntityOptions("\nSelect an Alignment Object: ");
PromptEntityResult resalignment = ed.GetEntity(BCCGETALIGNMENT);
ObjectId alignmentId = resalignment.ObjectId;
var BCCSelectedPoint = ed.GetPoint("\nSelect Point: ");
Point3d BCCPNT = BCCSelectedPoint.Value;
var BCCPNTX = BCCPNT.X;
var BCCPNTY = BCCPNT.Y;
ed.WriteMessage("\nX={0},Y={1}", BCCPNTX, BCCPNTY);
using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database
.TransactionManager.StartTransaction())
{
Alignment alignment = alignmentId.GetObject(OpenMode.ForRead) as Alignment;
ed.WriteMessage("\nAlignment name: {0}", alignment.Name);
double FNLSTA = 0.0;
double FNLOFF = 0.0;
alignment.StationOffset (BCCPNT.X, BCCPNT.Y, ref FNLSTA, ref FNLOFF);
ed.WriteMessage("\nSta:{0},Off:{1}", FNLSTA, FNLOFF);
}
}
}
}
Try to use the variables you declare in your code, rather than fetching them again.
For example, you set the active document to a variable, but then you use Application.DocumentManager.MdiActiveDocument... to start a transaction. Others may be more willing to look at code that's succinct and doesn't use fully-qualified names
Unless your code is designed to be usable from some other context besides a command, you should use the Document's TransactionManager rather than the Database's TransactionManager. The former will ensure that graphics are updated in all cases, but the latter may not always do that.