- UID
- 215174
- 积分
- 286
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-1-29
- 最后登录
- 1970-1-1
|
发表于 2006-10-11 08:57:24
|
显示全部楼层
第二个问题的解答:
The following function lists the hyperlinks associated with an entity and allows new hyperlinks to be added in their place. (Error checking is not shown.)
- [FONT=courier new]
- 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();
- }
- [/FONT]
复制代码 |
|