.NET/ObjectARX API allows you to use the custom properties to be used in fields. Below code sample shows procedure to link the custom property of the drawing. Below code assumes that the current drawing has a custom property called “Address”.
[CommandMethod("AddCusPropertyField")]
public void AddCusPropertyField()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointOptions ppo = new
PromptPointOptions("nSpecify insertion point: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
return;
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
//%%
MText text = new MText();
text.Location = ppr.Value;
ObjectId ModelSpaceId =
SymbolUtilityServices.GetBlockModelSpaceId(db);
BlockTableRecord record = Tx.GetObject(ModelSpaceId,
OpenMode.ForWrite) as BlockTableRecord;
record.AppendEntity(text);
Tx.AddNewlyCreatedDBObject(text, true);
Field custom =
new Field("%%");
custom.EvaluationOption = FieldEvaluationOptions.Automatic;
custom.Evaluate((int)(FieldEvaluationOptions.Automatic), db);
text.SetField(custom);
Tx.AddNewlyCreatedDBObject(custom, true);
Tx.Commit();
ed.Regen();
}
}

Leave a Reply