CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

超链接示例

2023-1-1 03:53| 发布者: admin| 查看: 661| 评论: 0|来自: AutoCAD

以下函数列出与实体关联的超链接,并允许在其位置添加新的超链接。(未显示错误检查。

void AddHyperlink()
{
    ads_name en;
    ads_point pt; 
    AcDbEntity * pEnt;
    AcDbObjectId pEntId;
    // Prompt user to select entity.   
    acedEntSel("\nSelect an Entity:  ", en, pt);
    // Get Object id.
    acdbGetObjectId(pEntId, en);
    // Open object for write.
    acdbOpenObject(pEnt, pEntId, AcDb::kForWrite);
    // The hyperlink collection object is created inside
    // of getHyperlinkCollection below. 
    // It is our responsibility to delete it.
    AcDbHyperlinkCollection * pcHCL = NULL;
    // Get the hyperlink collection associated with the entity.
    ACRX_X_CALL(pEnt, AcDbEntityHyperlinkPE)->
        getHyperlinkCollection(pEnt, pcHCL, false, true);
    // If a hyperlink exists already, say so.
    if (pcHCL->count() != 0)
    {
        AcDbHyperlink * pcHO;
        acutPrintf("\nThe following hyperlink info already exists
            on this entity:");
        // Iterate through collection and print existing hyperlinks.
        int i = 0;
        for (i = 0; i < pcHCL->count(); i++)
        {
            // Get point to current hyperlink object.
            pcHO = pcHCL->item(i); 
            acutPrintf("\nHyperlink name: %s", pcHO->name());
            acutPrintf("\nHyperlink location: %s", 
                pcHO->subLocation());
            acutPrintf("\nHyperlink description: %s", 
                pcHO->description());
        }
        acutPrintf("\n** All will be replaced.**");
        // Remove existing hyperlinks from collection. 
        // RemoveAt will delete objects too. 
        for (i = pcHCL->count() - 1; i >= 0; i--)
        {
            pcHCL->removeAt(i);
        }
    }
    // Get new hyperlinks for this entity.
    for (;;)
    {
        acutPrintf("\nEnter null name, location, and description to
            terminate input requests.");
        // Prompt user for name and description.
        char sName[100], sLocation[100], sDescription[100];
        if (acedGetString(TRUE, "\nEnter hyperlink name: ", sName)
            != RTNORM) 
            acutPrintf("Invalid input\n");
        if (acedGetString(TRUE, "\nEnter hyperlink location: ",
            sLocation) != RTNORM) 
            acutPrintf("Invalid input\n");
        if (acedGetString(TRUE, "\nEnter hyperlink description: ",
            sDescription) != RTNORM) 
            acutPrintf("Invalid input\n");
        // Add hyperlink or exit prompting.
        if (strcmp(sName, "") || strcmp(sLocation, "") ||
           strcmp(sDescription, ""))
           pcHCL->addTail(sName, sDescription, sLocation);
        else
           break;  
    }
    // Add these hyperlinks to the selected entity (opened above).
    ACRX_X_CALL(pEnt, AcDbEntityHyperlinkPE)->
        setHyperlinkCollection(pEnt, pcHCL);
    // Delete the collection. The collection will delete all its
    // contained hyperlink objects.
    delete pcHCL;
    // Close the object.
    pEnt->close();
}


路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 14:39

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部