Identifying entities with hyperlinks

By Virupaksha Aithal

The entities which contain the hyperlinks will have an xdata called “PE_URL”. So you can use “SelectAll’ API with xdata filter to get all the entities with hyperlinks. Refer below code.

[CommandMethod("HyperLinkCount")]
public void HyperLinkCount()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    TypedValue[] tvs = new TypedValue[1];
    tvs[0] = new TypedValue((int)DxfCode.ExtendedDataRegAppName,
                                                        "PE_URL");
 
    SelectionFilter filter = new SelectionFilter(tvs);
    PromptSelectionResult acSSPrompt = ed.SelectAll(filter);
 
    if (acSSPrompt.Status == PromptStatus.OK)
    {
        ed.WriteMessage(acSSPrompt.Value.Count.ToString());
 
        ObjectId[] ids = acSSPrompt.Value.GetObjectIds();
        using (Transaction Tx =
                      db.TransactionManager.StartTransaction())
        {
            foreach (ObjectId id in ids)
            {
                Entity ent = Tx.GetObject(id,
                                        OpenMode.ForRead) as Entity;
 
                HyperLinkCollection HyperCollection = ent.Hyperlinks;
                foreach (HyperLink link in HyperCollection)
                {
                    ed.WriteMessage(link.Name + "n");
                }
            }
        }
    }
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading