Using custom drawing property in Fields

By Virupaksha Aithal

.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();
    }
}

Comments

One response to “Using custom drawing property in Fields”

  1. Patrick Avatar
    Patrick

    Hello from France, is there a way with .NET to create my own category of fields like this:
    new Field(“%<\AcVar MyCustomDP.Address \f \”%tc4\”>%”.
    Thank you.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading