Adding a hidden flag to mtext objects

Adding a hidden flag to mtext objects

jnoordzij
Advocate Advocate
223 Views
2 Replies
Message 1 of 3

Adding a hidden flag to mtext objects

jnoordzij
Advocate
Advocate

I'm developing a tool that processes mtext objects. I would like to add a invisible flag to the mtext object that indicates that the object was processed. I was thinking about either setting a hidden parameter, or adding some non printable character to the content string. Do you have any advice on possible solutions? 

 

Edit : I'm currently thinking along the lines of adding an invisible character like the 'zero width space' character (Link). The presence of this  character could indicate that the object has been processed. Only this allows a risk of the user editing the mtext text content and the visible character might be deleted. 

 

I'm looking for a solution that is as risk free as possible. But all  suggestions are welcome. Also if you know more non printable characters that I could use for this case, that would be helpful advise. 

 

Thanks in advance !

0 Likes
Accepted solutions (1)
224 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

I think the simplest robust way should be using extended data (Xdata).

 

static string appName = "PROCESSED";

static void AddProcessedFlag(DBObject dbObject, Transaction tr)
{
    var db = dbObject.Database;
    var regAppTable = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead);
    if (!regAppTable.Has(appName))
    {
        regAppTable.UpgradeOpen();
        var regApp = new RegAppTableRecord();
        regApp.Name = appName;
        regAppTable.Add(regApp);
        tr.AddNewlyCreatedDBObject(regApp, true);
    }

    if (!dbObject.IsWriteEnabled)
        tr.GetObject(dbObject.ObjectId, OpenMode.ForWrite);
    dbObject.XData = new ResultBuffer(new TypedValue(1001, appName), new TypedValue(1070, 1));
}

static bool IsProcessed(DBObject dbObject) =>
    dbObject.GetXDataForApplication(appName) != null;


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3

jnoordzij
Advocate
Advocate

That's great advice. Will give that a try. Thanks 

0 Likes